2,526
社区成员
发帖
与我相关
我的任务
分享
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;
public class JSON : MonoBehaviour {
[MenuItem("Tools/CreateJSON")]
static void WriteJson()
{
string path = Application.dataPath + "/PartMessage.json";
GameObject obj = Selection.activeGameObject;
if (obj.name != "Part")
{
throw new System.Exception("Selection Model");
}
DateVO date = new DateVO();
for(int i = 1; i <= obj.transform.childCount; i++)
{
PartVO part = new PartVO
{
pos = obj.transform.GetChild(i).localPosition,
rot = obj.transform.GetChild(i).localEulerAngles,
scale = obj.transform.GetChild(i).localScale
};
date.parts.Add(part); //这行是不是有问题
}
string s = JsonUtility.ToJson(date);
File.WriteAllText(path,s);
AssetDatabase.Refresh();
}