Beispiel #1
0
 public void AddDecorator(string key, IntDecorator decorator) => intData[key]?.Add(decorator);
Beispiel #2
0
 public void RemoveDecorator(string key, IntDecorator decorator) => intData[key]?.Remove(decorator);
    public static DInt OnGUI(Rect position, DInt dInt, GUIContent label, SerializedObject serializedObject)
    {
        Rect pos = position;

        dInt = dInt ?? new DInt();
        string text = label.text + " = " + dInt.Value;

        pos.height = FIELD_HEIGHT;
        pos.width  = text.Length * CHARACTER_WIDTH;
        EditorGUI.BeginChangeCheck();
        dInt.isExpanded = EditorGUI.Foldout(pos, dInt.isExpanded, text);
        bool sizeChanged = EditorGUI.EndChangeCheck();

        pos.x    += pos.width + 3 * SPACE;
        pos.width = position.width - pos.width;
        pos.xMax -= 3 * SPACE;
        EditorGUI.BeginChangeCheck();
        int result = EditorGUI.DelayedIntField(pos, "[Real Value]", dInt.realValue);

        if (EditorGUI.EndChangeCheck())
        {
            dInt.Value = result;
            dInt.Refresh();
        }

        pos.x    = position.x + SPACE;
        pos.xMax = position.xMax - 2 * SPACE;
        if (dInt.isExpanded)
        {
            pos.height = FIELD_HEIGHT;
            int delete = -1;

            for (int i = 0, l = dInt.DecoratorCount; i < l; i++)
            {
                IntDecorator decorator = dInt.variableDecorators[i];
                pos.y += LINE_HEIGHT;
                Rect rect = new Rect(pos)
                {
                    xMax = pos.xMax - 4 * CHARACTER_WIDTH
                };
                EditorGUI.BeginChangeCheck();

                VariableDecoratorDrawer.OnGUI(rect, decorator, GUIContent.none);

                if (EditorGUI.EndChangeCheck())
                {
                    dInt.Sort();
                    dInt.Refresh();
                }

                rect.x    = rect.xMax + 2 * SPACE;
                rect.xMax = pos.xMax;
                if (GUI.Button(rect, "X"))
                {
                    delete = i;
                }
            }

            if (delete != -1)
            {
                dInt.Remove(delete);
                sizeChanged = true;
            }

            pos.y += LINE_HEIGHT;
            if (GUI.Button(pos, "Add Decorator"))
            {
                pos.height = LINE_HEIGHT * 5;
                dInt.Add(new IntDecorator());
                EditorUtility.SetDirty(serializedObject.targetObject);
                sizeChanged = false;
            }
        }

        if (sizeChanged)
        {
            EditorUtility.SetDirty(serializedObject.targetObject);
        }

        return(dInt);
    }