Пример #1
0
        protected override void Initialize()
        {
            var displayAttr = attributes.GetAttribute <DisplayAttribute>();

            _options = new SequenceOptions(displayAttr != null ? displayAttr.SeqOpt : Seq.None);

            if (_options.Readonly)
            {
                displayText += " (Readonly)";
            }

            _advancedKey          = RuntimeHelper.CombineHashCodes(id, "advanced");
            _shouldDrawAddingArea = !_options.Readonly && _elementType.IsA <UnityObject>();

            var perItem = attributes.GetAttribute <PerItemAttribute>();

            if (perItem != null)
            {
                if (perItem.ExplicitAttributes == null)
                {
                    _perItemAttributes = attributes.Where(x => !(x is PerItemAttribute)).ToArray();
                }
                else
                {
                    _perItemAttributes = attributes.Where(x => perItem.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray();
                }
            }

            if (_options.Filter)
            {
                _filter = new TextFilter(null, id, true, null);
            }

            _originalDisplay = displayText;

            if (memberValue == null)
            {
                memberValue = GetNew();
            }

            member.CollectionCount = memberValue.Count;
        }
Пример #2
0
 protected override void Initialize()
 {
     filter = new TextFilter(GetValues(), id, SetValue);
 }
Пример #3
0
        public override void OnGUI()
        {
            if (memberValue == null)
            {
                memberValue = string.Empty;
            }

            if (_values == null)
            {
                UpdateValues();
                if (attribute.Filter)
                {
                    _filter = new TextFilter(_values, id, false, prefs, SetValue);
                }
            }

            string newValue     = null;
            string currentValue = memberValue;

            using (gui.Horizontal())
            {
                if (attribute.TextField)
                {
                    #if PROFILE
                    Profiler.BeginSample("PopupDrawer TextFieldDrop");
                    #endif

                    newValue = gui.TextFieldDropDown(displayText, memberValue, _values);
                    if (currentValue != newValue)
                    {
                        _changed = true;
                    }

                    #if PROFILE
                    Profiler.EndSample();
                    #endif
                }
                else
                {
                    #if PROFILE
                    Profiler.BeginSample("PopupDrawer TextFieldDrop");
                    #endif

                    if (!_currentIndex.HasValue)
                    {
                        if (attribute.TakeLastPathItem)
                        {
                            _currentIndex = _values.IndexOf(x => GetActualValue(x) == currentValue);
                        }
                        else
                        {
                            _currentIndex = _values.IndexOf(currentValue);
                        }
                    }

                    if (_currentIndex == -1)
                    {
                        _currentIndex = 0;
                        if (_values.Length > 0)
                        {
                            SetValue(_values[0]);
                        }
                    }

                    gui.BeginCheck();
                    int selection = gui.Popup(displayText, _currentIndex.Value, _values);
                    if (gui.HasChanged() && _values.Length > 0)
                    {
                        _currentIndex = selection;
                        _changed      = true;
                        newValue      = _values[selection];
                    }

                    #if PROFILE
                    Profiler.EndSample();
                    #endif
                }

                if (attribute.Filter)
                {
                    _filter.OnGUI(gui, 45f);
                }

                if (_changed)
                {
                    _changed = false;
                    SetValue(newValue);
                }

                if (_showUpdateButton && gui.MiniButton("U", "Update popup values", MiniButtonStyle.Right))
                {
                    UpdateValues();
                }
            }
        }
Пример #4
0
        protected override void Initialize()
        {
            _invalidKeyType = !typeof(TK).IsValueType && typeof(TK) != typeof(string);
            if (_invalidKeyType)
            {
                return;
            }

            _keyElements   = new List <EditorMember>();
            _valueElements = new List <EditorMember>();

            var perKey = attributes.GetAttribute <PerKeyAttribute>();

            if (perKey != null)
            {
                if (perKey.ExplicitAttributes == null)
                {
                    _perKeyAttributes = attributes.Where(x => !(x is PerKeyAttribute)).ToArray();
                }
                else
                {
                    _perKeyAttributes = attributes.Where(x => perKey.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray();
                }
            }

            var perValue = attributes.GetAttribute <PerValueAttribute>();

            if (perValue != null)
            {
                if (perValue.ExplicitAttributes == null)
                {
                    _perValueAttributes = attributes.Where(x => !(x is PerValueAttribute)).ToArray();
                }
                else
                {
                    _perValueAttributes = attributes.Where(x => perValue.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray();
                }
            }

            var displayAttr = attributes.GetAttribute <DisplayAttribute>();

            if (displayAttr != null)
            {
                _formatPairPattern = displayAttr.FormatKVPair;
            }

            _options = new DictionaryOptions(displayAttr != null ? displayAttr.DictOpt : Dict.None);

            if (_formatPairPattern.IsNullOrEmpty())
            {
                _formatPairPattern = "[$key, $value]";
            }

            if (_options.Readonly)
            {
                displayText += " (Readonly)";
            }

            _originalDisplay = displayText;

            if (_options.Filter)
            {
                _filter = new TextFilter(null, id, true, null);
            }

            if (memberValue == null && !_options.ManualAlloc)
            {
                memberValue = memberType.Instance <IDictionary <TK, TV> >();
            }

            if (memberValue != null)
            {
                member.CollectionCount = memberValue.Count;
            }

            if (_options.TempKey)
            {
                _tempKeyMember = EditorMember.WrapMember(GetType().GetField("_tempKey", Flags.InstanceAnyVisibility),
                                                         this, unityTarget, RuntimeHelper.CombineHashCodes(id, "temp"), null);
                _tempKeyMember.DisplayText = string.Empty;
                _tempKey = GetNewKey(memberValue);
            }

            #if DBG
            Log("Dictionary drawer Initialized (" + dictionaryName + ")");
            #endif
        }