将选中的物体写入XML文件
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using UnityEditor;
using UnityEngine;
public class GenerateXMLInfoFile
{
[MenuItem("UnityAB/CreateAB")]
public static void AnAB()
{
GameObject[] objs = Selection.gameObjects;
if (objs.Length > 0)
{
XDocument document = new XDocument();
XElement root = new XElement("Root");
foreach (var item in objs)
{
XElement objName = new XElement("GameObject");
objName.SetElementValue("Name",item.name);
XElement posInfo = new XElement("Postion");
string position = item.transform.position.x + "|" + item.transform.position.y + "|" + item.transform.position.z;
posInfo.SetValue(position);
XElement rotInfo = new XElement("Rotation");
string rotation = item.transform.localRotation.eulerAngles.x + "|" + item.transform.localRotation.eulerAngles.y + "|" + item.transform.localRotation.eulerAngles.x;
rotInfo.SetValue(rotation);
XElement scaleInfo = new XElement("Scale");
string scale = item.transform.localScale.x + "|" + item.transform.localScale.y + "|" + item.transform.localScale.z;
scaleInfo.SetValue(scale);
root.Add(objName);
objName.Add(posInfo);
objName.Add(rotInfo);
objName.Add(scaleInfo);
root.Save("G:\\234.xml");
}
}
}
}

浙公网安备 33010602011771号