Skip to content

Commit aca23be

Browse files
committed
AssetManager Init
1 parent a8fb016 commit aca23be

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

Assets/MapEditor/Managers/AssetManager.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,30 @@
99

1010
public static class AssetManager
1111
{
12+
#region Init
13+
[InitializeOnLoadMethod]
14+
private static void Init()
15+
{
16+
EditorApplication.update += OnProjectLoad;
17+
}
18+
19+
private static void OnProjectLoad()
20+
{
21+
EditorApplication.update -= OnProjectLoad;
22+
if (!IsInitialised && SettingsManager.LoadBundleOnLaunch)
23+
Initialise(SettingsManager.RustDirectory + SettingsManager.BundlePathExt);
24+
}
25+
#endregion
26+
1227
public static class Callbacks
1328
{
14-
public delegate void AssetManagerCallback();
29+
public delegate void Bundle();
1530

1631
/// <summary>Called after Rust Asset Bundles are loaded into the editor. </summary>
17-
public static event AssetManagerCallback BundlesLoaded;
32+
public static event Bundle BundlesLoaded;
1833

1934
/// <summary>Called after Rust Asset Bundles are unloaded from the editor. </summary>
20-
public static event AssetManagerCallback BundlesDisposed;
35+
public static event Bundle BundlesDisposed;
2136

2237
public static void OnBundlesLoaded() => BundlesLoaded?.Invoke();
2338
public static void OnBundlesDisposed() => BundlesDisposed?.Invoke();

Assets/MapEditor/Managers/PathManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public enum PathType
3838
Powerline = 2,
3939
}
4040

41-
42-
4341
public static void SpawnPath(PathData pathData)
4442
{
4543
Vector3 averageLocation = Vector3.zero;

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using UnityEngine;
22
using UnityEditor;
3-
using static WorldSerialization;
43
using Unity.EditorCoroutines.Editor;
54
using System.Collections;
65
using System.Collections.Generic;
76
using System.Linq;
7+
using static WorldSerialization;
88

99
public static class PrefabManager
1010
{
@@ -20,11 +20,7 @@ private static void OnProjectLoad()
2020
DefaultPrefab = Resources.Load<GameObject>("Prefabs/DefaultPrefab");
2121
PrefabParent = GameObject.FindGameObjectWithTag("Prefabs").transform;
2222
if (DefaultPrefab != null && PrefabParent != null)
23-
{
2423
EditorApplication.update -= OnProjectLoad;
25-
if (!AssetManager.IsInitialised && SettingsManager.LoadBundleOnLaunch)
26-
AssetManager.Initialise(SettingsManager.RustDirectory + SettingsManager.BundlePathExt);
27-
}
2824
}
2925
#endregion
3026

@@ -245,6 +241,7 @@ public static IEnumerator SpawnPrefabs(PrefabData[] prefabs, int progressID)
245241
}
246242
Spawn(Load(prefabs[i].id), prefabs[i], GetParent(prefabs[i].category));
247243
}
244+
248245
Progress.Report(progressID, 0.99f, "Spawned " + prefabs.Length + " prefabs.");
249246
Progress.Finish(progressID, Progress.Status.Succeeded);
250247
}
@@ -267,6 +264,7 @@ public static IEnumerator DeletePrefabs(PrefabDataHolder[] prefabs, int progress
267264
}
268265
GameObject.DestroyImmediate(prefabs[i].gameObject);
269266
}
267+
270268
Progress.Report(progressID, 0.99f, "Deleted " + prefabs.Length + " prefabs.");
271269
Progress.Finish(progressID, Progress.Status.Succeeded);
272270
}
@@ -288,6 +286,7 @@ public static IEnumerator ReplaceWithLoaded(PrefabDataHolder[] prefabs, int prog
288286
Spawn(Load(prefabs[i].prefabData.id), prefabs[i].prefabData, GetParent(prefabs[i].prefabData.category));
289287
GameObject.DestroyImmediate(prefabs[i].gameObject);
290288
}
289+
291290
Progress.Report(progressID, 0.99f, "Replaced " + prefabs.Length + " prefabs.");
292291
Progress.Finish(progressID, Progress.Status.Succeeded);
293292
IsChangingPrefabs = false;
@@ -310,9 +309,9 @@ public static IEnumerator ReplaceWithDefault(PrefabDataHolder[] prefabs, int pro
310309
Spawn(DefaultPrefab, prefabs[i].prefabData, GetParent(prefabs[i].prefabData.category));
311310
GameObject.DestroyImmediate(prefabs[i].gameObject);
312311
}
312+
313313
Progress.Report(progressID, 0.99f, "Replaced " + prefabs.Length + " prefabs.");
314314
Progress.Finish(progressID, Progress.Status.Succeeded);
315-
316315
IsChangingPrefabs = false;
317316
}
318317

0 commit comments

Comments
 (0)