Ejemplo n.º 1
0
 public void AddDecorator(string key, LongDecorator decorator) => longData[key]?.Add(decorator);
Ejemplo n.º 2
0
 public void RemoveDecorator(string key, LongDecorator decorator) => longData[key]?.Remove(decorator);
Ejemplo n.º 3
0
    public static DLong OnGUI(Rect position, DLong DLong, GUIContent label, SerializedObject serializedObject)
    {
        Rect pos = position;

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

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

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

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

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

            for (int i = 0, l = DLong.DecoratorCount; i < l; i++)
            {
                LongDecorator decorator = DLong.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())
                {
                    DLong.Sort();
                    DLong.Refresh();
                }

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

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

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

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

        return(DLong);
    }