Exemplo n.º 1
0
    public void InitEidtorFromLayout(EditorRoot e)
    {
        if (null == e)
        {
            return;
        }

        string editorName = e.editorName;
        string initCallbackRefTypeName = e.initCallbackRefType;
        string initCallbackName        = e.initCallback;

//        object userData = e.UserData;

        e.Init();

        Type       refType          = Assembly.GetExecutingAssembly().GetType(initCallbackRefTypeName);
        MethodInfo initCallbackInfo = refType.GetMethod(initCallbackName, BindingFlags.Public | BindingFlags.Static);

        if (refType == null || initCallbackInfo == null)
        {
            Debug.Log("编辑器\"" + editorName + "\"恢复失败!");
            return;
        }

        VoidDelegate initDelegate = Delegate.CreateDelegate(typeof(VoidDelegate), null, initCallbackInfo, false) as VoidDelegate;

        initDelegate(e);

        EditorManager.GetInstance().AssignCtrlID(e, e.RootCtrl);

        UniversalEditorUtility.LoadEditorLayout(e);

        if (e.onAwake != null)
        {
            e.onAwake(e);
        }

        if (e.onEnable != null)
        {
            e.onEnable(e);
        }

        if (!roots.ContainsKey(editorName))
        {
            roots.Add(editorName, e);
        }
    }
Exemplo n.º 2
0
    public EditorRoot CreateEditor <T>(string name, bool utility, VoidDelegate initCallback, object userData = null)
        where T : EditorRoot, new()
    {
        if (roots.ContainsKey(name))
        {//有重名编辑器
            Debug.LogError("出现重名编辑器" + "\"name\"!");
            return(null);
        }

        //流程一:先实例化了一个Editor
        EditorRoot newEditor = EditorWindow.CreateInstance <T>();

        //初始化编辑器,实例化了一个EditorRender;
        newEditor.Init();

        //记录初始化回调,用于反射重生;

        //填写回调函数所在的类型;
        newEditor.initCallbackRefType = initCallback.Method.ReflectedType.FullName;
        //填写回调函数的函数名;
        newEditor.initCallback = initCallback.Method.Name;
        //填写是否为是Utility类型窗口;
        newEditor.isUtility = utility;
        //填写Editor的名称
        newEditor.editorName = name;
#if UNITY_5_1
        newEditor.titleContent = new GUIContent(name);
#else
        newEditor.title = name;
#endif

        newEditor.UserData = userData;

        //区分是否是utility类型调用Show方法;
        if (utility)
        {
            newEditor.ShowUtility();
        }
        else
        {
            newEditor.Show();
        }
        newEditor.Focus();

        //初始化控件
        initCallback(newEditor);

        AssignCtrlID(newEditor, newEditor.RootCtrl);

        UniversalEditorUtility.LoadEditorLayout(newEditor);

        if (newEditor.onAwake != null)
        {
            newEditor.onAwake(newEditor);
        }

        if (newEditor.onEnable != null)
        {
            newEditor.onEnable(newEditor);
        }

        roots.Add(name, newEditor);


        return(newEditor);
    }