Пример #1
0
 private void Init(ByEnumProperty <K, V> byEnumProperty)
 {
     if (byEnumProperty.Values == null)
     {
         byEnumProperty.Values = new Dictionary <K, V>();
     }
 }
Пример #2
0
    public override void OnInspectorGUI()
    {
        ByEnumProperty <K, V> projectileEscapeRange = (ByEnumProperty <K, V>)target;

        this.Init(projectileEscapeRange);

        this.foldout = EditorGUILayout.Foldout(this.foldout, target.name, true);

        if (this.foldout)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20f)))
            {
                projectileEscapeRange.Values[(K)Enum.Parse(typeof(K), this.selectedEnum.ToString())] = default(V);
            }

            if (EditorGUILayout.DropdownButton(new GUIContent(this.selectedEnum.ToString()), FocusType.Passive))
            {
                this.DisplayEnumChoice();
            }

            if (Event.current.type == EventType.Repaint)
            {
                this.dropdownRect = GUILayoutUtility.GetLastRect();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical();
            foreach (var key in projectileEscapeRange.Values.Keys.ToList())
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.EnumPopup(key);
                if (typeof(V) == typeof(float))
                {
                    projectileEscapeRange.Values[key] = (V)((object)EditorGUILayout.FloatField(float.Parse(projectileEscapeRange.Values[key].ToString())));
                }

                if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.Width(20f)))
                {
                    projectileEscapeRange.Values.Remove(key);
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }
        }
    }