Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
- [GUI] Change Scene Hierarchy root node to be original file when a…
Browse files Browse the repository at this point in the history
…vailable.
  • Loading branch information
Razmoth committed Sep 19, 2023
1 parent 2e3dcdc commit 8b49dd5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 46 deletions.
29 changes: 20 additions & 9 deletions AssetStudioGUI/AssetStudioGUIForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private void sceneHierarchy_Click(object sender, EventArgs e)
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
var path = saveFileDialog.FileName;
var nodes = new Dictionary<string, dynamic>();
var nodes = new Dictionary<string, object>();
foreach (TreeNode node in sceneTreeView.Nodes)
{
var value = GetNode(node);
Expand All @@ -652,21 +652,32 @@ private void sceneHierarchy_Click(object sender, EventArgs e)
}
}

private dynamic GetNode(TreeNode treeNode)
private object GetNode(TreeNode treeNode)
{
if (treeNode.GetNodeCount(true) == 0)
var nodes = new Dictionary<string, object>();
foreach (TreeNode node in treeNode.Nodes)
{
if (HasGameObjectNode(node))
{
nodes.TryAdd(node.Text, GetNode(node));
}
}
return nodes.Count == 0 ? string.Empty : nodes;
}

private bool HasGameObjectNode(TreeNode treeNode)
{
if (treeNode is GameObjectTreeNode gameObjectNode && !(bool)gameObjectNode.gameObject.m_Transform?.m_Father.IsNull)
{
return string.Empty;
return gameObjectNode.gameObject.m_Animator != null;
}
else
{
var nodes = new Dictionary<string, dynamic>();
var exportableNodes = treeNode.Nodes.Cast<GameObjectTreeNode>().Where(x => x.gameObject.m_Animator != null || (bool)x.gameObject.m_Transform?.m_Father.IsNull).ToList();
foreach (TreeNode node in exportableNodes)
foreach (TreeNode node in treeNode.Nodes)
{
nodes.TryAdd(node.Text, GetNode(node));
return HasGameObjectNode(node);
}
return nodes;
return false;
}
}

Expand Down
91 changes: 54 additions & 37 deletions AssetStudioGUI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,79 +421,96 @@ public static (string, List<TreeNode>) BuildAssetData()

var treeNodeCollection = new List<TreeNode>();
var treeNodeDictionary = new Dictionary<GameObject, GameObjectTreeNode>();
var assetsFileCount = assetsManager.assetsFileList.Count;
int j = 0;
Progress.Reset();
foreach (var assetsFile in assetsManager.assetsFileList)
var files = assetsManager.assetsFileList.GroupBy(x => x.originalPath ?? string.Empty).OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToList());
foreach (var (file, assetsFiles) in files)
{
var fileNode = new TreeNode(assetsFile.fileName); //RootNode
var fileNode = !string.IsNullOrEmpty(file) ? new TreeNode(Path.GetFileName(file)) : null; //RootNode

foreach (var obj in assetsFile.Objects)
foreach (var assetsFile in assetsFiles)
{
if (assetsManager.tokenSource.IsCancellationRequested)
{
Logger.Info("Building tree structure been cancelled !!");
return (string.Empty, Array.Empty<TreeNode>().ToList());
}
var assetsFileNode = new TreeNode(assetsFile.fileName);

if (obj is GameObject m_GameObject)
foreach (var obj in assetsFile.Objects)
{
if (!treeNodeDictionary.TryGetValue(m_GameObject, out var currentNode))
if (assetsManager.tokenSource.IsCancellationRequested)
{
currentNode = new GameObjectTreeNode(m_GameObject);
treeNodeDictionary.Add(m_GameObject, currentNode);
Logger.Info("Building tree structure been cancelled !!");
return (string.Empty, Array.Empty<TreeNode>().ToList());
}

foreach (var pptr in m_GameObject.m_Components)
if (obj is GameObject m_GameObject)
{
if (pptr.TryGet(out var m_Component))
if (!treeNodeDictionary.TryGetValue(m_GameObject, out var currentNode))
{
objectAssetItemDic[m_Component].TreeNode = currentNode;
if (m_Component is MeshFilter m_MeshFilter)
currentNode = new GameObjectTreeNode(m_GameObject);
treeNodeDictionary.Add(m_GameObject, currentNode);
}

foreach (var pptr in m_GameObject.m_Components)
{
if (pptr.TryGet(out var m_Component))
{
if (m_MeshFilter.m_Mesh.TryGet(out var m_Mesh))
objectAssetItemDic[m_Component].TreeNode = currentNode;
if (m_Component is MeshFilter m_MeshFilter)
{
objectAssetItemDic[m_Mesh].TreeNode = currentNode;
if (m_MeshFilter.m_Mesh.TryGet(out var m_Mesh))
{
objectAssetItemDic[m_Mesh].TreeNode = currentNode;
}
}
}
else if (m_Component is SkinnedMeshRenderer m_SkinnedMeshRenderer)
{
if (m_SkinnedMeshRenderer.m_Mesh.TryGet(out var m_Mesh))
else if (m_Component is SkinnedMeshRenderer m_SkinnedMeshRenderer)
{
objectAssetItemDic[m_Mesh].TreeNode = currentNode;
if (m_SkinnedMeshRenderer.m_Mesh.TryGet(out var m_Mesh))
{
objectAssetItemDic[m_Mesh].TreeNode = currentNode;
}
}
}
}
}

var parentNode = fileNode;
var parentNode = assetsFileNode;

if (m_GameObject.m_Transform != null)
{
if (m_GameObject.m_Transform.m_Father.TryGet(out var m_Father))
if (m_GameObject.m_Transform != null)
{
if (m_Father.m_GameObject.TryGet(out var parentGameObject))
if (m_GameObject.m_Transform.m_Father.TryGet(out var m_Father))
{
if (!treeNodeDictionary.TryGetValue(parentGameObject, out var parentGameObjectNode))
if (m_Father.m_GameObject.TryGet(out var parentGameObject))
{
parentGameObjectNode = new GameObjectTreeNode(parentGameObject);
treeNodeDictionary.Add(parentGameObject, parentGameObjectNode);
if (!treeNodeDictionary.TryGetValue(parentGameObject, out var parentGameObjectNode))
{
parentGameObjectNode = new GameObjectTreeNode(parentGameObject);
treeNodeDictionary.Add(parentGameObject, parentGameObjectNode);
}
parentNode = parentGameObjectNode;
}
parentNode = parentGameObjectNode;
}
}

parentNode.Nodes.Add(currentNode);
}
}

parentNode.Nodes.Add(currentNode);
if (assetsFileNode.Nodes.Count > 0)
{
if (fileNode == null)
{
treeNodeCollection.Add(assetsFileNode);
}
else
{
fileNode.Nodes.Add(assetsFileNode);
}
}
}

if (fileNode.Nodes.Count > 0)
if (fileNode?.Nodes.Count > 0)
{
treeNodeCollection.Add(fileNode);
}

Progress.Report(++j, assetsFileCount);
Progress.Report(++j, files.Count);
}
treeNodeDictionary.Clear();

Expand Down

0 comments on commit 8b49dd5

Please sign in to comment.