Skip to content

Commit

Permalink
fix debug of the active is false
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjgameer committed Aug 11, 2023
1 parent 65cec0b commit ec33760
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
60 changes: 37 additions & 23 deletions Export/filter/HierarchyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ internal class HierarchyFile
public HierarchyFile()
{
this.notPerfabNodes = new List<GameObject>();
var prefabs = Object.FindObjectsOfType<GameObject>();//场景中所有GameObject
GameObject[] gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
var allNodes = getSceneAllNode(gameObjects);//场景中所有GameObject
Dictionary<string, GameObject> perfabList = new Dictionary<string, GameObject>();//用于避免重复的列表
foreach (var gameObject in prefabs)//遍历
foreach (var gameObject in allNodes)//遍历
{
if(!gameObject.activeInHierarchy)
continue;
var rt = PerfabFile.getPerfabFilePath(gameObject);//物体的Prefab根节点
if (rt == null)
{
Expand All @@ -41,43 +40,51 @@ public HierarchyFile()
GameObject gameObject = map.Value;
this.nodeMap.addNodeMap(gameObject, JsonUtils.GetGameObject(gameObject), true);
}
GameObject[] gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
List<GameObject> trueGameObjects = new List<GameObject>();
foreach (var obj in gameObjects)
foreach (var obj in allNodes)
{
if(obj.activeInHierarchy)
trueGameObjects.Add(obj);
getGameObjectData(obj);
}

foreach (var item in trueGameObjects)
{
getGameObjectData(item);
}
this.nodeMap.setRoots(trueGameObjects.ToArray());
this.nodeMap.setRoots(gameObjects);
this.resouremap.createNodeTree();

}

private void getGameObjectData(GameObject gameObject)
private List<GameObject> getSceneAllNode(GameObject[] gameObjects)
{
if(!gameObject.activeInHierarchy&& ExportConfig.IgnoreNotActiveGameObject)
List<GameObject> lists = new List<GameObject>();
for (int i = 0; i < gameObjects.Length; i++)
{
return;
this.AddtoList(gameObjects[i], lists);
}
if (this.notPerfabNodes.Contains(gameObject))
return lists;
}

private void AddtoList(GameObject gameObject, List<GameObject> list)
{
if (!gameObject.activeInHierarchy && ExportConfig.IgnoreNotActiveGameObject)
{
JSONObject nodeData = JsonUtils.GetGameObject(gameObject);
this.nodeMap.addNodeMap(gameObject, nodeData, false);
return;
}
list.Add(gameObject);
if (gameObject.transform.childCount > 0)
{
for (int i = 0; i < gameObject.transform.childCount; i++)
{
getGameObjectData(gameObject.transform.GetChild(i).gameObject);
AddtoList(gameObject.transform.GetChild(i).gameObject,list);
}
}
}

private void getGameObjectData(GameObject gameObject)
{
if (this.notPerfabNodes.Contains(gameObject))
{
JSONObject nodeData = JsonUtils.GetGameObject(gameObject);
this.nodeMap.addNodeMap(gameObject, nodeData, false);
}
}

public void saveAllFile(bool isScene)
{
if (isScene)
Expand All @@ -90,8 +97,15 @@ public void saveAllFile(bool isScene)
for (int i = 0; i < gameObjects.Length; i++)
{
GameObject gameObject = gameObjects[i];
if(!gameObject.activeInHierarchy) continue;
this.resouremap.AddExportFile(new JsonFile(gameObject.name +".lh", this.nodeMap.getPerfabJson(gameObject)));
if (!gameObject.activeInHierarchy && ExportConfig.IgnoreNotActiveGameObject)
{
continue;
}
GameObject perfabRoot = PerfabFile.getPrefabInstanceRoot(gameObject);
if (perfabRoot == null||perfabRoot != gameObject)
{
this.resouremap.AddExportFile(new JsonFile(gameObject.name + ".lh", this.nodeMap.getPerfabJson(gameObject)));
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions Export/resoure/ResoureMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public void getComponentsData(GameObject gameObject, JSONObject node,NodeMap map

public void writeComponentData(JSONObject compents,Component comp, NodeMap map, bool isOverride)
{
if(comp == null)
{
return;
}
GameObject gameObject = comp.gameObject;
if(comp is MeshRenderer)
{
Expand Down

0 comments on commit ec33760

Please sign in to comment.