Пример #1
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;
                }
            }
        }
Пример #2
0
 public override void OnInspectorGUI()
 {
     EGUILayout.DrawScript(target);
     ruler.Platform = EGUILayout.StringPopup("Platform", ruler.Platform, PlatformContents);
     ruler.MaxSize  = EGUILayout.DrawPopup <int>("MaxSize", MaxSizeContents, MaxSizeValues, ruler.MaxSize);
     if (ruler.Platform == PlatformContents[0])
     {
         ruler.Format = EGUILayout.DrawPopup <int>("Format", StandaloneFormatContents, StandaloneFormatValues, ruler.Format);
     }
     else if (ruler.Platform == PlatformContents[1])
     {
         ruler.Format = EGUILayout.DrawPopup <int>("Format", AndroidFormatContents, AndroidFormatValues, ruler.Format);
     }
     else if (ruler.Platform == PlatformContents[2])
     {
         ruler.Format = EGUILayout.DrawPopup <int>("Format", iPhoneFormatContents, iPhoneFormatValues, ruler.Format);
     }
 }
        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;
                }
            }
        }