Exemplo n.º 1
0
        private void OnEnable()
        {
            if (_types == null)
            {
                _types                 = TypeUtil.GetRuntimeFilterTypes.ToArray();
                _ValueEditPopup        = new ValueEditPopupWindow();
                _ValueEditPopup.OnEdit = _save;
                _simpleTypeSelect      = new SimpleTypeSelectPopupWindow(true, _types);
            }

            _varMapSer = serializedObject.FindProperty(IcSkillGroup.VarMapFieldName);

            _group = (IcSkillGroup)target;
        }
        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);
        }