lua 自动获取ui组件并生成代码工具

gameobject上挂载

using UnityEngine;
public class UIInterface : MonoBehaviour
{
    public Object[] compChilds;
}

写wraper

    [LuaCallCSharp]
    public static class UIInterfaceWraper
    {
        //由于lua特性,lua获取到的Object类型,可以直接调用其具体类型的属性方法
        //但是,如果要调用C#方法,必须使用具体类型
        //比如这个,需通过wraper方法
        public static void ForceRebuildLayoutImmediate(Object obj)
        {
            LayoutRebuilder.ForceRebuildLayoutImmediate(obj as RectTransform);
        }
        public static Object GetUnityEngineObject(UIInterface face,int index)
        {
           return face.compChilds[index];
        }
    }

lua中这样获取

local getUEObject =function (index,face)
    return face.compChilds[index]
end

local face = self.container:GetComponent("UIInterface")
self.obj1 = getUEObject(0, face)
self.scrollRect = getUEObject(1, face)--获取Object类型,可直接在lua'中当作对应类型处理
self.content = getUEObject(2, face)

CS.UIInterfaceWraper.ForceRebuildLayoutImmediate(self.content)

ui组件自动获取(editor代码)

    public static void AddComp()
    {
        GameObject window = Selection.activeGameObject;
        if (window == null)
            return;

        UIInterface face = window.GetComponent();
        if (face == null)
        {
            face = window.AddComponent();
        }
        AllList = new List();

        AddToList(face.transform);

        face.pChilds = new Object[AllList.Count];
        for (int i = 0; i < AllList.Count; i++)
        {
            face.compChilds[i] = AllList[i];
        }
        EditorUtility.SetDirty(window);
        //AssetDatabase.SaveAssets();
    }
    static void AddToList(Transform transform)
    {
        foreach (Transform item in transform)
        {
            var obj = GetObj(item.gameObject);
            if (obj != null)
            {
                AllList.Add(obj);
            }

            if (item.childCount > 0 && item.GetComponent() == null)
                AddToList(item);
        }
    }
public static UnityEngine.Object GetObj(GameObject tgo)
    {
        int length = tgo.gameObject.name.Length;
        if (length <= 3)
            return null;

        string n = tgo.name.Remove(3);
        UnityEngine.Object obj = null;
        switch (n)
        {
            case "txt":
                obj = tgo.GetComponent();
                break;
            case "btn":
                obj = tgo.GetComponent