标签:场景树 转xml
日前遇到些运行时场景树中未按预期销毁的GameObject
需要打印出场景树结构做前后比较,所以写个这个简单的函数
public static void ExchangeHierarchy2XmlNode(Transform transParant, System.Xml.XmlNode node,System.Xml.XmlDocument doc)
{
int indexCount = transParant.transform.childCount;
string name = transParant.name;
if (string.IsNullOrEmpty(name))
{
name = "Untitiled";
}
name=name.Replace(‘(‘, ‘_‘);name=name.Replace(‘)‘, ‘_‘);
name = name.Replace(‘ ‘, ‘_‘);
name = "_" + name;
System.Xml.XmlElement curentElement = doc.CreateElement(name);
node.AppendChild(curentElement);
foreach (Component comp in transParant.gameObject.GetComponents(typeof(MonoBehaviour)))
{
System.Xml.XmlAttribute newAttr = doc.CreateAttribute(comp.GetType().Name);
newAttr.Value = "";
curentElement.Attributes.Append(newAttr);
}
for (int i = 0; i < indexCount; i++)
{
Transform transChild = transParant.transform.GetChild(i);
ExchangeHierarchy2XmlNode(transChild, curentElement, doc);
}
}
本文出自 “山脊” 博客,请务必保留此出处http://cmdszh.blog.51cto.com/2792338/1616810
标签:场景树 转xml
原文地址:http://cmdszh.blog.51cto.com/2792338/1616810