Example #1
0
        void OnGUI()
        {
            Init();
            GUILayout.Space(10);
            baseTypePopup.Draw();
            LineHelper.Draw(Color.black);
            GUILayout.Space(10);

            if (ColorButton.Draw("Create", CommonColor.LightGreen, GUILayout.Height(30)))
            {
                string      lastPath    = "";
                UIManConfig uiManConfig = Resources.Load <UIManConfig> ("UIManConfig");
                if (uiManConfig != null)
                {
                    if (baseTypePopup.SelectedItem == arrSupportType [0])
                    {
                        lastPath = uiManConfig.modelScriptFolder;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [1])
                    {
                        lastPath = uiManConfig.screenScriptFolder;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [2])
                    {
                        lastPath = uiManConfig.dialogScriptFolder;
                    }
                }

                lastPath = EditorUtility.SaveFilePanel("Save script", Application.dataPath + lastPath, typeName, "cs");

                if (!string.IsNullOrEmpty(lastPath))
                {
                    typeName = Path.GetFileNameWithoutExtension(lastPath);

                    lastPath = Path.GetDirectoryName(lastPath).Replace(Application.dataPath, "");
                    if (baseTypePopup.SelectedItem == arrSupportType [0])
                    {
                        uiManConfig.modelScriptFolder      = lastPath;
                        uiManConfig.generatingTypeIsDialog = false;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [1])
                    {
                        uiManConfig.screenScriptFolder     = lastPath;
                        uiManConfig.generatingTypeIsDialog = false;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [2])
                    {
                        uiManConfig.dialogScriptFolder     = lastPath;
                        uiManConfig.generatingTypeIsDialog = true;
                    }
                    EditorUtility.SetDirty(uiManConfig);

                    GenerateViewModel();
                }
            }
        }
Example #2
0
        private void DrawSelectedTypeHeader()
        {
            // Title
            GUILayout.Space(2);
            LabelHelper.TitleLabel(_selectedType.Name);
            LineHelper.Draw(Color.gray);

            // Common
            GUILayout.Space(2);

            if (_selectedType.BaseType != typeof(ObservableModel))
            {
                DrawHeaderButtons();
            }

            // Base type
            GUILayout.Space(10);
            LabelHelper.HeaderLabel("Type");
            GUILayout.Space(2);
            this.baseTypePopup.Draw();

            GUILayout.Space(4);
            _selectedTypeIsSealed = EditorGUILayout.Toggle("Sealed", _selectedTypeIsSealed);

            // Namespace
            GUILayout.Space(10);
            LabelHelper.HeaderLabel("Namespace");
            GUILayout.Space(2);
            this.namespaceField.Draw(GUIContent.none, 0);

            if (this.baseTypePopup.SelectedItem != nameof(ObservableModel) &&
                !string.Equals(_selectedType.Namespace, this.namespaceField.Text))
            {
                EditorGUILayout.HelpBox($"Must manually change the namespace in {_selectedType.Name}.Handler.cs", MessageType.Warning);
            }

            // Properties
            GUILayout.Space(10);
            LabelHelper.HeaderLabel("Properties");
            GUILayout.Space(2);

            _propertiesScrollPos = EditorGUILayout.BeginScrollView(_propertiesScrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            if (_propertiesDrawerCache.ContainsKey(_selectedType))
            {
                EditablePropertyDrawer[] props = _propertiesDrawerCache[_selectedType];
                for (var i = 0; i < props.Length; i++)
                {
                    props[i].Draw(_propertiesAreaWidth);
                }
            }
            EditorGUILayout.EndScrollView();
        }
Example #3
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);
        }
Example #4
0
        private void DrawSelectedType(int id)
        {
            if (_selectedType != null)
            {
                DrawSelectedTypeHeader();
            }

            GUILayout.Space(10);

            // Add property
            if (ColorButton.Draw("Add New Property", CommonColor.LightGreen, GUILayout.Height(30)))
            {
                var newIndex    = 0;
                var strNewIndex = "";
                for (var i = 0; i < _selectedProperties.Length; i++)
                {
                    if (_selectedProperties[i].LastName.Contains("NewProperty"))
                    {
                        newIndex++;
                    }
                }
                if (newIndex > 0)
                {
                    strNewIndex = newIndex.ToString();
                }
                var newProperty = new CustomPropertyInfo("", typeof(string))
                {
                    LastName = "NewProperty" + strNewIndex
                };
                ArrayUtility.Add(ref _selectedProperties, newProperty);
                CachePropertiesDrawer();
            }

            //Save all change
            var changeList   = new CustomPropertyInfo[0];
            var selectedList = new CustomPropertyInfo[0];

            for (var i = 0; i < _selectedProperties.Length; i++)
            {
                if (_selectedProperties[i].HasChange)
                {
                    ArrayUtility.Add(ref changeList, _selectedProperties[i]);
                }
                if (_selectedProperties[i].IsSelected)
                {
                    ArrayUtility.Add(ref selectedList, _selectedProperties[i]);
                }
            }

            GUILayout.Space(10);
            LineHelper.Draw(Color.gray);
            GUILayout.Space(5);

            if (changeList.Length > 0 || !string.Equals(_selectedType.Namespace, this.namespaceField.Text) ||
                _selectedType.IsSealed != _selectedTypeIsSealed)
            {
                if (ColorButton.Draw("Save All Changes", CommonColor.LightGreen, GUILayout.Height(30)))
                {
                    for (var i = 0; i < changeList.Length; i++)
                    {
                        changeList[i].CommitChange();
                    }
                    SaveCurrentType(true, this.baseTypePopup.SelectedItem);
                }
            }

            if (selectedList.Length > 0)
            {
                if (ColorButton.Draw("Delete Selected Properties", CommonColor.LightRed, GUILayout.Height(30)))
                {
                    for (var i = 0; i < selectedList.Length; i++)
                    {
                        ArrayUtility.Remove(ref _selectedProperties, selectedList[i]);
                    }
                    SaveCurrentType(true, this.baseTypePopup.SelectedItem);
                    CachePropertiesDrawer(true);
                }
            }

            if (_selectedProperties.Length > 0)
            {
                if (ColorButton.Draw("Delete All Properties", CommonColor.LightRed, GUILayout.Height(30)))
                {
                    while (_selectedProperties.Length > 0)
                    {
                        ArrayUtility.Clear(ref _selectedProperties);
                        SaveCurrentType();
                        CachePropertiesDrawer(true);
                    }
                }
            }
        }
Example #5
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);
            }
        }
Example #6
0
        void PropertiesWindow(int id = 2)
        {
            GUILayout.BeginVertical();

            if (listTypes != null && !string.IsNullOrEmpty(listTypes.SelectedItem))
            {
                if (selectedType != null)
                {
                    // Title
                    GUILayout.Space(2);
                    LabelHelper.TitleLabel(selectedType.Name);
                    LineHelper.Draw(Color.gray);

                    // Common
                    GUILayout.Space(2);
                    if (selectedType.BaseType != typeof(ObservableModel))
                    {
                        GUILayout.BeginHorizontal();
                        if (ColorButton.Draw("Edit View Logic (Handler)", CommonColor.LightBlue, GUILayout.Height(30)))
                        {
                            string handler = CodeGenerationHelper.GetScriptPathByType(selectedType);
                            handler = handler.Replace(".cs", ".Handler.cs");
                            UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1);
                        }

                        if (ColorButton.Draw("Edit View (UI)", CommonColor.LightBlue, GUILayout.Height(30)))
                        {
                            GameObject         prefabInstance;
                            UnityEngine.Object obj = FindObjectOfType(selectedType);
                            if (obj != null)
                            {
                                prefabInstance = ((MonoBehaviour)obj).gameObject;
                            }
                            else
                            {
                                bool       isDialog     = selectedType.BaseType == typeof(UIManDialog);
                                string     prefabFolder = GetUIPrefabPath(selectedType, isDialog);
                                string     prefabFile   = selectedType.Name + PREFAB_EXT;
                                string     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)))
                        {
                            string cs      = CodeGenerationHelper.GetScriptPathByType(selectedType);
                            string handler = cs.Replace(".cs", ".Handler.cs");
                            AssetDatabase.DeleteAsset(cs);
                            AssetDatabase.DeleteAsset(handler);

                            bool   isDialog     = selectedType.BaseType == typeof(UIManDialog);
                            string prefabFolder = GetUIPrefabPath(selectedType, isDialog);
                            string prefabFile   = selectedType.Name + PREFAB_EXT;
                            string prefabPath   = UIManDefine.ASSETS_FOLDER + prefabFolder + prefabFile;
                            AssetDatabase.DeleteAsset(prefabPath);
                            AssetDatabase.Refresh();
                        }
                        GUILayout.EndHorizontal();
                        LineHelper.Draw(Color.gray);
                    }

                    // Base type
                    GUILayout.Space(10);
                    LabelHelper.HeaderLabel("Type");
                    LineHelper.Draw(Color.gray);
                    baseTypePopup.Draw();

                    if (baseTypePopup.SelectedItem != "ObservableModel")
                    {
                        if (!System.IO.File.Exists(handlerScriptPath))
                        {
                            if (GUILayout.Button("Generate Handler"))
                            {
                                string backupCode = CodeGenerationHelper.DeleteScript(handlerScriptPath);
                                GenerateViewModelHandler(backupCode, selectedType.BaseType.Name);
                            }
                        }
                    }

                    // Properties
                    GUILayout.Space(10);
                    LabelHelper.HeaderLabel("Properties");
                    LineHelper.Draw(Color.gray);

                    propertiesScrollPos = EditorGUILayout.BeginScrollView(propertiesScrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                    if (propertiesDrawerCache.ContainsKey(selectedType))
                    {
                        EditablePropertyDrawer[] props = propertiesDrawerCache [selectedType];
                        for (int i = 0; i < props.Length; i++)
                        {
                            props [i].Draw(propertiesAreaWidth);
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }

                GUILayout.Space(10);

                // Add property
                if (ColorButton.Draw("Add New Property", CommonColor.LightGreen, GUILayout.Height(30)))
                {
                    int    newIndex    = 0;
                    string strNewIndex = "";
                    for (int i = 0; i < selectedProperties.Length; i++)
                    {
                        if (selectedProperties [i].LastName.Contains("NewProperty"))
                        {
                            newIndex++;
                        }
                    }
                    if (newIndex > 0)
                    {
                        strNewIndex = newIndex.ToString();
                    }
                    CustomPropertyInfo newProperty = new CustomPropertyInfo("", typeof(string));
                    newProperty.LastName = "NewProperty" + strNewIndex;
                    ArrayUtility.Add <CustomPropertyInfo> (ref selectedProperties, newProperty);
                    CachePropertiesDrawer();
                }

                //Save all change
                CustomPropertyInfo[] changeList   = new CustomPropertyInfo[0];
                CustomPropertyInfo[] selectedList = new CustomPropertyInfo[0];
                for (int i = 0; i < selectedProperties.Length; i++)
                {
                    if (selectedProperties [i].HasChange)
                    {
                        ArrayUtility.Add(ref changeList, selectedProperties [i]);
                    }
                    if (selectedProperties [i].IsSelected)
                    {
                        ArrayUtility.Add(ref selectedList, selectedProperties [i]);
                    }
                }

                GUILayout.Space(10);
                LineHelper.Draw(Color.gray);
                GUILayout.Space(5);

                if (changeList.Length > 0)
                {
                    if (ColorButton.Draw("Save All Changes", CommonColor.LightGreen, GUILayout.Height(30)))
                    {
                        for (int i = 0; i < changeList.Length; i++)
                        {
                            changeList [i].CommitChange();
                        }
                        SaveCurrentType(true, baseTypePopup.SelectedItem);
                    }
                }

                if (selectedList.Length > 0)
                {
                    if (ColorButton.Draw("Delete Selected Properties", CommonColor.LightRed, GUILayout.Height(30)))
                    {
                        for (int i = 0; i < selectedList.Length; i++)
                        {
                            ArrayUtility.Remove(ref selectedProperties, selectedList [i]);
                        }
                        SaveCurrentType(true, baseTypePopup.SelectedItem);
                        CachePropertiesDrawer(true);
                    }
                }

                if (selectedProperties.Length > 0)
                {
                    if (ColorButton.Draw("Delete All Properties", CommonColor.LightRed, GUILayout.Height(30)))
                    {
                        while (selectedProperties.Length > 0)
                        {
                            ArrayUtility.Clear(ref selectedProperties);
                            SaveCurrentType();
                            CachePropertiesDrawer(true);
                        }
                    }
                }
            }
            else
            {
                GUILayout.Label("NO DATA FOR PREVIEW!");
            }


            GUILayout.EndVertical();
        }
Example #7
0
        public override void OnInspectorGUI()
        {
            GUILayout.BeginHorizontal("Box");
            LabelHelper.HeaderLabel("UIMan View Model");
            GUILayout.EndHorizontal();
            LineHelper.Draw(Color.gray);

            UIManBase uiManBase = (UIManBase)target;

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

            if (uiManBase is UIManDialog)
            {
                UIManDialog dialog = (UIManDialog)uiManBase;
                dialog.useCover = EditorGUILayout.Toggle(cover, dialog.useCover);
                EditorUtility.SetDirty(target);
            }
            else if (uiManBase is UIManBase)
            {
                UIManScreen screen = (UIManScreen)uiManBase;
                screen.useBackground = EditorGUILayout.Toggle(background, screen.useBackground);
                if (screen.useBackground)
                {
                    screen.backgroundType = EditorGUILayout.TextField(screen.backgroundType);
                }
                EditorUtility.SetDirty(target);
            }

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

                uiManBase.animRoot = EditorGUILayout.ObjectField(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(show, uiManBase.motionShow);
            uiManBase.motionHide = (UIMotion)EditorGUILayout.EnumPopup(hide, uiManBase.motionHide);
            uiManBase.motionIdle = (UIMotion)EditorGUILayout.EnumPopup(idle, uiManBase.motionIdle);

            UIMotion[] motions = new UIMotion[3] {
                uiManBase.motionShow, uiManBase.motionHide, uiManBase.motionIdle
            };
            bool haveMecanimAnim = false;
            bool 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.CUSTOM_MECANIM_ANIMATION && 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(time, uiManBase.animTime);
            uiManBase.showPosition = EditorGUILayout.Vector3Field(position, uiManBase.showPosition);

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

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

            EditorGUILayout.Space();
            if (GUILayout.Button("Edit View (UI)", GUILayout.Height(25)))
            {
                GameObject         prefabInstance;
                UnityEngine.Object obj = FindObjectOfType(uiManBase.UIType);
                if (obj != null)
                {
                    prefabInstance = ((MonoBehaviour)obj).gameObject;
                }
                else
                {
                    bool isDialog = uiManBase.GetUIBaseType() == UIBaseType.DIALOG;
//					string prefabFolder = GetUIPrefabPath (selectedType, isDialog);
//					string prefabFile = selectedType.Name + PREFAB_EXT;
//					string prefabPath = Path.Combine (prefabFolder, prefabFile);
//					GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject> (prefabPath);
//					if (prefab == null) {
//						prefab = FindAssetObject<GameObject> (selectedType.Name, PREFAB_EXT);
//					}

                    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 (GUILayout.Button("Edit View Logic (Handler)", GUILayout.Height(25)))
            {
                string handler = CodeGenerationHelper.GetScriptPathByType(target.GetType());
                handler = handler.Replace(".cs", ".Handler.cs");
                UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1);
            }
        }
Example #8
0
        private void OnGUI()
        {
            Initialize();

            GUILayout.Space(10);
            LabelHelper.HeaderLabel("Type");
            LineHelper.Draw(Color.gray);
            this.baseTypePopup.Draw();

            GUILayout.Space(10);
            LabelHelper.HeaderLabel("Namespace");
            LineHelper.Draw(Color.gray);
            this.namespaceField.Draw(GUIContent.none, 0);

            GUILayout.Space(10);

            if (ColorButton.Draw("Create", CommonColor.LightGreen, GUILayout.Height(30)))
            {
                var lastPath = "";
                var config   = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(false);

                if (config != null)
                {
                    if (this.baseTypePopup.SelectedItem == this.arrSupportType[0])
                    {
                        lastPath      = config.modelScriptFolder;
                        this.typeName = "NewViewModel";
                    }
                    else if (this.baseTypePopup.SelectedItem == this.arrSupportType[1])
                    {
                        lastPath      = config.screenScriptFolder;
                        this.typeName = "UINewScreen";
                    }
                    else if (this.baseTypePopup.SelectedItem == this.arrSupportType[2])
                    {
                        lastPath      = config.dialogScriptFolder;
                        this.typeName = "UINewDialog";
                    }
                }

                lastPath = EditorUtility.SaveFilePanel("Save script", Application.dataPath + lastPath, this.typeName, "cs");

                if (!string.IsNullOrEmpty(lastPath))
                {
                    this.typeName = Path.GetFileNameWithoutExtension(lastPath);

                    lastPath = Path.GetDirectoryName(lastPath).Replace("\\", "/").Replace(Application.dataPath, "");

                    if (this.baseTypePopup.SelectedItem == this.arrSupportType[0])
                    {
                        config.modelScriptFolder      = lastPath;
                        config.generatingTypeIsDialog = false;
                    }
                    else if (this.baseTypePopup.SelectedItem == this.arrSupportType[1])
                    {
                        config.screenScriptFolder     = lastPath;
                        config.generatingTypeIsDialog = false;
                    }
                    else if (this.baseTypePopup.SelectedItem == this.arrSupportType[2])
                    {
                        config.dialogScriptFolder     = lastPath;
                        config.generatingTypeIsDialog = true;
                    }

                    EditorUtility.SetDirty(config);
                    GenerateType();
                }
            }
        }