File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Assets/MapEditor/Managers Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments