Skip to content

Commit 0a726a3

Browse files
committed
Can read toplevel Assets Folder
- Added the ability to read from an Assets folder from toplevel. This is for functionality with plans we have in place for the Thunderstore
1 parent 16d6e1c commit 0a726a3

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Distance.CustomCar/Data/Car/CarBuilder.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,55 @@ private Dictionary<string, GameObject> LoadAssetsBundles()
173173
}
174174
}
175175

176+
try
177+
{
178+
DirectoryInfo otherAssetsDirectory = new DirectoryInfo(Path.Combine(Directory.GetParent(Directory.GetParent(Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location)).ToString()).ToString(), "Assets"));
179+
180+
foreach (FileInfo assetsFile in otherAssetsDirectory.GetFiles("*", SearchOption.AllDirectories).Concat(globalCarsDirectory.GetFiles("*", SearchOption.AllDirectories)).OrderBy(x => x.Name))
181+
{
182+
try
183+
{
184+
Assets assets = Assets.FromUnsafePath(assetsFile.FullName);
185+
AssetBundle bundle = assets.Bundle as AssetBundle;
186+
187+
int foundPrefabCount = 0;
188+
189+
foreach (string assetName in from name in bundle.GetAllAssetNames() where name.EndsWith(".prefab", StringComparison.InvariantCultureIgnoreCase) select name)
190+
{
191+
GameObject carPrefab = bundle.LoadAsset<GameObject>(assetName);
192+
193+
string assetKey = $"{assetsFile.FullName} ({assetName})";
194+
195+
if (!assetsList.ContainsKey(assetKey))
196+
{
197+
assetsList.Add(assetKey, carPrefab);
198+
foundPrefabCount++;
199+
}
200+
}
201+
202+
if (foundPrefabCount == 0)
203+
{
204+
Mod.Instance.Errors.Add($"Can't find a prefab in the asset bundle: {assetsFile.FullName}");
205+
Mod.Log.LogInfo($"Can't find a prefab in the asset bundle: {assetsFile.FullName}");
206+
}
207+
}
208+
catch (Exception ex)
209+
{
210+
Mod.Instance.Errors.Add($"Could not load assets file: {assetsFile.FullName}");
211+
Mod.Log.LogInfo($"Could not load assets file: {assetsFile.FullName}");
212+
Mod.Instance.Errors.Add(ex);
213+
Mod.Log.LogInfo(ex);
214+
}
215+
}
216+
}
217+
catch (Exception ex)
218+
{
219+
Mod.Log.LogInfo($"Could not find assets file in the top level directory. This is not bad, this just means no cars were downloaded from the Thunderstore");
220+
Mod.Log.LogInfo(ex);
221+
}
222+
223+
224+
176225
return assetsList;
177226
}
178227

0 commit comments

Comments
 (0)