Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the function that converts the scene tree to XML

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use the function to convert the scene tree into XML. I hope you will get something after reading this article. Let's discuss it together.

A few days ago, I encountered some GameObject that were not destroyed as expected in the runtime scenario tree.

You need to print out the scene tree structure for comparison, so write this simple function.

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; iTunes +)

{

Transform transChild = transParant.transform.GetChild (I)

ExchangeHierarchy2XmlNode (transChild, curentElement, doc)

}

}

After reading this article, I believe you have a certain understanding of "how to use the function to convert the scene tree into XML". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report