Unity 编辑器 Editor 导出配置数据

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Text;

[CustomEditor(typeof(GameObject))]
public class ExportPos : Editor
{
    void ForAll(Transform tran)
    {
         StringBuilder  texts = new StringBuilder();
        //var obj = target as GameObject;
        foreach (Transform o in tran)
        {
            texts.Append(o.gameObject.name + ": " + o.transform.position + "\n");
            Debug.Log(texts);
            if (o.transform.GetComponentsInChildren<Transform>().Length > 0)
            {
                ForAll(o);
            }
        }

    }
    void OnSceneGUI()
    {
        Handles.BeginGUI();
        if(GUILayout.Button("导出配置数据"))
        {
            //var obj = Selection.gameObjects;
            StringBuilder  texts = new StringBuilder();
            //foreach(var o in obj)
            //{
            //    texts.Append(o.name + ": " + o.transform.position);
            //}

            //var obj = target as GameObject;
            //foreach (Transform o in obj.transform)
            //{
            //    if (o.transform.GetComponentsInChildren<Transform>().Length > 0 )
            //    {
            //        Debug.Log(o.transform.GetComponentsInChildren<Transform>().Length);

            //    }
            //    texts.Append(o.gameObject.name + ": " + o.transform.position +"\n");
            //}
            //texts.Append(obj.name + obj.transform.position);

            //Debug.Log(texts);


            var obj = target as GameObject;
            ForAll(obj.transform);
            //var gt = target as GameTest;
            //Debug.Log("num =" + gt.num);
        }
        Handles.EndGUI();
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        OnSceneGUI();
    }
}

猜你喜欢

转载自blog.csdn.net/qq_15559109/article/details/128229689