Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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);
                    }
                }
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public void Draw(float totalWidth)
        {
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.Space(3);
            this._property.IsSelected = EditorGUILayout.Toggle(this._property.IsSelected);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4);

            GUILayoutOption nameWidth       = GUILayout.Width(totalWidth * 1 / 4 - 10);
            GUILayoutOption typeWidth       = GUILayout.Width(totalWidth / 5 - 10);
            GUILayoutOption defaultValWidth = GUILayout.Width(totalWidth * 2 / 5 - 10);
            GUILayoutOption buttonWidth     = GUILayout.Width(totalWidth / 16 - 5);

            // Property name
            this._property.LastName = EditorGUILayout.TextField(this._property.LastName, nameWidth);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4.5f);

            // Property type
            var rect = EditorGUILayout.GetControlRect(typeWidth);

            Popup(this.selectedType, this.observableTypes, rect, OnSelectType);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4);

            var type = this._property.LastPropertyType;

            // Default value
            if (type == typeof(bool))
            {
                this._property.SetLastValueAs(EditorGUILayout.Toggle(this._property.GetLastValueAs <bool>(), defaultValWidth));
            }
            else if (type == typeof(byte))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <byte>(), defaultValWidth));
            }
            else if (type == typeof(sbyte))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <sbyte>(), defaultValWidth));
            }
            else if (type == typeof(short))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <short>(), defaultValWidth));
            }
            else if (type == typeof(ushort))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <ushort>(), defaultValWidth));
            }
            else if (type == typeof(int))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <int>(), defaultValWidth));
            }
            else if (type == typeof(uint))
            {
                this._property.SetLastValueAs(EditorGUILayout.LongField(this._property.GetLastValueAs <uint>(), defaultValWidth));
            }
            else if (type == typeof(long))
            {
                this._property.SetLastValueAs(EditorGUILayout.LongField(this._property.GetLastValueAs <long>(), defaultValWidth));
            }
            else if (type == typeof(float))
            {
                this._property.SetLastValueAs(EditorGUILayout.FloatField(this._property.GetLastValueAs <float>(), defaultValWidth));
            }
            else if (type == typeof(double))
            {
                this._property.SetLastValueAs(EditorGUILayout.DoubleField(this._property.GetLastValueAs <double>(), defaultValWidth));
            }
            else if (type == typeof(char))
            {
                if (this._property.DefaltValue == null)
                {
                    this._property.DefaltValue = string.Empty;
                    this._property.LastValue   = string.Empty;
                }

                var val = EditorGUILayout.TextField(this._property.GetLastValueAs <char>().ToString(), defaultValWidth);
                this._property.SetLastValueAs(string.IsNullOrEmpty(val) ? (char)0 : val[0]);
            }
            else if (type == typeof(string))
            {
                if (this._property.DefaltValue == null)
                {
                    this._property.DefaltValue = string.Empty;
                    this._property.LastValue   = string.Empty;
                }

                this._property.SetLastValueAs(EditorGUILayout.TextField(this._property.GetLastValueAs <string>(), defaultValWidth));
            }
            else if (type.IsEnum)
            {
                var mask  = type.GetCustomAttribute <FlagsAttribute>();
                var value = this._property.GetLastValueAs <Enum>();

                if (value == null)
                {
                    value = type.GetEnumValues().GetValue(0) as Enum;
                }

                if (mask == null)
                {
                    this._property.SetLastValueAs(EditorGUILayout.EnumPopup(value, defaultValWidth));
                }
                else
                {
                    this._property.SetLastValueAs(EditorGUILayout.EnumFlagsField(value, defaultValWidth));
                }
            }
            else if (type == typeof(Color))
            {
                this._property.SetLastValueAs(EditorGUILayout.ColorField(this._property.GetLastValueAs <Color>(), defaultValWidth));
            }
            else if (type == typeof(Vector2))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector2Field(string.Empty, this._property.GetLastValueAs <Vector2>(), defaultValWidth));
            }
            else if (type == typeof(Vector2Int))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector2IntField(string.Empty, this._property.GetLastValueAs <Vector2Int>(), defaultValWidth));
            }
            else if (type == typeof(Vector3))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector3Field(string.Empty, this._property.GetLastValueAs <Vector3>(), defaultValWidth));
            }
            else if (type == typeof(Vector3Int))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector3IntField(string.Empty, this._property.GetLastValueAs <Vector3Int>(), defaultValWidth));
            }
            else if (type == typeof(Vector4))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector4Field(string.Empty, this._property.GetLastValueAs <Vector4>(), defaultValWidth));
            }
            else if (type == typeof(Bounds))
            {
                this._property.SetLastValueAs(EditorGUILayout.BoundsField(this._property.GetLastValueAs <Bounds>(), defaultValWidth));
            }
            else if (type == typeof(BoundsInt))
            {
                this._property.SetLastValueAs(EditorGUILayout.BoundsIntField(this._property.GetLastValueAs <BoundsInt>(), defaultValWidth));
            }
            else if (type == typeof(Rect))
            {
                this._property.SetLastValueAs(EditorGUILayout.RectField(this._property.GetLastValueAs <Rect>(), defaultValWidth));
            }
            else if (type == typeof(RectInt))
            {
                this._property.SetLastValueAs(EditorGUILayout.RectIntField(this._property.GetLastValueAs <RectInt>(), defaultValWidth));
            }
            else if (type == typeof(LayerMask))
            {
                EditorGUI.BeginChangeCheck();
                var maskField = EditorGUILayout.MaskField(LayerMaskToField(this._property.GetLastValueAs <LayerMask>()), InternalEditorUtility.layers, defaultValWidth);

                if (EditorGUI.EndChangeCheck())
                {
                    this._property.SetLastValueAs(FieldToLayerMask(maskField));
                }
            }
            else if (type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                this._property.SetLastValueAs(EditorGUILayout.ObjectField(this._property.GetLastValueAs <UnityEngine.Object>(), type, false, defaultValWidth));
            }
            else
            {
                GUILayout.Label("Undefined!", defaultValWidth);
            }

            GUILayout.EndVertical();

            Color textColor = Color.gray;

            if (this._property.HasChange)
            {
                textColor = Color.black;
            }

            if (ColorButton.Draw("S", CommonColor.LightGreen, textColor, buttonWidth))
            {
                if (this._property.HasChange)
                {
                    this._property.CommitChange();
                    this._onPropertyChanged?.Invoke(this._property);
                }
            }

            if (ColorButton.Draw("X", CommonColor.LightRed, buttonWidth))
            {
                this._onPropertyDelete?.Invoke(this._property);
            }

            GUILayout.EndHorizontal();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 7
0
        public void Draw(float totalWidth)
        {
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.Space(3);
            _property.IsSelected = EditorGUILayout.Toggle(_property.IsSelected);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4);

            GUILayoutOption nameWidth       = GUILayout.Width(totalWidth * 1 / 3 - 10);
            GUILayoutOption typeWidth       = GUILayout.Width(totalWidth / 6 - 10);
            GUILayoutOption defaultValWidth = GUILayout.Width(totalWidth * 1 / 3 - 10);
            GUILayoutOption buttonWidth     = GUILayout.Width(totalWidth / 16 - 5);

            // Property name
            _property.LastName = EditorGUILayout.TextField(_property.LastName, nameWidth);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4.5f);

            // Property type
            selectedType = EditorGUILayout.Popup(selectedType, observableTypes, typeWidth);
            _property.LastPropertyType = ReflectUtils.GetTypeByName(observableTypes [selectedType]);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4);

            // Default value
            if (_property.LastPropertyType == typeof(int))
            {
                _property.SetLastValueAs <int> (EditorGUILayout.IntField(_property.GetLastValueAs <int> (), defaultValWidth));
            }
            else if (_property.LastPropertyType == typeof(long))
            {
                _property.SetLastValueAs <long> (EditorGUILayout.LongField(_property.GetLastValueAs <long> (), defaultValWidth));
            }
            else if (_property.LastPropertyType == typeof(float))
            {
                _property.SetLastValueAs <float> (EditorGUILayout.FloatField(_property.GetLastValueAs <float> (), defaultValWidth));
            }
            else if (_property.LastPropertyType == typeof(double))
            {
                _property.SetLastValueAs <double> (EditorGUILayout.DoubleField(_property.GetLastValueAs <double> (), defaultValWidth));
            }
            else if (_property.LastPropertyType == typeof(string))
            {
                if (_property.DefaltValue == null)
                {
                    _property.DefaltValue = string.Empty;
                    _property.LastValue   = string.Empty;
                }
                _property.SetLastValueAs <string> (EditorGUILayout.TextField(_property.GetLastValueAs <string> (), defaultValWidth));
            }
            else if (_property.LastPropertyType == typeof(bool))
            {
                _property.SetLastValueAs <bool> (EditorGUILayout.Toggle(_property.GetLastValueAs <bool> (), defaultValWidth));
            }
            else
            {
                GUILayout.Label("Undefined!", defaultValWidth);
            }
            GUILayout.EndVertical();

            Color textColor = Color.gray;

            if (_property.HasChange)
            {
                textColor = Color.black;
            }

            if (ColorButton.Draw("S", CommonColor.LightGreen, textColor, buttonWidth))
            {
                if (_property.HasChange)
                {
                    _property.CommitChange();
                    if (_onPropertyChanged != null)
                    {
                        _onPropertyChanged(_property);
                    }
                }
            }

            if (ColorButton.Draw("X", CommonColor.LightRed, buttonWidth))
            {
                if (_onPropertyDelete != null)
                {
                    _onPropertyDelete(_property);
                }
            }

            GUILayout.EndHorizontal();
        }
Ejemplo n.º 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();
                }
            }
        }