Пример #1
0
        /// <summary>
        /// 确认变更编辑器实例,立即退出当前的实例并尝试切换至目标的编辑器实例
        /// </summary>
        public void SwitchAnotherEditorInstance()
        {
            // 退出上一个编辑器实例
            if (EditorInstance != null)
            {
                EditorInstance.OnDiable();
                EditorInstance.UpdatableComponent = null;
            }

            EditorUtility.SetDirty(target);
            InspectorObjects.Clear();

            // 变更为无组件,旧数据不清除,以模拟“子继承组件”替换
            if (string.IsNullOrWhiteSpace(SelectedILTypeName))
            {
                updatableComponent.ILTypeFullName = string.Empty;
                return;
            }
            // 用户觉得能切换到目标编辑器实例,实际上不行
            // 例如使用 UI. 作为模糊搜索
            if (!UpdatableComponentsEditor.Value.TryGetValue(SelectedILTypeName, out ConstructorInfo info))
            {
                return;
            }
            else
            {
                EditorInstance = info.Invoke(new object[0]) as IUpdatableComponentEditor;
                if (EditorInstance != null)
                {
                    EditorInstance.UpdatableComponent = updatableComponent;
                    EditorInstance.OnEnable();
                }
                updatableComponent.ILTypeFullName = SelectedILTypeName;
            }

            // 通过组件名称找到对应的自定义组件序列化信息,这个组件可能没有导出
            if (!DeserializeInspectorObject())
            {
                Debug.LogError($"Not Found {nameof(UpdatableComponentInfo)} in Export File.ILTypeFullName : {updatableComponent.ILTypeFullName}");
            }
        }
Пример #2
0
        /* ctor */
        private void OnEnable()
        {
            SelectedILTypeName = string.Empty;
            PatternSelections  = new GUIContent[0];
            PatternIndex       = new int[0];
            SelectionIndex     = NoneSelection;
            InspectorObjects   = new List <InspectorObject>();

            updatableComponent.OnBeforeSerialize_Handle += OnBeforeSerialize_Callback;

            // 还没有选择
            if (string.IsNullOrWhiteSpace(updatableComponent.ILTypeFullName))
            {
                // 强制 UpdatableComponentsEditor.Value 初始化
                _ = UpdatableComponentsEditor.Value;
                EditorApplication.delayCall += RefreshSelectionsPopup;
                return;
            }
            // 通过组件名称找到对应的编辑器实例,这个组件可能就没有编辑器实例
            if (UpdatableComponentsEditor.Value.TryGetValue(updatableComponent.ILTypeFullName, out ConstructorInfo info))
            {
                EditorInstance = info.Invoke(new object[0]) as IUpdatableComponentEditor;
                if (EditorInstance != null)
                {
                    EditorInstance.UpdatableComponent = updatableComponent;
                    EditorInstance.OnEnable();
                }
            }
            // 通过组件名称找到对应的自定义组件序列化信息,这个组件可能没有导出
            if (!DeserializeInspectorObject())
            {
                Debug.LogError($"Not Found {nameof(UpdatableComponentInfo)} in Export File.ILTypeFullName : {updatableComponent.ILTypeFullName}");
            }

            SelectedILTypeName = updatableComponent.ILTypeFullName;
        }