Skip to content

Commit ec33760

Browse files
committed
fix debug of the active is false
1 parent 65cec0b commit ec33760

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

Export/filter/HierarchyFile.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ internal class HierarchyFile
1111
public HierarchyFile()
1212
{
1313
this.notPerfabNodes = new List<GameObject>();
14-
var prefabs = Object.FindObjectsOfType<GameObject>();//场景中所有GameObject
14+
GameObject[] gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
15+
var allNodes = getSceneAllNode(gameObjects);//场景中所有GameObject
1516
Dictionary<string, GameObject> perfabList = new Dictionary<string, GameObject>();//用于避免重复的列表
16-
foreach (var gameObject in prefabs)//遍历
17+
foreach (var gameObject in allNodes)//遍历
1718
{
18-
if(!gameObject.activeInHierarchy)
19-
continue;
2019
var rt = PerfabFile.getPerfabFilePath(gameObject);//物体的Prefab根节点
2120
if (rt == null)
2221
{
@@ -41,43 +40,51 @@ public HierarchyFile()
4140
GameObject gameObject = map.Value;
4241
this.nodeMap.addNodeMap(gameObject, JsonUtils.GetGameObject(gameObject), true);
4342
}
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)
4744
{
48-
if(obj.activeInHierarchy)
49-
trueGameObjects.Add(obj);
45+
getGameObjectData(obj);
5046
}
5147

52-
foreach (var item in trueGameObjects)
53-
{
54-
getGameObjectData(item);
55-
}
56-
this.nodeMap.setRoots(trueGameObjects.ToArray());
48+
this.nodeMap.setRoots(gameObjects);
5749
this.resouremap.createNodeTree();
5850

5951
}
6052

61-
private void getGameObjectData(GameObject gameObject)
53+
private List<GameObject> getSceneAllNode(GameObject[] gameObjects)
6254
{
63-
if(!gameObject.activeInHierarchy&& ExportConfig.IgnoreNotActiveGameObject)
55+
List<GameObject> lists = new List<GameObject>();
56+
for (int i = 0; i < gameObjects.Length; i++)
6457
{
65-
return;
58+
this.AddtoList(gameObjects[i], lists);
6659
}
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)
6866
{
69-
JSONObject nodeData = JsonUtils.GetGameObject(gameObject);
70-
this.nodeMap.addNodeMap(gameObject, nodeData, false);
67+
return;
7168
}
69+
list.Add(gameObject);
7270
if (gameObject.transform.childCount > 0)
7371
{
7472
for (int i = 0; i < gameObject.transform.childCount; i++)
7573
{
76-
getGameObjectData(gameObject.transform.GetChild(i).gameObject);
74+
AddtoList(gameObject.transform.GetChild(i).gameObject,list);
7775
}
7876
}
7977
}
8078

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+
8188
public void saveAllFile(bool isScene)
8289
{
8390
if (isScene)
@@ -90,8 +97,15 @@ public void saveAllFile(bool isScene)
9097
for (int i = 0; i < gameObjects.Length; i++)
9198
{
9299
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+
}
95109
}
96110
}
97111

Export/resoure/ResoureMap.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public void getComponentsData(GameObject gameObject, JSONObject node,NodeMap map
156156

157157
public void writeComponentData(JSONObject compents,Component comp, NodeMap map, bool isOverride)
158158
{
159+
if(comp == null)
160+
{
161+
return;
162+
}
159163
GameObject gameObject = comp.gameObject;
160164
if(comp is MeshRenderer)
161165
{

0 commit comments

Comments
 (0)