Skip to content

Commit 20686c5

Browse files
committed
SceneManager
- Added SceneManager class, currently monitors the hierachy and parents items that are cloned outside of the parented objects.
1 parent 4cf1af7 commit 20686c5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using UnityEditor;
2+
using UnityEditor.SceneManagement;
3+
using UnityEngine.SceneManagement;
4+
5+
public static class SceneManager
6+
{
7+
public static Scene EditorScene { get; private set; }
8+
9+
[InitializeOnLoadMethod]
10+
private static void Init()
11+
{
12+
EditorApplication.update += OnProjectLoad;
13+
EditorApplication.hierarchyChanged += OnSceneChanged;
14+
}
15+
16+
private static void OnProjectLoad()
17+
{
18+
EditorScene = EditorSceneManager.GetActiveScene();
19+
if (EditorScene.IsValid())
20+
EditorApplication.update -= OnProjectLoad;
21+
}
22+
23+
private static void OnSceneChanged()
24+
{
25+
if (EditorScene.rootCount != 4)
26+
{
27+
foreach (var item in EditorScene.GetRootGameObjects())
28+
{
29+
if (item.TryGetComponent(out PrefabDataHolder prefab))
30+
{
31+
prefab.gameObject.transform.SetParent(PrefabManager.PrefabParent);
32+
continue;
33+
}
34+
if (item.TryGetComponent(out PathDataHolder path))
35+
path.gameObject.transform.SetParent(PathManager.PathParent);
36+
}
37+
}
38+
}
39+
}

Assets/MapEditor/Managers/SceneManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)