Esempio n. 1
0
        protected SerializationDict <TKey, TValue> GetMap(SerializedProperty property)
        {
            if (Map == null)
            {
                Map = (SerializationDict <TKey, TValue>) this.fieldInfo.GetValue(property.serializedObject.targetObject);
            }

            return(Map);
        }
Esempio n. 2
0
 protected abstract float DrawItem(Rect rect, SerializationDict <TKey, TValue> map,
                                   KeyValuePair <TKey, TValue> item);
        protected override float DrawItem(Rect rect, SerializationDict <string, ValueS> map,
                                          KeyValuePair <string, ValueS> item)
        {
            if (_valueEditPopup == null || _simpleTypeSelectPopup == null)
            {
                _valueEditPopup        = new ValueEditPopupWindow();
                _simpleTypeSelectPopup = new SimpleTypeSelectPopupWindow(true);
            }

            var keyRect = rect;

            keyRect.size = new Vector2(Position.width / 4, ItemHeight());

            var valueRect = keyRect;

            valueRect.position += new Vector2(keyRect.size.x + 10, 0);
            valueRect.size      = rect.size - keyRect.size;
            valueRect.size     += new Vector2(0, keyRect.height);
            {
                string newKey;

                var key   = item.Key;
                var value = item.Value;

                if (value == null)
                {
                    value    = new ValueS();
                    map[key] = value;
                }

                EditorGUI.BeginChangeCheck();
                {
                    newKey = EditorGUI.DelayedTextField(keyRect, key);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    if (!string.IsNullOrEmpty(newKey))
                    {
                        map.Remove(key);
                        map.Add(newKey, item.Value);
                        Save();
                    }
                }

                if (value.ValueType == null)
                {
                    _drawValueTypeSelect(ref valueRect, value);
                }
                else
                {
                    _drawValue(ref valueRect, value);
                }
                var buttonRect = valueRect;
                buttonRect.size = new Vector2(26, 26);
                if (value.ValueType != null)
                {
                    if (GUI.Button(buttonRect, new GUIContent(EditorGUIUtility.FindTexture("Refresh"), $"Change Type,Current Type '{value.ValueType.FullName}'")))
                    {
                        value.ValueType = null;
                        value.SetValue(null);
                        Save();
                        return(0);
                    }

                    buttonRect.position += new Vector2(30, 0);
                }
                buttonRect.position = new Vector2(rect.width - 10, buttonRect.position.y);
                if (GUI.Button(buttonRect, new GUIContent(EditorGUIUtility.FindTexture("d_P4_DeletedLocal"), "Remove Item")))
                {
                    map.Remove(key);
                    Save();
                }
            }
            return(0);
        }