Skip to content

Commit 9d1a912

Browse files
committed
Callback progress
1 parent bc97753 commit 9d1a912

File tree

6 files changed

+48
-32
lines changed

6 files changed

+48
-32
lines changed

Assets/MapEditor/Editor/PrefabDataHolderEditor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ public override void OnInspectorGUI()
1414
Functions.PrefabID(script);
1515
Functions.SnapToGround(script);
1616
Functions.ToggleLights(script);
17-
Functions.BreakPrefab(script);
1817
}
1918
}

Assets/MapEditor/Editor/TreeView/PrefabsList/PrefabsListWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static MultiColumnHeaderState DefaultMultiColumnHeaderState(float treeVie
7373

7474
private void OnEnable()
7575
{
76-
EventManager.BundlesLoaded += ReloadTree;
76+
AssetManager.Callbacks.BundlesLoaded += ReloadTree;
7777
}
7878

7979
void InitIfNeeded()

Assets/MapEditor/Managers/AssetManager.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99

1010
public static class AssetManager
1111
{
12+
public static class Callbacks
13+
{
14+
public delegate void AssetManagerCallback();
15+
16+
/// <summary>Called after Rust Asset Bundles are loaded into the editor. </summary>
17+
public static event AssetManagerCallback BundlesLoaded;
18+
19+
/// <summary>Called after Rust Asset Bundles are unloaded from the editor. </summary>
20+
public static event AssetManagerCallback BundlesDisposed;
21+
22+
public static void OnBundlesLoaded() => BundlesLoaded?.Invoke();
23+
public static void OnBundlesDisposed() => BundlesDisposed?.Invoke();
24+
}
25+
1226
public static string BundlePath { get; private set; }
1327

1428
public static GameManifest Manifest { get; private set; }
@@ -19,11 +33,11 @@ public static class AssetManager
1933

2034
public static Dictionary<uint, string> IDLookup { get; private set; } = new Dictionary<uint, string>();
2135
public static Dictionary<string, uint> PathLookup { get; private set; } = new Dictionary<string, uint>();
36+
public static Dictionary<string, AssetBundle> BundleLookup { get; private set; } = new Dictionary<string, AssetBundle>();
2237

2338
public static Dictionary<string, AssetBundle> Bundles { get; private set; } = new Dictionary<string, AssetBundle>(System.StringComparer.OrdinalIgnoreCase);
24-
public static Dictionary<string, AssetBundle> AssetPaths { get; private set; } = new Dictionary<string, AssetBundle>(System.StringComparer.OrdinalIgnoreCase);
25-
public static Dictionary<string, Object> Cache { get; private set; } = new Dictionary<string, Object>();
26-
public static Dictionary<string, Texture2D> Previews { get; private set; } = new Dictionary<string, Texture2D>();
39+
public static Dictionary<string, Object> AssetCache { get; private set; } = new Dictionary<string, Object>();
40+
public static Dictionary<string, Texture2D> PreviewCache { get; private set; } = new Dictionary<string, Texture2D>();
2741

2842
public static List<string> ManifestStrings { get => IsInitialised ? GetManifestStrings() : new List<string>(); private set => ManifestStrings = value; }
2943

@@ -47,7 +61,7 @@ public static void Dispose()
4761

4862
private static T GetAsset<T>(string filePath) where T : Object
4963
{
50-
if (!AssetPaths.TryGetValue(filePath, out AssetBundle bundle))
64+
if (!BundleLookup.TryGetValue(filePath, out AssetBundle bundle))
5165
return null;
5266

5367
return bundle.LoadAsset<T>(filePath);
@@ -57,29 +71,29 @@ public static T LoadAsset<T>(string filePath) where T : Object
5771
{
5872
var asset = default(T);
5973

60-
if (Cache.ContainsKey(filePath))
61-
asset = Cache[filePath] as T;
74+
if (AssetCache.ContainsKey(filePath))
75+
asset = AssetCache[filePath] as T;
6276
else
6377
{
6478
asset = GetAsset<T>(filePath);
6579
if (asset != null)
66-
Cache.Add(filePath, asset);
80+
AssetCache.Add(filePath, asset);
6781
}
6882
return asset;
6983
}
7084

7185
public static GameObject LoadPrefab(string filePath)
7286
{
73-
if (Cache.ContainsKey(filePath))
74-
return Cache[filePath] as GameObject;
87+
if (AssetCache.ContainsKey(filePath))
88+
return AssetCache[filePath] as GameObject;
7589

7690
else
7791
{
7892
GameObject val = GetAsset<GameObject>(filePath);
7993
if (val != null)
8094
{
8195
PrefabManager.Setup(val, filePath);
82-
Cache.Add(filePath, val);
96+
AssetCache.Add(filePath, val);
8397
return val;
8498
}
8599
Debug.LogWarning("Prefab not loaded from bundle: " + filePath);
@@ -89,7 +103,7 @@ public static GameObject LoadPrefab(string filePath)
89103

90104
public static Texture2D GetPreview(string filePath)
91105
{
92-
if (Previews.TryGetValue(filePath, out Texture2D preview))
106+
if (PreviewCache.TryGetValue(filePath, out Texture2D preview))
93107
return preview;
94108
else
95109
{
@@ -99,7 +113,7 @@ public static Texture2D GetPreview(string filePath)
99113

100114
prefab.SetActive(true);
101115
var tex = AssetPreview.GetAssetPreview(prefab) ?? new Texture2D(60, 60);
102-
Previews.Add(filePath, tex);
116+
PreviewCache.Add(filePath, tex);
103117
prefab.SetActive(false);
104118
return tex;
105119
}
@@ -121,7 +135,7 @@ private static List<string> GetManifestStrings()
121135
public static void AssetDump()
122136
{
123137
using (StreamWriter streamWriter = new StreamWriter(AssetDumpPath, false))
124-
foreach (var item in AssetPaths.Keys)
138+
foreach (var item in BundleLookup.Keys)
125139
streamWriter.WriteLine(item + " : " + ToID(item));
126140
}
127141

@@ -177,7 +191,7 @@ public static IEnumerator Initialise(string bundlesRoot)
177191
yield return EditorCoroutineUtility.StartCoroutineOwnerless(SetMaterials(materialID));
178192

179193
IsInitialised = true; IsInitialising = false;
180-
EventManager.OnBundlesLoaded();
194+
Callbacks.OnBundlesLoaded();
181195
PrefabManager.ReplaceWithLoaded(PrefabManager.CurrentMapPrefabs, prefabID);
182196
}
183197

@@ -209,9 +223,9 @@ public static IEnumerator Dispose()
209223
}
210224

211225
int bundleCount = Bundles.Count;
212-
AssetPaths.Clear();
226+
BundleLookup.Clear();
213227
Bundles.Clear();
214-
Cache.Clear();
228+
AssetCache.Clear();
215229

216230
Progress.Report(bundleID, 0.99f, "Unloaded: " + bundleCount + " bundles.");
217231
Progress.Finish(bundleID, Progress.Status.Succeeded);
@@ -282,7 +296,7 @@ public static IEnumerator SetBundleReferences((int parent, int bundle) ID)
282296
{
283297
foreach (var filename in asset.GetAllAssetNames())
284298
{
285-
AssetPaths.Add(filename, asset);
299+
BundleLookup.Add(filename, asset);
286300
if (sw.Elapsed.TotalMilliseconds >= 0.5f)
287301
{
288302
yield return null;
@@ -291,7 +305,7 @@ public static IEnumerator SetBundleReferences((int parent, int bundle) ID)
291305
}
292306
foreach (var filename in asset.GetAllScenePaths())
293307
{
294-
AssetPaths.Add(filename, asset);
308+
BundleLookup.Add(filename, asset);
295309
if (sw.Elapsed.TotalMilliseconds >= 0.5f)
296310
{
297311
yield return null;

Assets/MapEditor/Managers/EventManager.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
public static class EventManager
44
{
5-
public delegate void AssetManagerCallback();
5+
public delegate void MapManagerCallback(string mapName = "");
66

7-
/// <summary>Called after Rust Asset Bundles are loaded into the editor. </summary>
8-
public static event AssetManagerCallback BundlesLoaded;
7+
/// <summary>Called after a map has been loaded. Calls on both map loaded and map created.</summary>
8+
public static event MapManagerCallback MapLoaded;
99

10-
/// <summary>Called after Rust Asset Bundles are unloaded from the editor. </summary>
11-
public static event AssetManagerCallback BundlesDisposed;
10+
public static event MapManagerCallback MapSaved;
1211

13-
public static void OnBundlesLoaded() => BundlesLoaded?.Invoke();
14-
15-
public static void OnBundlesDisposed() => BundlesDisposed?.Invoke();
12+
public static void OnMapLoaded(string mapName = "") => MapLoaded?.Invoke(mapName);
13+
public static void OnMapSaved(string mapName = "") => MapSaved?.Invoke(mapName);
1614
}

Assets/MapEditor/Managers/MapManager.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ public static void CreateMap(int size, int ground = 4, int biome = 1, float land
664664

665665
private class Coroutines
666666
{
667-
public static IEnumerator Load(MapInfo mapInfo, string loadPath = "")
667+
public static IEnumerator Load(MapInfo mapInfo, string path = "")
668668
{
669669
for (int i = 0; i < Progress.GetCount(); i++) // Remove old progress
670670
{
@@ -673,7 +673,7 @@ public static IEnumerator Load(MapInfo mapInfo, string loadPath = "")
673673
progress.Remove();
674674
}
675675

676-
int progressID = Progress.Start("Load: " + loadPath.Split('/').Last(), "Preparing Map", Progress.Options.Sticky);
676+
int progressID = Progress.Start("Load: " + path.Split('/').Last(), "Preparing Map", Progress.Options.Sticky);
677677
int delPrefab = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);
678678
int spwPrefab = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);
679679
int delPath = Progress.Start("Paths", null, Progress.Options.Sticky, progressID);
@@ -714,6 +714,8 @@ public static IEnumerator Load(MapInfo mapInfo, string loadPath = "")
714714
Progress.Report(progressID, 0.99f, "Loaded");
715715
Progress.Finish(terrainID, Progress.Status.Succeeded);
716716
Progress.Finish(progressID, Progress.Status.Succeeded);
717+
718+
EventManager.OnMapLoaded(path);
717719
}
718720

719721
public static IEnumerator Save(string path)
@@ -739,6 +741,8 @@ public static IEnumerator Save(string path)
739741
Progress.Finish(pathID, Progress.Status.Succeeded);
740742
Progress.Finish(terrainID, Progress.Status.Succeeded);
741743
Progress.Finish(progressID, Progress.Status.Succeeded);
744+
745+
EventManager.OnMapSaved(path);
742746
}
743747

744748
public static IEnumerator CreateMap(int size, int ground = 4, int biome = 1, float landHeight = 503f)

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ public static IEnumerator BreakPrefab(GameObject prefab)
212212
var nameSplit = transforms[i].gameObject.name.Split(' ');
213213
var prefabName = nameSplit[0].Trim() + ".prefab";
214214
var prefabNameCheck = prefabName.ToLower();
215-
// cbf making another text file to read from.
215+
// cbf making another text file to read from. This is terrible.
216216
if (prefabNameCheck == "props.prefab" || prefabNameCheck == "lights.prefab" || prefabNameCheck == "beam.prefab" ||
217-
prefabNameCheck == "on.prefab" || prefabNameCheck == "fur.prefab" || prefabNameCheck == "ore.prefab" || prefabNameCheck == "buildings.prefab")
217+
prefabNameCheck == "on.prefab" || prefabNameCheck == "fur.prefab" || prefabNameCheck == "ore.prefab" || prefabNameCheck == "buildings.prefab" ||
218+
prefabNameCheck == "close.prefab" || prefabNameCheck == "body.prefab" || prefabNameCheck == "prop.prefab")
218219
continue;
219220

220221
var prefabPaths = assetPaths.Where(x => x.Contains(prefabName));

0 commit comments

Comments
 (0)