public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.type != "Enum")
            {
                EditorGUI.PropertyField(position, property, label, true);
                return;
            }
            if (idHash == 0)
            {
                idHash = "SearchableEnumDrawer".GetHashCode();
            }
            int id = GUIUtility.GetControlID(idHash, FocusType.Keyboard, position);

            label    = EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, id, label);

            GUIContent buttonText =
                new GUIContent(property.enumDisplayNames[property.enumValueIndex]);

            if (DropdownButton(id, position, buttonText))
            {
                Action <int> onSelect = i =>
                {
                    property.enumValueIndex = i;
                    property.serializedObject.ApplyModifiedProperties();
                };

                SearchablePopup.Show(position, property.enumDisplayNames,
                                     property.enumValueIndex, onSelect);
            }
            EditorGUI.EndProperty();
        }
Example #2
0
        private void DrawType(Rect position, Type type, SerializedProperty property, GUIContent label, int id)
        {
            SerializedProperty typeNameProperty = property.FindPropertyRelative("assemblyQualifiedName");

            if (_types == null || _types.Length == 0)
            {
                TypeDrawerUtillity.GetTypes(null, out _types, out _displayTypes);
                _typeIndex = -1;
            }

            Type serializedType = TypeDrawerUtillity.GetTypeFromAQN(typeNameProperty.stringValue);

            label    = EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, id, label);

            GUIContent buttonText = serializedType == null
                ? new GUIContent()
                : new GUIContent(TypeDrawerUtillity.GetNiceTypeName(serializedType));

            if (TypeDrawerUtillity.DropdownButton(id, position, buttonText))
            {
                Action <int> onSelect = i =>
                {
                    _typeIndex = i;
                    typeNameProperty.stringValue = _types[i];
                    property.serializedObject.ApplyModifiedProperties();
                };

                SearchablePopup.Show(position, _displayTypes, _typeIndex, onSelect);
            }

            EditorGUI.EndProperty();
        }
Example #3
0
        protected override void OnDrawProperty(string label)
        {
            var attr = GetAttr <StringPopupAttribute>();

            string[] options = attr.Options;
            if (!string.IsNullOrEmpty(attr.MemberName))
            {
                options = NativeDrawerUtility.GetMemberValue <string[]>(attr.MemberName, DrawerProperty.Target);
            }

            var value = DrawerProperty.GetValue <string>();

            label = label ?? "";

            if (attr.IsSearchable)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PrefixLabel(label);
                    Rect btnRect = GUILayoutUtility.GetRect(new GUIContent(value), "dropdownbutton");

                    if (EditorGUI.DropdownButton(btnRect, new GUIContent(value), FocusType.Keyboard))
                    {
                        try
                        {
                            SearchablePopup.Show(btnRect, new Vector2(200, 400), Array.IndexOf(options, value), options, (selected) =>
                            {
                                DrawerProperty.Value = options[selected];
                            });
                        }
                        catch (ExitGUIException)
                        {
                            lastSearchableWindow = EditorWindow.focusedWindow;
                            throw;
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (lastSearchableWindow && lastSearchableWindow != EditorWindow.mouseOverWindow)
                {
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        Event.current.Use();
                    }
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                {
                    value = EGUILayout.DrawPopup <string>(label, options, options, value);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    DrawerProperty.Value = value;
                }
            }
        }
Example #4
0
    public static void Show(Rect position, GUIContent label, Func <IList <string> > optionsFunc, string current, Action <int> onSelectionMade)
    {
        // array index.
        int id = GUIUtility.GetControlID(idHash, FocusType.Keyboard, position);

        position = EditorGUI.PrefixLabel(position, id, label);

        if (DropdownButton(id, position, new GUIContent(current)))
        {
            var options = optionsFunc();
            SearchablePopup.Show(position, options, options.IndexOf(current), onSelectionMade);
        }
    }
Example #5
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // If this is not used on an eunum, show an error
        if (property.type != "Enum")
        {
            GUIStyle errorStyle = "CN EntryErrorIconSmall";
            Rect     r          = new Rect(position);
            r.width       = errorStyle.fixedWidth;
            position.xMin = r.xMax;
            GUI.Label(r, "", errorStyle);
            GUI.Label(position, TYPE_ERROR);
            return;
        }

        // By manually creating the control ID, we can keep the ID for the
        // label and button the same. This lets them be selected together
        // with the keyboard in the inspector, much like a normal popup.
        if (idHash == 0)
        {
            idHash = "SearchableEnumDrawer".GetHashCode();
        }
        int id = GUIUtility.GetControlID(idHash, FocusType.Keyboard, position);

        label    = EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, id, label);

        GUIContent buttonText;

        // If the enum has changed, a blank entry
        if (property.enumValueIndex < 0 || property.enumValueIndex >= property.enumDisplayNames.Length)
        {
            buttonText = new GUIContent();
        }
        else
        {
            buttonText = new GUIContent(property.enumDisplayNames[property.enumValueIndex]);
        }

        if (DropdownButton(id, position, buttonText))
        {
            Action <int> onSelect = i => {
                property.enumValueIndex = i;
                property.serializedObject.ApplyModifiedProperties();
            };

            SearchablePopup.Show(position, property.enumDisplayNames,
                                 property.enumValueIndex, onSelect);
        }
        EditorGUI.EndProperty();
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.type != "string")
            {
                EditorGUI.PropertyField(position, property, label, true);
                return;
            }
            SearchableStringAttribute sr = this.attribute as SearchableStringAttribute;
            object parent = GetParentObjectOfProperty(property.propertyPath, property.serializedObject.targetObject);

            string[] array = parent.GetType().GetField(sr.searchArray, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(parent) as string[];

            if (array == null || array.Length == 0)
            {
                EditorGUI.PropertyField(position, property, label, true);
                return;
            }
            if (idHash == 0)
            {
                idHash = "SearchableStringDrawer".GetHashCode();
            }
            int id = GUIUtility.GetControlID(idHash, FocusType.Keyboard, position);

            label    = EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, id, label);

            GUIContent buttonText = new GUIContent(property.stringValue);

            if (DropdownButton(id, position, buttonText))
            {
                int j = -1;
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] == property.stringValue)
                    {
                        j = i;
                        break;
                    }
                }
                SearchablePopup.Show(position, array, j, (index, str) => {
                    property.stringValue = str;
                    property.serializedObject.ApplyModifiedProperties();
                });
            }
            EditorGUI.EndProperty();
        }
Example #7
0
    public static void Show(Rect position, GUIContent label, IList <string> options, int current, Action <int> onSelectionMade)
    {
        // array index.
        if (current >= options.Count || current <= 0)
        {
            current = 0;
        }

        int id = GUIUtility.GetControlID(idHash, FocusType.Keyboard, position);

        position = EditorGUI.PrefixLabel(position, id, label);

        if (DropdownButton(id, position, new GUIContent(options[current])))
        {
            SearchablePopup.Show(position, options, current, onSelectionMade);
        }
    }
        protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
        {
            //prepare pick button label
            var buttonLabel = property.enumValueIndex >= 0 &&
                              property.enumValueIndex < property.enumDisplayNames.Length
                ? new GUIContent(property.enumDisplayNames[property.enumValueIndex])
                : new GUIContent();
            var id = GUIUtility.GetControlID(FocusType.Keyboard, position);

            //begin the true property
            label = EditorGUI.BeginProperty(position, label, property);
            //draw the prefix label
            position = EditorGUI.PrefixLabel(position, id, label);
            //draw dropdown button, will be used to activate popup
            if (EditorGUI.DropdownButton(position, buttonLabel, FocusType.Keyboard))
            {
                try
                {
                    SearchablePopup.Show(position, property.enumValueIndex, property.enumDisplayNames, (i) =>
                    {
                        property.serializedObject.Update();
                        property.enumValueIndex = i;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                }
                catch (ExitGUIException)
                {
                    lastSearchableWindow = EditorWindow.focusedWindow;
                    throw;
                }
            }
            EditorGUI.EndProperty();

            //handle situation when inspector window captures ScrollWheel event
            if (IsNonTargetWindowFocused())
            {
                //NOTE: unfortunately PopupWidnows are not indpendent and we have to
                //override internal events to prevent scrolling the Inspector Window
                if (Event.current.type == EventType.ScrollWheel)
                {
                    Event.current.Use();
                }
            }
        }
Example #9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.type != "string")
            {
                EditorGUI.PropertyField(position, property, label, true);
                return;
            }
            if (_hashID == 0)
            {
                _hashID = "LanguageKeyDrawer".GetHashCode();
            }
            int ctrlId = GUIUtility.GetControlID(_hashID, FocusType.Keyboard, position);

            {
                label    = EditorGUI.BeginProperty(position, label, property);
                position = EditorGUI.PrefixLabel(position, ctrlId, label);
                if (DropdownButton(ctrlId, position, new GUIContent(property.stringValue)))
                {
                    int index = -1;
                    for (int i = 0; i < _LanGroup.keys.Count; i++)
                    {
                        if (_LanGroup.keys[i] == property.stringValue)
                        {
                            index = i;
                            break;
                        }
                    }
                    SearchablePopup.Show(position, _LanGroup.keys.ToArray(), index, (i, str) =>
                    {
                        property.stringValue = str;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                }
            }
            EditorGUI.EndProperty();
        }
Example #10
0
            private void AddLanPairFunc()
            {
                if (window.lanKeys.Count == 0)
                {
                    return;
                }
                Rect rect;

                this.EBeginHorizontal(out rect, Styles.Fold)
                .Foldout(ref createLanPairFlodon, "Create LanPair", true)
                .EEndHorizontal()
                .Pan(() =>
                {
                    if (!createLanPairFlodon)
                    {
                        return;
                    }
                    if (tmpLanPair == null)
                    {
                        tmpLanPair = new LanPair()
                        {
                            key = window.lanKeys[0]
                        }
                    }
                    ;
                    if (hashID == 0)
                    {
                        hashID = "CreateView".GetHashCode();
                    }
                    this.DrawVertical(() =>
                    {
                        this.BeginHorizontal()
                        .Label("Lan", GUILayout.Width(describeWidth))
                        .Pan(() => { tmpLanPair.Lan = (SystemLanguage)EditorGUILayout.EnumPopup(tmpLanPair.Lan); })
                        .EndHorizontal()
                        .BeginHorizontal()
                        .Label("Key", GUILayout.Width(describeWidth))
                        .Label(tmpLanPair.key)
                        .Label(EditorGUIUtility.IconContent("editicon.sml"), GUILayout.Width(smallBtnSize))
                        .EndHorizontal()
                        .Pan(() => {
                            Rect pos   = GUILayoutUtility.GetLastRect();
                            int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos);
                            {
                                if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("Key: {0}", tmpLanPair.key))))
                                {
                                    int index = -1;
                                    for (int i = 0; i < window.lanKeys.Count; i++)
                                    {
                                        if (window.lanKeys[i] == tmpLanPair.key)
                                        {
                                            index = i; break;
                                        }
                                    }
                                    SearchablePopup.Show(pos, window.lanKeys.ToArray(), index, (i, str) =>
                                    {
                                        tmpLanPair.key = str;
                                        window.Repaint();
                                    });
                                }
                            }
                        })
                        .BeginHorizontal()
                        .Label("Val", GUILayout.Width(describeWidth))
                        .TextField(ref tmpLanPair.Value)
                        .EndHorizontal()
                        .BeginHorizontal()
                        .FlexibleSpace()
                        .Button(() => {
                            //createLanPairFlodon = false;
                            window.AddLanPair(tmpLanPair);
                            //tmpLanPair = null;
                        }, Contents.OK)
                        .EndHorizontal();
                    }, Styles.BG);
                });
            }
        protected override void OnDrawProperty(string label)
        {
            var attr = GetAttr <IntPopupAttribute>();

            string[] contents = attr.Contents;
            if (!string.IsNullOrEmpty(attr.ContentMemberName))
            {
                contents = DrawerUtility.GetMemberValue <string[]>(attr.ContentMemberName, Property.Target);
            }

            int[] values = attr.Values;
            if (!string.IsNullOrEmpty(attr.ValueMemberName))
            {
                values = DrawerUtility.GetMemberValue <int[]>(attr.ValueMemberName, Property.Target);
            }

            var value      = Property.GetValue <int>();
            var valueIndex = Array.IndexOf(values, value);

            if (valueIndex < 0 && values != null && values.Length > 0)
            {
                valueIndex = 0;
                value      = values[0];

                Property.Value = value;
            }

            label = label ?? "";

            if (attr.IsSearchable)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PrefixLabel(label);
                    Rect btnRect = GUILayoutUtility.GetRect(new GUIContent(contents[valueIndex]), "dropdownbutton");

                    if (EditorGUI.DropdownButton(btnRect, new GUIContent(contents[valueIndex]), FocusType.Keyboard))
                    {
                        try
                        {
                            SearchablePopup.Show(btnRect, new Vector2(200, 400), valueIndex, contents, (selected) =>
                            {
                                Property.Value = values[selected];
                            });
                        }
                        catch (ExitGUIException)
                        {
                            lastSearchableWindow = EditorWindow.focusedWindow;
                            throw;
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (lastSearchableWindow && lastSearchableWindow != EditorWindow.mouseOverWindow)
                {
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        Event.current.Use();
                    }
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                {
                    value = EGUILayout.DrawPopup <int>(label, contents, values, value);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Property.Value = value;
                }
            }
        }
Example #12
0
            public override void OnGUI()
            {
                this.Space(5)
                .DrawHorizontal(() => {
                    this.Label("Check UIMap Script Name", Styles.toolbar);
                    this.TextField(ref UIMapName);
                });
                this.DrawHorizontal(() =>
                {
                    this.Label("Drag UIMap Gen Directory", Styles.toolbar);
                    this.Label(UIMapDir);
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (string.IsNullOrEmpty(UIMapDir))
                    {
                        rect.DrawOutLine(10, Color.red);
                    }
                    else
                    {
                        rect.DrawOutLine(2, Color.black);
                    }
                    if (rect.Contains(Event.current.mousePosition))
                    {
                        var drag = EditorTools.DragAndDropTool.Drag(Event.current, rect);
                        if (drag.compelete && drag.enterArera && drag.paths.Length == 1)
                        {
                            string path = drag.paths[0];
                            if (path.Contains("Assets"))
                            {
                                if (path.IsDirectory())
                                {
                                    UIMapDir = path;
                                }
                                else
                                {
                                    UIMapDir = path.GetDirPath();
                                }
                            }
                        }
                    }
                })
                .DrawHorizontal(() =>
                {
                    this.FlexibleSpace()
                    .Button(() =>
                    {
                        if (string.IsNullOrEmpty(UIMapDir))
                        {
                            EditorWindow.focusedWindow.ShowNotification(new GUIContent("Set UI Map Gen Dir "));
                            return;
                        }
                        //   string uimapGenPath = genpath.CombinePath("MapGen_MVVM.txt");
                        CreateUIMapGen(uimapGenPath);
                        WriteTxt(UIMapDir.CombinePath(UIMap_CSName), uimapGenPath, null);
                        AssetDatabase.Refresh();
                    }, "Copy UIMap From Source");
                }).Space(30);
                if (hashID == 0)
                {
                    hashID = "MVVM_GenCodeView".GetHashCode();
                }
                this.DrawHorizontal(() =>
                {
                    this.Label("Click Choose Panel Type", Styles.toolbar);
                    GUILayout.Label("");
                    Rect pos = GUILayoutUtility.GetLastRect();

                    int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos);
                    {
                        if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("PanelType: {0}", panelType))))
                        {
                            if (panelTypes == null)
                            {
                                EditorWindow.focusedWindow.ShowNotification(new GUIContent("Fresh Panel Types"));
                                return;
                            }
                            int index = -1;
                            for (int i = 0; i < panelTypes.Count; i++)
                            {
                                if (panelTypes[i] == panelType)
                                {
                                    index = i; break;
                                }
                            }
                            SearchablePopup.Show(pos, panelTypes.ToArray(), index, (i, str) =>
                            {
                                panelType = str;
                                EditorWindow.focusedWindow.Repaint();
                            });
                        }
                    }
                })
                .Space(10)
                .DrawHorizontal(() =>
                {
                    this.Label("Click Choose Model Type", Styles.toolbar);
                    GUILayout.Label("");
                    Rect pos = GUILayoutUtility.GetLastRect();

                    int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos);
                    {
                        if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("ModelType: {0}", modelType))))
                        {
                            if (modelTypes == null)
                            {
                                EditorWindow.focusedWindow.ShowNotification(new GUIContent("Fresh Model Types"));
                                return;
                            }
                            int index = -1;
                            for (int i = 0; i < modelTypes.Count; i++)
                            {
                                if (modelTypes[i] == modelType)
                                {
                                    index = i; break;
                                }
                            }
                            SearchablePopup.Show(pos, modelTypes.ToArray(), index, (i, str) =>
                            {
                                modelType = str;
                                EditorWindow.focusedWindow.Repaint();
                            });
                        }
                    }
                })
                .Space(10)
                .DrawHorizontal(() =>
                {
                    this.Label("Drag Panel Gen Directory", Styles.toolbar);
                    this.Label(PanelGenDir);
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (string.IsNullOrEmpty(PanelGenDir))
                    {
                        rect.DrawOutLine(10, Color.red);
                    }
                    else
                    {
                        rect.DrawOutLine(2, Color.black);
                    }
                    if (rect.Contains(Event.current.mousePosition))
                    {
                        var drag = EditorTools.DragAndDropTool.Drag(Event.current, rect);
                        if (drag.compelete && drag.enterArera && drag.paths.Length == 1)
                        {
                            string path = drag.paths[0];
                            if (path.Contains("Assets"))
                            {
                                if (path.IsDirectory())
                                {
                                    PanelGenDir = path;
                                }
                                else
                                {
                                    PanelGenDir = path.GetDirPath();
                                }
                            }
                        }
                    }
                })
                .Space(10)
                .DrawHorizontal(() =>
                {
                    this.Button(() =>
                    {
                        panelTypes = typeof(UIPanel).GetSubTypesInAssemblys().Select((type) =>
                        {
                            return(type.FullName);
                        }).ToList();
                        modelTypes = typeof(IDataModel).GetSubTypesInAssemblys().Select((type) =>
                        {
                            return(type.FullName);
                        }).ToList();
                    }, "Fresh Panel && Model Types")
                    .Space(20)
                    .Button(() =>
                    {
                        if (string.IsNullOrEmpty(UIMapDir))
                        {
                            EditorWindow.focusedWindow.ShowNotification(new GUIContent("Set UI Map Gen Dir "));
                            return;
                        }
                        if (!File.Exists(UIMapDir.CombinePath(UIMap_CSName)))
                        {
                            EditorWindow.focusedWindow.ShowNotification(new GUIContent("Copy UI Map"));
                            return;
                        }
                        if (string.IsNullOrEmpty(panelType))
                        {
                            EditorWindow.focusedWindow.ShowNotification(new GUIContent("Choose UI Panel Type "));
                            return;
                        }
                        if (string.IsNullOrEmpty(modelType))
                        {
                            EditorWindow.focusedWindow.ShowNotification(new GUIContent("Choose UI Model Type "));
                            return;
                        }
                        if (string.IsNullOrEmpty(PanelGenDir))
                        {
                            EditorWindow.focusedWindow.ShowNotification(new GUIContent("Set UI Panel Gen Dir "));
                            return;
                        }
                        string _modelType = modelType.Split('.').ToList().Last();
                        string paneltype  = panelType.Split('.').ToList().Last();
                        string vmType     = paneltype.Append("ViewModel");
                        string viewType   = paneltype.Append("View");

                        //string viewPath = genpath.CombinePath("View_MVVM.txt");
                        //string VMPath = genpath.CombinePath("VM_MVVM.txt");


                        CreateViewGen(viewGenPath);
                        CreateVMGen(VMGenPath);

                        //v
                        WriteTxt(PanelGenDir.CombinePath(viewType.Append(".cs")), viewGenPath,
                                 (str) => {
                            return(str.Replace("#VMType#", vmType).Replace("#PanelType#", paneltype));
                        }
                                 );
                        //vm
                        WriteTxt(PanelGenDir.CombinePath(vmType.Append(".cs")), VMGenPath,
                                 (str) => {
                            string fieldStr = " ";
                            string syncStr  = " ";
                            Type t          = AppDomain.CurrentDomain.GetAssemblies()
                                              .SelectMany((a) => { return(a.GetTypes()); })
                                              .ToList().Find((type) => { return(type.FullName == modelType); });
                            var fs = t.GetFields();
                            for (int i = 0; i < fs.Length; i++)
                            {
                                var info = fs[i];
                                fieldStr = WriteField(fieldStr, info.FieldType, info.Name);
                                syncStr  = WriteSyncStr(syncStr, info.Name);
                            }

                            return(str.Replace("#ModelType#", _modelType)
                                   .Replace("#FieldString#", fieldStr)
                                   .Replace("#SyncModelValue#", syncStr));
                        }
                                 );

                        WriteMap(UIMapDir.CombinePath(UIMap_CSName), UIMapDir.CombinePath(UIMap_CSName));
                        AssetDatabase.Refresh();
                    }, "Gen");
                });
            }