예제 #1
0
        private void CustomAddObjectsButton()
        {
            var usableGestures = GetUsableGestures()
                                 .Where(x => !CodeBlocks.Select(y => y.Gesture)
                                        .Contains(x.GetGesture <Gesture>()));

            var selector = new GenericSelector <ScriptableGesture>(null, true, x => x.name, usableGestures);

            selector.ShowInPopup(Event.current.mousePosition + Vector2.left * 135, 135);
            selector.SelectionTree.Config.DrawSearchToolbar = false;
            selector.SelectionConfirmed += sel =>
            {
                var gestures = sel as IList <ScriptableGesture> ?? sel.ToList();
                foreach (var gesture in gestures)
                {
                    CodeBlocks.Add(new CodeBlock(gesture.GetGesture <Gesture>(), gesture.name));
                }

                CodeBlocks[CodeBlocks.Count - 1].DisableConjunction = true;
                if (CodeBlocks.Count > 1)
                {
                    CodeBlocks[CodeBlocks.Count - 2].DisableConjunction = false;
                }
            };
        }
예제 #2
0
        private GenericSelector <UnityEngine.Object> CreateSelector()
        {
            var t    = isList ? (this.Property.ChildResolver as ICollectionResolver).ElementType : typeof(T);
            var isGo = t == typeof(GameObject);
            var root = this.GetRoot(0);

            var children = root.GetComponentsInChildren(isGo ? typeof(Transform) : t)
                           .Where(x => this.Attribute.IncludeSelf || x.transform != root)
                           .OfType <UnityEngine.Object>();

            if (isGo)
            {
                children = children.OfType <Component>().Select(x => x.gameObject).OfType <UnityEngine.Object>();
            }

            Func <UnityEngine.Object, string> getName = x =>
            {
                var c         = x as Component;
                var o         = x as GameObject;
                var transform = c ? c.transform : o.transform;
                return(this.GetGameObjectPath(root, transform));
            };

            var selector = new GenericSelector <UnityEngine.Object>(
                null, false, getName, children.Where(x => x.GetType().InheritsFrom(t)));

            selector.SelectionTree.Config.DrawSearchToolbar = true;
            selector.SetSelection(this.ValueEntry.SmartValue as UnityEngine.Object);
            selector.SelectionTree.EnumerateTree().AddThumbnailIcons(true);
            selector.SelectionTree.EnumerateTree().Where(x => x.Icon == null).ForEach(x => x.Icon = EditorIcons.UnityGameObjectIcon);
            selector.SelectionTree.EnumerateTree().ForEach(x => x.Toggled = true);
            selector.EnableSingleClickToSelect();

            return(selector);
        }
예제 #3
0
        private GenericSelector <object> CreateSelector()
        {
            IEnumerable <ValueDropdownItem> query = this.getValues();

            if (query == null)
            {
                // God damm it bjarke.
                query = Enumerable.Empty <ValueDropdownItem>();
            }

            var enableSearch = query.Take(10).Count() == 10;

            GenericSelector <object> selector = new GenericSelector <object>(this.Attribute.DropdownTitle, false, query.Select(x => new GenericSelectorItem <object>(x.Text, x.Value)));

            selector.CheckboxToggle = false;
            selector.EnableSingleClickToSelect();

            selector.SelectionTree.Config.DrawSearchToolbar = enableSearch;

            IEnumerable <object> selection = Enumerable.Empty <object>();

            if (!this.isList)
            {
                selection = this.getSelection();
            }

            selection = selection.Select(x => (x == null ? null : x.GetType()) as object);
            selector.SetSelection(selection);
            selector.SelectionTree.EnumerateTree().AddThumbnailIcons(true);

            return(selector);
        }
예제 #4
0
        private void OnBrowseClicked(object sender, RoutedEventArgs e)
        {
            if (Module.ModelTypes == null)
            {
                return;
            }

            List <GenericSelector.Item> items = new List <GenericSelector.Item>();

            GenericSelector.Item current = null;

            foreach (ModelTypes model in Module.ModelTypes)
            {
                GenericSelector.Item item = new GenericSelector.Item(model.Name, model.Id);

                if (model.Id == this.ModelType)
                {
                    current = item;
                }

                items.Add(item);
            }

            GenericSelector.Show("Model Type", current, items, (i) => { this.ModelType = (int)i.Data; });
        }
예제 #5
0
        public void Pick()
        {
            GenericSelector <string> selector = new GenericSelector <string>("", false, item => item, Table <T> .GetAllKeys());

            var window = selector.ShowInPopup();

            selector.SelectionConfirmed += selection => this.prettyName = Table <T> .Find(selection.FirstOrDefault(), true).PrettyName;

            selector.EnableSingleClickToSelect();
        }
예제 #6
0
        private void OnTargetChanged(Object target)
        {
            if (target == null)
            {
                var persistentCall = Property.ValueEntry.WeakSmartValue as PersistentCallBase;

                var call = new PersistentCall();
                call.Set(null, string.Empty, persistentCall.Info);
                Property.BaseValueEntry.WeakSmartValue = call;

                return;
            }

            bool IsValidMethod(MethodInfo info)
            {
                if (info.IsGenericMethod)
                {
                    return(false);
                }
                if (info.ReturnType != typeof(void))
                {
                    return(false);
                }
                if (info.GetParameters().Length > 4)
                {
                    return(false);
                }

                return(true);
            }

            var methods = target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(IsValidMethod).ToArray();

            string GetMethodName(MethodInfo info)
            {
                if (info.Name.Contains("set_"))
                {
                    return($"Properties/{info.GetParameters().First().ParameterType.Name} {info.Name.Remove(0,4)}");
                }
                else if (methods.Count(otherInfo => info.Name == otherInfo.Name) > 1)
                {
                    return($"Methods/{info.Name}/{info.GetNiceName()}");
                }
                else
                {
                    return($"Methods/{info.GetNiceName()}");
                }
            }

            dropdown = new GenericSelector <MethodInfo>(string.Empty, false, GetMethodName, methods);
            dropdown.SelectionTree.DefaultMenuStyle.Height = (int)EditorGUIUtility.singleLineHeight + 4;

            dropdown.SelectionChanged   += SaveMethod;
            dropdown.SelectionConfirmed += SaveMethod;
        }
예제 #7
0
        protected override void OnEnable()
        {
            var types = typeof(Feedback).GetDependencies().ToArray();

            dropdown = new GenericSelector <Type>(string.Empty, false, GetEffectName, types);
            dropdown.SelectionTree.DefaultMenuStyle.Height = (int)EditorGUIUtility.singleLineHeight + 4;
            dropdown.SetSelection(types.First());

            dropdown.SelectionChanged   += items => type = items.FirstOrDefault();
            dropdown.SelectionConfirmed += items => type = items.FirstOrDefault();
        }
예제 #8
0
    private OdinSelector <ValueDropdownItem <int> > DoSelector(Rect buttonRect)
    {
        var dropdownValues = SortingLayer.layers.Select(sortingLayer => new ValueDropdownItem <int>(sortingLayer.name, sortingLayer.id));

        var genericSelector = new GenericSelector <ValueDropdownItem <int> >(dropdownValues);

        buttonRect.xMax = GUIHelper.GetCurrentLayoutRect().xMax;

        genericSelector.EnableSingleClickToSelect();
        genericSelector.ShowInPopup(buttonRect);

        return(genericSelector);
    }
예제 #9
0
        private void OnTargetChanged(Object target)
        {
            if (target == null)
            {
                Property.ValueEntry.WeakSmartValue = "None";
                return;
            }

            var methods = target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public);

            bool IsMethodValid(MethodInfo info)
            {
                return(Attribute.returnType.IsAssignableFrom(info.ReturnType) && info.IsGenericMethod == Attribute.allowGenerics);
            }

            string GetItemName(MethodInfo info)
            {
                var name = info.Name.Remove(0, 4);

                if (info.Name.Contains("set_"))
                {
                    return($"Properties/{name}({info.GetParameters().First().ParameterType.Name} value)");
                }
                else if (info.Name.Contains("get_"))
                {
                    return($"Properties/{info.ReturnType.Name} {name}()");
                }
                else
                {
                    if (methods.Count(method => method.Name == info.Name) > 1)
                    {
                        return($"Methods/{info.Name}/{info.GetNiceName()}");
                    }
                    else
                    {
                        return($"Methods/{info.GetNiceName()}");
                    }
                }
            }

            var items = methods.Where(IsMethodValid).ToArray();

            dropdown = new GenericSelector <MethodInfo>(string.Empty, false, GetItemName, items);
            dropdown.SelectionTree.DefaultMenuStyle.Height = (int)EditorGUIUtility.singleLineHeight + 4;

            dropdown.SelectionChanged   += SaveProperty;
            dropdown.SelectionConfirmed += SaveProperty;
        }
 private void AddLanguage()
 {
     #if UNITY_EDITOR
     var source = Enum.GetValues(typeof(SystemLanguage)).Cast <SystemLanguage>();
     GenericSelector <SystemLanguage> selector = new GenericSelector <SystemLanguage>("Language", false, x => x.ToString(), source);
     selector.SelectionConfirmed += (selection) =>
     {
         var select = selection.FirstOrDefault();
         if (!languages.Contains(select))
         {
             languages.Add(select);
             OnAddLanguage(select);
         }
     };
     selector.ShowInPopup();
     #endif
 }
        private void CustomAddObjectsButton()
        {
            // Gets all GestureObjeects not in TrackedObjects list and created a popup selector with support for multi-selection
            List <GestureObject> availableGestureObjects = GestureManager.Instance.GetGestureObjects();

            var selector = new GenericSelector <GestureObject>(null, true, x => x.Skeleton.StructureName, availableGestureObjects);

            selector.ShowInPopup(Event.current.mousePosition + Vector2.left * 135, 135);
            selector.SelectionTree.Config.DrawSearchToolbar = false;
            selector.SelectionConfirmed += sel =>
            {
                var gestureObjects = sel as IList <GestureObject> ?? sel.ToList();
                foreach (var gestureObject in gestureObjects)
                {
                    _gestureObjectsToTrack.Add(new DetectObjectStructure(gestureObject));
                }
            };
        }
        private void CustomAddStatsButton()
        {
            // Finds all available stat-types and excludes the types that the statList already contains, so we don't get multiple entries of the same type.
            var availableStats = Enum.GetValues(typeof(StatType))
                                 .Cast <StatType>()
                                 .Except(this.stats.Select(x => x.Type))
                                 .Select(x => new StatValue()
            {
                Type = x
            })
                                 .ToList();

            // Here we then quickly make a popup selector, with no title, and support for multi-selection - because why not.
            var selector = new GenericSelector <StatValue>(null, true, x => x.Type.ToString().SplitPascalCase(), availableStats);

            selector.SelectionTree.Config.DrawSearchToolbar = false;
            selector.SelectionConfirmed += this.stats.AddRange;
            selector.ShowInPopup(Event.current.mousePosition + Vector2.left * 45, 90);
        }
예제 #13
0
        private void DrawDropdown()
        {
            IEnumerable <object> newResult = null;

            if (!this.isList)
            {
                GUILayout.BeginHorizontal();
                {
                    var width = 15f;
                    if (this.label != null)
                    {
                        width += GUIHelper.BetterLabelWidth;
                    }

                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, GUIContent.none, this.ShowSelector, GUIStyle.none, GUILayoutOptions.Width(width));

                    if (Event.current.type == EventType.Repaint)
                    {
                        var btnRect = GUILayoutUtility.GetLastRect().AlignRight(15);
                        btnRect.y += 4;
                        SirenixGUIStyles.PaneOptions.Draw(btnRect, GUIContent.none, 0);
                    }

                    GUILayout.BeginVertical();
                    this.CallNextDrawer(null);
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                string valueName = this.GetCurrentValueName();
                newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, valueName, this.ShowSelector);
            }

            if (newResult != null && newResult.Any())
            {
                this.AddResult(newResult);
            }
        }
        private void OnTargetChanged(Object target)
        {
            if (target == null)
            {
                Property.ValueEntry.WeakSmartValue = "None";
                return;
            }

            var methods = target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

            var wantedType = default(Type);

            if (Attribute.genericTypeIndex != -1)
            {
                wantedType = Property.Parent.ValueEntry.TypeOfValue.GetGenericArguments()[Attribute.genericTypeIndex];
            }
            else
            {
                wantedType = Attribute.type;
            }

            bool IsPropertyValid(PropertyInfo info)
            {
                if (!info.CanRead || !info.CanWrite)
                {
                    return(false);
                }
                return(wantedType.IsAssignableFrom(info.PropertyType));
            }

            string GetItemName(PropertyInfo info) => $"{info.PropertyType.Name} {info.Name}";

            var items = methods.Where(IsPropertyValid).ToArray();

            dropdown = new GenericSelector <PropertyInfo>(string.Empty, false, GetItemName, items);
            dropdown.SelectionTree.DefaultMenuStyle.Height = (int)EditorGUIUtility.singleLineHeight + 4;

            dropdown.SelectionChanged   += SaveProperty;
            dropdown.SelectionConfirmed += SaveProperty;
        }
예제 #15
0
        private void DrawDropdown()
        {
            EditorGUI.BeginChangeCheck();

            IEnumerable <object> newResult = null;

            string valueName = GetCurrentValueName();

            if (this.Property.Children.Count > 0)
            {
                Rect valRect;
                this.isToggled.Value = SirenixEditorGUI.Foldout(this.isToggled.Value, this.label, out valRect);
                newResult            = GenericSelector <object> .DrawSelectorDropdown(valRect, valueName, this.ShowSelector);

                if (SirenixEditorGUI.BeginFadeGroup(this, this.isToggled.Value))
                {
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < this.Property.Children.Count; i++)
                    {
                        var child = this.Property.Children[i];
                        child.Draw(child.Label);
                    }
                    EditorGUI.indentLevel--;
                }
                SirenixEditorGUI.EndFadeGroup();
            }
            else
            {
                newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, valueName, this.ShowSelector);
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (newResult != null)
                {
                    this.AddResult(newResult);
                }
            }
        }
예제 #16
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (_odinTest.stringList.Count > 1)
        {
            int selectIndex = 0;
            if (_odinTest.stringList.Contains(_odinTest.selectString))
            {
                for (int i = 0; i < _odinTest.stringList.Count; i++)
                {
                    if (_odinTest.selectString == _odinTest.stringList[i])
                    {
                        selectIndex = i;
                        break;
                    }
                }
            }
            //selectIndex = EditorGUILayout.Popup("SelectString", selectIndex, _odinTest.stringList.ToArray());
            //_odinTest.selectString = _odinTest.stringList[selectIndex];
            if (GUILayout.Button(_odinTest.selectString, "MiniPopup"))
            {
                GenericSelector <string> selector = new GenericSelector <string>("SelectString", false,
                                                                                 _odinTest.stringList);
                selector.SetSelection(_odinTest.stringList[selectIndex]);
                selector.SelectionTree.DefaultMenuStyle.Height = 20;
                selector.SelectionConfirmed += stringList =>
                {
                    _odinTest.selectString = stringList.FirstOrDefault();
                };
                selector.SelectionTree.Config.DrawSearchToolbar = true;

                var window = selector.ShowInPopup();
                window.OnClose += selector.SelectionTree.Selection.ConfirmSelection;
            }
        }
    }
예제 #17
0
    private OdinSelector <string> CreateSelector(Rect buttonRect)
    {
        var eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventPathResolver.GetValue());

        eventInstance.getDescription(out var description);
        description.getParameterDescriptionCount(out var parameterDescriptionCount);

        var parameters = new List <string>();

        for (var i = 0; i < parameterDescriptionCount; i++)
        {
            description.getParameterDescriptionByIndex(i, out var parameterDescription);

            parameters.Add(parameterDescription.name);
        }

        var selector = new GenericSelector <string>(parameters);

        buttonRect.xMax = GUIHelper.GetCurrentLayoutRect().xMax;

        selector.EnableSingleClickToSelect();
        selector.ShowInPopup(buttonRect);
        return(selector);
    }
예제 #18
0
        protected override void DrawPropertyLayout(GUIContent label)
        {
            if (!this.rootIsComponent)
            {
                // Serialization root is not a Component, so it has no children.
                // Should we display a warning or an error here?
                this.CallNextDrawer(label);
                return;
            }

            if (this.rootCount > 1)
            {
                // TODO: Add support for multi-selection to the child-selector dropdown.
                this.CallNextDrawer(label);
                return;
            }

            if (this.isList)
            {
                var prev = CollectionDrawerStaticInfo.NextCustomAddFunction;
                CollectionDrawerStaticInfo.NextCustomAddFunction = ListAddButton;
                this.CallNextDrawer(label);
                CollectionDrawerStaticInfo.NextCustomAddFunction = prev;
                return;
            }

            // If we want it to validate the value each frame.
            // if (Event.current.type == EventType.Layout)
            // {
            //     this.ValidateCurrentValue();
            // }

            if (!this.isValidValues)
            {
                SirenixEditorGUI.ErrorMessageBox("The object must be a child of the selected GameObject.");
            }

            GUILayout.BeginHorizontal();
            {
                var width = 15f;
                if (label != null)
                {
                    width += GUIHelper.BetterLabelWidth;
                }

                var newResult = GenericSelector <UnityEngine.Object> .DrawSelectorDropdown(label, GUIContent.none, this.ShowSelector, GUIStyle.none, GUILayoutOptions.Width(width));

                if (newResult != null && newResult.Any())
                {
                    this.ValueEntry.SmartValue = newResult.FirstOrDefault() as T;
                }

                if (Event.current.type == EventType.Repaint)
                {
                    var btnRect = GUILayoutUtility.GetLastRect().AlignRight(15);
                    btnRect.y += 4;
                    SirenixGUIStyles.PaneOptions.Draw(btnRect, GUIContent.none, 0);
                }

                GUILayout.BeginVertical();
                this.CallNextDrawer(null);
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();
        }
예제 #19
0
        protected override void OnBeginDrawEditors()
        {
            var selected      = this.MenuTree.Selection.FirstOrDefault();
            var toolbarHeight = this.MenuTree.Config.SearchToolbarHeight;

            // Draws a toolbar with the name of the currently selected menu item.
            SirenixEditorGUI.BeginHorizontalToolbar(toolbarHeight);
            {
                if (selected != null)
                {
                    GUILayout.Label(selected.Name);

                    if (selected.Value.GetType() == typeof(Domain))
                    {
                        Domain currentDomain = (Domain)selected.Value;
                        if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add New Feature")))
                        {
                            // Add Feature Here
                            EditorInputDialog.Show("New Feature", "Enter new Feature name", "", ret: val =>
                            {
                                if (!string.IsNullOrEmpty(val))
                                {
                                    var newFeature = new Feature()
                                    {
                                        name       = val,
                                        components = new List <Component>(),
                                    };
                                    _currentFeatures.AddIfNotContains(newFeature);
                                    MenuTree.Add($"{currentDomain.name}/{newFeature.name}", newFeature);
                                    base.TrySelectMenuItemWithObject(newFeature);
                                    hasUnsavedChanges = true;
                                }
                            });
                        }

                        if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add Existing Feature")))
                        {
                            // Add Feature Here
                            var features             = domains.Select(item => item.features).ToList();
                            var distinctFeatures     = features.SelectMany(list => list).Distinct().ToList();
                            var distinctFeatureNames = distinctFeatures.Select(item => item.name).ToList();

                            string selectedFeatureName = distinctFeatureNames[0];

                            GenericSelector <string> selector = new GenericSelector <string>("Title", false, distinctFeatureNames);
                            selector.SetSelection(selectedFeatureName);
                            selector.SelectionTree.Config.DrawSearchToolbar = true;
                            selector.SelectionTree.DefaultMenuStyle.Height  = 22;
                            selector.SelectionConfirmed += (selection) =>
                            {
                                selectedFeatureName = selection.FirstOrDefault();
                                var selectedFeature = new Feature(distinctFeatures.FirstOrDefault(item => item.name == selectedFeatureName));
                                _currentFeatures.AddIfNotContains(selectedFeature);
                                MenuTree.Add($"{currentDomain.name}/{selectedFeature.name}", selectedFeature);
                                base.TrySelectMenuItemWithObject(selectedFeature);
                                hasUnsavedChanges = true;
                            };
                            var popup = selector.ShowInPopup();
                        }

                        if (SirenixEditorGUI.ToolbarButton(new GUIContent("Delete Domain")))
                        {
                            // Delete Domains Here
                            EditorYesNoDialog.Show("Delete Domain?", "Are you sure, this will delete the\n domain with its entire hierarchy!", () =>
                            {
                                domains.Remove(currentDomain);
                                ForceMenuTreeRebuild();
                                hasUnsavedChanges = true;
                            }, () =>
                            {
                                // Do Nothing
                            });
                        }
                    }
                    else if (selected.Value.GetType() == typeof(Feature))
                    {
                        Domain  currentDomain  = (Domain)selected.Parent.Value;
                        Feature currentFeature = (Feature)selected.Value;
                        if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add Component")))
                        {
                            // Add Component Here
                            EditorInputDialog.Show("New Component", "Enter new Component name", "", ret: val =>
                            {
                                if (!string.IsNullOrEmpty(val))
                                {
                                    var newComponent = new Component()
                                    {
                                        name  = val,
                                        asset = null,
                                    };
                                    _currentComponents.Add(newComponent);
                                    MenuTree.Add($"{currentDomain.name}/{currentFeature.name}/{newComponent.name}", newComponent);
                                    base.TrySelectMenuItemWithObject(newComponent);
                                    hasUnsavedChanges = true;
                                }
                            });
                        }

                        if (SirenixEditorGUI.ToolbarButton(new GUIContent("Delete Feature")))
                        {
                            // Delete Domains Here
                            EditorYesNoDialog.Show("Delete Feature?", "Are you sure, this will delete the\n feature with its entire hierarchy!", () =>
                            {
                                currentDomain.features.Remove(currentFeature);
                                ForceMenuTreeRebuild();
                                hasUnsavedChanges = true;
                            }, () =>
                            {
                                // Do Nothing
                            });
                        }
                    }
                    else if (selected.Value.GetType() == typeof(Component))
                    {
                        Domain    currentDomain    = (Domain)selected.Parent.Parent.Value;
                        Feature   currentFeature   = (Feature)selected.Parent.Value;
                        Component currentComponent = (Component)selected.Value;
                        if (SirenixEditorGUI.ToolbarButton(new GUIContent("Delete Component")))
                        {
                            // Delete Domains Here
                            EditorYesNoDialog.Show("Delete Component?", "Are you sure, this will delete the component!", () =>
                            {
                                currentFeature.components.Remove(currentComponent);
                                ForceMenuTreeRebuild();
                                hasUnsavedChanges = true;
                            }, () =>
                            {
                                // Do Nothing
                            });
                        }
                    }
                }

                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add Domain")))
                {
                    // Add Domain Here
                    EditorInputDialog.Show("New Domain", "Enter new Domain name", "", ret: val =>
                    {
                        if (!string.IsNullOrEmpty(val))
                        {
                            var newDomain = new Domain()
                            {
                                name     = val,
                                features = new List <Feature>(),
                            };
                            domains.Add(newDomain);
                            MenuTree.Add(newDomain.name, newDomain);
                            base.TrySelectMenuItemWithObject(newDomain);
                            hasUnsavedChanges = true;
                        }
                    });
                }

                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Save")))
                {
                    SaveChanges();
                    hasUnsavedChanges = false;
                }
            }
            SirenixEditorGUI.EndHorizontalToolbar();
        }
        private void DoProperty <TBase>(IPropertyValueEntry weakEntry, ValueDropdownAttribute attribute, GUIContent label)
        {
            var entry  = (IPropertyValueEntry <TBase>)weakEntry;
            var config = entry.Property.Context.Get(this, "Config", (PropertyConfig <TBase>)null);

            if (config.Value == null)
            {
                config.Value = new PropertyConfig <TBase>();

                Type parentType;

                if (entry.ValueCategory == PropertyValueCategory.Member)
                {
                    parentType = entry.ParentType;
                    config.Value.GetParentValuesFromProperty = entry.Property;
                }
                else
                {
                    parentType = entry.Property.Parent.ParentType;
                    config.Value.GetParentValuesFromProperty = entry.Property.Parent;
                }

                MemberInfo memberInfo = parentType.FindMember()
                                        .HasReturnType <IList <TBase> >(true)
                                        .HasNoParameters()
                                        .IsNamed(attribute.MemberName)
                                        .GetMember <MemberInfo>(out config.Value.ErrorMessage);

                if (config.Value.ErrorMessage == null)
                {
                    string memberName = attribute.MemberName + ((memberInfo is MethodInfo) ? "()" : "");
                    if (memberInfo.IsStatic())
                    {
                        config.Value.StaticValueDropdownGetter = DeepReflection.CreateValueGetter <IList <TBase> >(parentType, memberName);
                    }
                    else
                    {
                        config.Value.InstanceValueDropdownGetter = DeepReflection.CreateWeakInstanceValueGetter <IList <TBase> >(parentType, memberName);
                    }
                    config.Value.IsValueDropdown = false;
                }
                else
                {
                    string errorMessage;

                    memberInfo = parentType.FindMember()
                                 .HasReturnType <IList <ValueDropdownItem <TBase> > >(true)
                                 .HasNoParameters()
                                 .IsNamed(attribute.MemberName)
                                 .GetMember <MemberInfo>(out errorMessage);

                    if (errorMessage == null)
                    {
                        string memberName = attribute.MemberName + ((memberInfo is MethodInfo) ? "()" : "");
                        if (memberInfo.IsStatic())
                        {
                            config.Value.ValueDropdownStaticValueDropdownGetter = DeepReflection.CreateValueGetter <IList <ValueDropdownItem <TBase> > >(parentType, memberName);
                        }
                        else
                        {
                            config.Value.ValueDropdownInstanceValueDropdownGetter = DeepReflection.CreateWeakInstanceValueGetter <IList <ValueDropdownItem <TBase> > >(parentType, memberName);
                        }
                        config.Value.ErrorMessage    = null;
                        config.Value.IsValueDropdown = true;
                    }
                    else
                    {
                        if (config.Value.ErrorMessage != errorMessage)
                        {
                            config.Value.ErrorMessage += " or\n" + errorMessage;
                        }

                        if (IsStrongList)
                        {
                            memberInfo = parentType.FindMember()
                                         .HasReturnType(typeof(IList <>).MakeGenericType(StrongListElementType), true)
                                         .HasNoParameters()
                                         .IsNamed(attribute.MemberName)
                                         .GetMember <MemberInfo>(out errorMessage);

                            if (errorMessage != null)
                            {
                                config.Value.ErrorMessage += " or\n" + errorMessage;

                                Type valueDropdown = typeof(ValueDropdownItem <>).MakeGenericType(StrongListElementType);

                                memberInfo = parentType.FindMember()
                                             .HasReturnType(typeof(IList <>).MakeGenericType(valueDropdown), true)
                                             .HasNoParameters()
                                             .IsNamed(attribute.MemberName)
                                             .GetMember <MemberInfo>(out errorMessage);

                                if (errorMessage != null)
                                {
                                    config.Value.ErrorMessage += " or\n" + errorMessage;
                                }
                                else
                                {
                                    config.Value.ErrorMessage   = null;
                                    config.Value.CallNextDrawer = true;
                                }
                            }
                            else
                            {
                                config.Value.ErrorMessage   = null;
                                config.Value.CallNextDrawer = true;
                            }
                        }
                    }
                }
            }

            if (config.Value.ErrorMessage != null)
            {
                if (entry.ValueCategory == PropertyValueCategory.Member)
                {
                    SirenixEditorGUI.ErrorMessageBox(config.Value.ErrorMessage);
                }

                this.CallNextDrawer(entry, label);
            }
            else if (config.Value.CallNextDrawer)
            {
                this.CallNextDrawer(entry, label);
            }
            else
            {
                if (config.Value.IsValueDropdown)
                {
                    IList <ValueDropdownItem <TBase> > selectList = config.Value.ValueDropdownStaticValueDropdownGetter != null?
                                                                    config.Value.ValueDropdownStaticValueDropdownGetter() :
                                                                        config.Value.ValueDropdownInstanceValueDropdownGetter(config.Value.GetParentValuesFromProperty.ParentValues[0]);

                    selectedValuesBuffer.Clear();

                    if (selectList != null && selectList.Count > 0)
                    {
                        for (int i = 0; i < entry.Values.Count; i++)
                        {
                            var val = entry.Values[i];
                            for (int j = 0; j < selectList.Count; j++)
                            {
                                if (EqualityComparer <TBase> .Default.Equals((TBase)val, selectList[j].Value))
                                {
                                    selectedValuesBuffer.Add(j);
                                }
                            }
                        }
                    }

                    if (SirenixEditorFields.Dropdown <ValueDropdownItem <TBase> >(label, selectedValuesBuffer, selectList, false))
                    {
                        if (selectedValuesBuffer.Count > 0)
                        {
                            entry.SmartValue = selectList[selectedValuesBuffer[0]].Value;
                        }
                    }
                }
                else
                {
                    IList <TBase> selectList = config.Value.StaticValueDropdownGetter != null?
                                               config.Value.StaticValueDropdownGetter() :
                                                   config.Value.InstanceValueDropdownGetter(config.Value.GetParentValuesFromProperty.ParentValues[0]);

                    if (GeneralDrawerConfig.Instance.UseImprovedEnumDropDown)
                    {
                        int  id;
                        bool hasFocus;
                        Rect rect;
                        Action <OdinSelector <TBase> > bindSelector;
                        Func <IEnumerable <TBase> >    getResult;

                        TempFeatureRichControlRect(label, out id, out hasFocus, out rect);

                        if (GenericSelector <TBase> .DrawSelectorButton(rect, entry.SmartValue + "", EditorStyles.popup, id, out bindSelector, out getResult))
                        {
                            var selector = new GenericSelector <TBase>(selectList);
                            selector.SetSelection(entry.SmartValue);
                            selector.ShowInPopup(new Vector2(rect.xMin, rect.yMax));
                            bindSelector(selector);
                        }

                        if (getResult != null)
                        {
                            entry.SmartValue = getResult().FirstOrDefault();
                        }
                    }
                    else
                    {
                        entry.SmartValue = SirenixEditorFields.Dropdown(label, entry.SmartValue, selectList);
                    }
                }
            }
        }
예제 #21
0
        private void DrawDropdown()
        {
            IEnumerable <object> newResult = null;

            //if (this.Attribute.InlineSelector)
            //{
            //    bool recreateBecauseOfListChange = false;

            //    if (Event.current.type == EventType.Layout)
            //    {
            //        var _newCol = this.rawGetter.GetValue();
            //        if (_newCol != this.rawPrevGettedValue)
            //        {
            //            this.ReloadDropdownCollections();
            //            recreateBecauseOfListChange = true;
            //        }

            //        var iList = _newCol as IList;
            //        if (iList != null)
            //        {
            //            if (iList.Count != this.rawPrevGettedValueCount)
            //            {
            //                this.ReloadDropdownCollections();
            //                recreateBecauseOfListChange = true;
            //            }

            //            this.rawPrevGettedValueCount = iList.Count;
            //        }

            //        this.rawPrevGettedValue = _newCol;
            //    }

            //    if (this.inlineSelector == null || recreateBecauseOfListChange)
            //    {
            //        this.inlineSelector = this.CreateSelector();
            //        this.inlineSelector.SelectionChanged += (x) =>
            //        {
            //            this.nextResult = x;
            //        };
            //    }

            //    this.inlineSelector.OnInspectorGUI();

            //    if (this.nextResult != null)
            //    {
            //        newResult = this.nextResult;
            //        this.nextResult = null;
            //    }
            //}
            //else if (this.Attribute.AppendNextDrawer && !this.isList)
            if (this.Attribute.AppendNextDrawer && !this.isList)
            {
                GUILayout.BeginHorizontal();
                {
                    var width = 15f;
                    if (this.label != null)
                    {
                        width += GUIHelper.BetterLabelWidth;
                    }

                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, GUIContent.none, this.ShowSelector, GUIStyle.none, GUILayoutOptions.Width(width));

                    if (Event.current.type == EventType.Repaint)
                    {
                        var btnRect = GUILayoutUtility.GetLastRect().AlignRight(15);
                        btnRect.y += 4;
                        SirenixGUIStyles.PaneOptions.Draw(btnRect, GUIContent.none, 0);
                    }

                    GUILayout.BeginVertical();
                    bool disable = this.Attribute.DisableGUIInAppendedDrawer;
                    if (disable)
                    {
                        GUIHelper.PushGUIEnabled(false);
                    }
                    this.CallNextDrawer(null);
                    if (disable)
                    {
                        GUIHelper.PopGUIEnabled();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                string valueName = GetCurrentValueName();

                if (this.Attribute.HideChildProperties == false && this.Property.Children.Count > 0)
                {
                    Rect valRect;
                    this.isToggled.Value = SirenixEditorGUI.Foldout(this.isToggled.Value, this.label, out valRect);
                    newResult            = GenericSelector <object> .DrawSelectorDropdown(valRect, valueName, this.ShowSelector);

                    if (SirenixEditorGUI.BeginFadeGroup(this, this.isToggled.Value))
                    {
                        EditorGUI.indentLevel++;
                        for (int i = 0; i < this.Property.Children.Count; i++)
                        {
                            var child = this.Property.Children[i];
                            child.Draw(child.Label);
                        }
                        EditorGUI.indentLevel--;
                    }
                    SirenixEditorGUI.EndFadeGroup();
                }
                else
                {
                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, valueName, this.ShowSelector);
                }
            }

            if (newResult != null && newResult.Any())
            {
                this.AddResult(newResult);
            }
        }
예제 #22
0
        private GenericSelector <object> CreateSelector()
        {
            // TODO: Attribute is now cached, could that become a problem here?
            this.Attribute.IsUniqueList = this.Attribute.IsUniqueList || this.Attribute.ExcludeExistingValuesInList;
            IEnumerable <ValueDropdownItem> query = this.getValues();

            if (query == null)
            {
                // God damm it bjarke.
                query = Enumerable.Empty <ValueDropdownItem>();
            }

            var isEmpty = query == null || query.Any() == false;

            if (!isEmpty)
            {
                if (this.isList && this.Attribute.ExcludeExistingValuesInList || (this.isListElement && this.Attribute.IsUniqueList))
                {
                    var list         = query.ToList();
                    var listProperty = this.Property.FindParent(x => (x.ChildResolver as IOrderedCollectionResolver) != null, true);
                    var comparer     = new IValueDropdownEqualityComparer(false);

                    listProperty.ValueEntry.WeakValues.Cast <IEnumerable>()
                    .SelectMany(x => x.Cast <object>())
                    .ForEach(x =>
                    {
                        list.RemoveAll(c => comparer.Equals(c, x));
                    });

                    query = list;
                }
            }

            var enableSearch = this.Attribute.NumberOfItemsBeforeEnablingSearch == 0 || (query != null && query.Take(this.Attribute.NumberOfItemsBeforeEnablingSearch).Count() == this.Attribute.NumberOfItemsBeforeEnablingSearch);

            GenericSelector <object> selector = new GenericSelector <object>(this.Attribute.DropdownTitle, false, query.Select(x => new GenericSelectorItem <object>(x.Text, x.Value)));

            this.enableMultiSelect = this.isList && this.Attribute.IsUniqueList && !this.Attribute.ExcludeExistingValuesInList;

            if (this.Attribute.FlattenTreeView)
            {
                selector.FlattenedTree = true;
            }

            if (this.isList && !this.Attribute.ExcludeExistingValuesInList && this.Attribute.IsUniqueList)
            {
                selector.CheckboxToggle = true;
            }
            else if (this.Attribute.DoubleClickToConfirm == false && !enableMultiSelect)
            {
                selector.EnableSingleClickToSelect();
            }

            if (this.isList && enableMultiSelect)
            {
                selector.SelectionTree.Selection.SupportsMultiSelect = true;
                selector.DrawConfirmSelectionButton = true;
            }

            selector.SelectionTree.Config.DrawSearchToolbar = enableSearch;

            IEnumerable <object> selection = Enumerable.Empty <object>();

            if (!this.isList)
            {
                selection = this.getSelection();
            }
            else if (this.enableMultiSelect)
            {
                selection = this.getSelection().SelectMany(x => (x as IEnumerable).Cast <object>());
            }

            selector.SetSelection(selection);
            selector.SelectionTree.EnumerateTree().AddThumbnailIcons(true);

            if (this.Attribute.ExpandAllMenuItems)
            {
                selector.SelectionTree.EnumerateTree(x => x.Toggled = true);
            }

            if (this.Attribute.SortDropdownItems)
            {
                selector.SelectionTree.SortMenuItemsByName();
            }

            return(selector);
        }
예제 #23
0
 public static void SelectLast <T>(this GenericSelector <T> selector)
 {
     selector.SelectedItem.Value = selector.Items.LastOrDefault();
 }