Пример #1
0
 public void OnSelecType(string typeName)
 {
     _config.selectedType  = typeName;
     _selectedType         = UIManEditorReflection.GetTypeByName(typeName);
     _selectedTypeIsSealed = _selectedType.IsSealed;
     _selectedProperties   = _selectedType.GetUIManProperties(true);
     this.namespaceField   = new TextFieldHelper(_selectedType.Namespace);
     this.baseTypePopup    = new EditablePopup(_arrSupportType, _selectedType.BaseType.Name, OnChangeBaseType);
     _currentScriptPath    = UIManCodeGenerator.GetScriptPathByType(_selectedType);
     _handlerScriptPath    = UIManCodeGenerator.GeneratPathWithSubfix(_currentScriptPath, ".Handler.cs");
     CachePropertiesDrawer();
 }
Пример #2
0
        private void DrawHeaderButtons()
        {
            GUILayout.BeginHorizontal();

            if (!File.Exists(_handlerScriptPath))
            {
                if (ColorButton.Draw("Generate Type Handler", CommonColor.LightGreen, GUILayout.Height(30)))
                {
                    var backupCode = UIManCodeGenerator.DeleteScript(_handlerScriptPath);
                    GenerateHandler(backupCode, _selectedType.BaseType.Name);
                }
            }
            else
            {
                if (ColorButton.Draw("Edit Type Handler", CommonColor.LightBlue, GUILayout.Height(30)))
                {
                    var handler = UIManCodeGenerator.GetScriptPathByType(_selectedType);
                    handler = handler.Replace(".cs", ".Handler.cs");
                    UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1);
                }
            }

            if (ColorButton.Draw("Edit Type View", CommonColor.LightBlue, GUILayout.Height(30)))
            {
                GameObject         prefabInstance;
                UnityEngine.Object obj = FindObjectOfType(_selectedType);
                if (obj != null)
                {
                    prefabInstance = ((MonoBehaviour)obj).gameObject;
                }
                else
                {
                    var        isDialog     = _selectedType.BaseType == typeof(UIManDialog);
                    var        prefabFolder = GetUIPrefabPath(_selectedType, isDialog);
                    var        prefabFile   = _selectedType.Name + PREFAB_EXT;
                    var        prefabPath   = Path.Combine(prefabFolder, prefabFile);
                    GameObject prefab       = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);
                    if (prefab == null)
                    {
                        prefab = FindAssetObject <GameObject>(_selectedType.Name, PREFAB_EXT);
                    }

                    prefabInstance = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                    if (isDialog)
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.dialogRoot, false);
                    }
                    else
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.screenRoot, false);
                    }
                }
                Selection.activeGameObject = prefabInstance;
            }

            if (ColorButton.Draw("Delete", CommonColor.LightRed, GUILayout.Height(30)))
            {
                var cs      = UIManCodeGenerator.GetScriptPathByType(_selectedType);
                var handler = cs.Replace(".cs", ".Handler.cs");
                AssetDatabase.DeleteAsset(cs);
                AssetDatabase.DeleteAsset(handler);

                var isDialog     = _selectedType.BaseType == typeof(UIManDialog);
                var prefabFolder = GetUIPrefabPath(_selectedType, isDialog);
                var prefabFile   = _selectedType.Name + PREFAB_EXT;
                var prefabPath   = UIManDefine.ASSETS_FOLDER + prefabFolder + prefabFile;
                AssetDatabase.DeleteAsset(prefabPath);
                AssetDatabase.Refresh();
            }

            GUILayout.EndHorizontal();
            LineHelper.Draw(Color.gray);
        }
Пример #3
0
        public override void OnInspectorGUI()
        {
            var uiManBase = (UIManBase)this.target;

            this.orgBgColor = GUI.backgroundColor;

            GUI.backgroundColor = CommonColor.LightOrange;
            GUILayout.BeginHorizontal("Box");
            LabelHelper.HeaderLabel(string.Format("UIMan View Model ({0})", uiManBase.GetUIBaseType()));
            GUILayout.EndHorizontal();

            GUI.backgroundColor = this.orgBgColor;

            LineHelper.Draw(Color.gray);

            EditorGUILayout.Space();
            LabelHelper.HeaderLabel("General");
            GUILayout.BeginVertical("Box");

            EditorGUI.BeginChangeCheck();

            if (uiManBase is UIManDialog dialog)
            {
                dialog.useCover = EditorGUILayout.Toggle(this.cover, dialog.useCover);
            }
            else if (uiManBase is UIManScreen screen)
            {
                screen.useBackground = EditorGUILayout.Toggle(this.background, screen.useBackground);
                if (screen.useBackground)
                {
                    screen.background = EditorGUILayout.TextField(screen.background);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(this.target);
            }

            if (uiManBase.motionShow == UIMotion.CustomMecanimAnimation || uiManBase.motionHide == UIMotion.CustomMecanimAnimation)
            {
                if (uiManBase.gameObject != null)
                {
                    uiManBase.animRoot = uiManBase.gameObject.GetComponent <Animator>();
                }

                uiManBase.animRoot = EditorGUILayout.ObjectField(this.animator, uiManBase.animRoot, typeof(Animator), true) as Animator;

                if (uiManBase.animRoot == null || uiManBase.animRoot.runtimeAnimatorController == null)
                {
                    if (GUILayout.Button("Generate Animator"))
                    {
                        AnimationEditorUtils.GenerateAnimator(uiManBase.gameObject, UIManDefine.ANIM_SHOW, UIManDefine.ANIM_HIDE, UIManDefine.ANIM_IDLE);
                    }
                }
            }

            uiManBase.motionShow = (UIMotion)EditorGUILayout.EnumPopup(this.show, uiManBase.motionShow);
            uiManBase.motionHide = (UIMotion)EditorGUILayout.EnumPopup(this.hide, uiManBase.motionHide);
            uiManBase.motionIdle = (UIMotion)EditorGUILayout.EnumPopup(this.idle, uiManBase.motionIdle);

            var motions = new UIMotion[3] {
                uiManBase.motionShow, uiManBase.motionHide, uiManBase.motionIdle
            };
            var haveMecanimAnim = false;
            var haveTweenAnim   = false;

            foreach (UIMotion m in motions)
            {
                if ((int)m == 7)
                {
                    haveMecanimAnim = true;
                }
                else
                {
                    haveTweenAnim = true;
                }
            }
            if (haveTweenAnim && haveMecanimAnim)
            {
                GUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField("<color=red><b>Warning: </b>Your motion type is not match with each others so it maybe cause unexpected error!\nPlease select all motion type as Mecanim if you want to make you animation manually with Unity animation editor!</color>", EditorGUIHelper.RichText(true));
                GUILayout.EndHorizontal();
            }

            if (uiManBase.motionIdle != UIMotion.CustomMecanimAnimation && uiManBase.motionIdle != UIMotion.None)
            {
                GUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField("<color=red><b>Warning: </b>Idle motion is now only support Mecanim animation!</color>", EditorGUIHelper.RichText(true));
                GUILayout.EndHorizontal();
            }

            uiManBase.animTime     = EditorGUILayout.FloatField(this.time, uiManBase.animTime);
            uiManBase.showPosition = EditorGUILayout.Vector3Field(this.position, uiManBase.showPosition);

            GUILayout.EndVertical();
            LineHelper.Draw(Color.gray);

            EditorGUILayout.Space();
            LabelHelper.HeaderLabel("Custom fields");
            GUILayout.BeginVertical("Box");
            DrawDefaultInspector();
            GUILayout.EndVertical();

            EditorGUILayout.Space();
            if (ColorButton.Draw("Edit View (UI)", CommonColor.LightGreen, GUILayout.Height(25)))
            {
                GameObject prefabInstance;
                Object     obj = FindObjectOfType(uiManBase.UIType);
                if (obj != null)
                {
                    prefabInstance = ((MonoBehaviour)obj).gameObject;
                }
                else
                {
                    var isDialog = uiManBase.GetUIBaseType() == UIBaseType.Dialog;
                    prefabInstance = PrefabUtility.InstantiatePrefab(uiManBase.gameObject) as GameObject;
                    if (isDialog)
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.dialogRoot, false);
                    }
                    else
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.screenRoot, false);
                    }
                }
                Selection.activeGameObject = prefabInstance;
            }
            if (ColorButton.Draw("Edit View Logic (Handler)", CommonColor.LightGreen, GUILayout.Height(25)))
            {
                var handler = UIManCodeGenerator.GetScriptPathByType(this.target.GetType());
                handler = handler.Replace(".cs", ".Handler.cs");
                UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1);
            }
        }