@@ -11,12 +11,11 @@ internal class HierarchyFile
11
11
public HierarchyFile ( )
12
12
{
13
13
this . notPerfabNodes = new List < GameObject > ( ) ;
14
- var prefabs = Object . FindObjectsOfType < GameObject > ( ) ; //场景中所有GameObject
14
+ GameObject [ ] gameObjects = SceneManager . GetActiveScene ( ) . GetRootGameObjects ( ) ;
15
+ var allNodes = getSceneAllNode ( gameObjects ) ; //场景中所有GameObject
15
16
Dictionary < string , GameObject > perfabList = new Dictionary < string , GameObject > ( ) ; //用于避免重复的列表
16
- foreach ( var gameObject in prefabs ) //遍历
17
+ foreach ( var gameObject in allNodes ) //遍历
17
18
{
18
- if ( ! gameObject . activeInHierarchy )
19
- continue ;
20
19
var rt = PerfabFile . getPerfabFilePath ( gameObject ) ; //物体的Prefab根节点
21
20
if ( rt == null )
22
21
{
@@ -41,43 +40,51 @@ public HierarchyFile()
41
40
GameObject gameObject = map . Value ;
42
41
this . nodeMap . addNodeMap ( gameObject , JsonUtils . GetGameObject ( gameObject ) , true ) ;
43
42
}
44
- GameObject [ ] gameObjects = SceneManager . GetActiveScene ( ) . GetRootGameObjects ( ) ;
45
- List < GameObject > trueGameObjects = new List < GameObject > ( ) ;
46
- foreach ( var obj in gameObjects )
43
+ foreach ( var obj in allNodes )
47
44
{
48
- if ( obj . activeInHierarchy )
49
- trueGameObjects . Add ( obj ) ;
45
+ getGameObjectData ( obj ) ;
50
46
}
51
47
52
- foreach ( var item in trueGameObjects )
53
- {
54
- getGameObjectData ( item ) ;
55
- }
56
- this . nodeMap . setRoots ( trueGameObjects . ToArray ( ) ) ;
48
+ this . nodeMap . setRoots ( gameObjects ) ;
57
49
this . resouremap . createNodeTree ( ) ;
58
50
59
51
}
60
52
61
- private void getGameObjectData ( GameObject gameObject )
53
+ private List < GameObject > getSceneAllNode ( GameObject [ ] gameObjects )
62
54
{
63
- if ( ! gameObject . activeInHierarchy && ExportConfig . IgnoreNotActiveGameObject )
55
+ List < GameObject > lists = new List < GameObject > ( ) ;
56
+ for ( int i = 0 ; i < gameObjects . Length ; i ++ )
64
57
{
65
- return ;
58
+ this . AddtoList ( gameObjects [ i ] , lists ) ;
66
59
}
67
- if ( this . notPerfabNodes . Contains ( gameObject ) )
60
+ return lists ;
61
+ }
62
+
63
+ private void AddtoList ( GameObject gameObject , List < GameObject > list )
64
+ {
65
+ if ( ! gameObject . activeInHierarchy && ExportConfig . IgnoreNotActiveGameObject )
68
66
{
69
- JSONObject nodeData = JsonUtils . GetGameObject ( gameObject ) ;
70
- this . nodeMap . addNodeMap ( gameObject , nodeData , false ) ;
67
+ return ;
71
68
}
69
+ list . Add ( gameObject ) ;
72
70
if ( gameObject . transform . childCount > 0 )
73
71
{
74
72
for ( int i = 0 ; i < gameObject . transform . childCount ; i ++ )
75
73
{
76
- getGameObjectData ( gameObject . transform . GetChild ( i ) . gameObject ) ;
74
+ AddtoList ( gameObject . transform . GetChild ( i ) . gameObject , list ) ;
77
75
}
78
76
}
79
77
}
80
78
79
+ private void getGameObjectData ( GameObject gameObject )
80
+ {
81
+ if ( this . notPerfabNodes . Contains ( gameObject ) )
82
+ {
83
+ JSONObject nodeData = JsonUtils . GetGameObject ( gameObject ) ;
84
+ this . nodeMap . addNodeMap ( gameObject , nodeData , false ) ;
85
+ }
86
+ }
87
+
81
88
public void saveAllFile ( bool isScene )
82
89
{
83
90
if ( isScene )
@@ -90,8 +97,15 @@ public void saveAllFile(bool isScene)
90
97
for ( int i = 0 ; i < gameObjects . Length ; i ++ )
91
98
{
92
99
GameObject gameObject = gameObjects [ i ] ;
93
- if ( ! gameObject . activeInHierarchy ) continue ;
94
- this . resouremap . AddExportFile ( new JsonFile ( gameObject . name + ".lh" , this . nodeMap . getPerfabJson ( gameObject ) ) ) ;
100
+ if ( ! gameObject . activeInHierarchy && ExportConfig . IgnoreNotActiveGameObject )
101
+ {
102
+ continue ;
103
+ }
104
+ GameObject perfabRoot = PerfabFile . getPrefabInstanceRoot ( gameObject ) ;
105
+ if ( perfabRoot == null || perfabRoot != gameObject )
106
+ {
107
+ this . resouremap . AddExportFile ( new JsonFile ( gameObject . name + ".lh" , this . nodeMap . getPerfabJson ( gameObject ) ) ) ;
108
+ }
95
109
}
96
110
}
97
111
0 commit comments