Ejemplo n.º 1
0
        private void Rebuild()
        {
            scrollArea.Layout.Clear();
            fields = null;

            if (fieldInfos == null || root == null)
            {
                return;
            }

            GUILabel header = new GUILabel(new LocEdString("Properties"), EditorStyles.Header);

            scrollArea.Layout.AddElement(header);

            layouts = new GUIAnimFieldLayouts();
            GUIPanel rootPanel       = scrollArea.Layout.AddPanel();
            GUIPanel mainPanel       = rootPanel.AddPanel();
            GUIPanel underlayPanel   = rootPanel.AddPanel(1);
            GUIPanel overlayPanel    = rootPanel.AddPanel(-1);
            GUIPanel backgroundPanel = rootPanel.AddPanel(2);

            layouts.main       = mainPanel.AddLayoutY();
            layouts.underlay   = underlayPanel.AddLayoutY();
            layouts.overlay    = overlayPanel.AddLayoutY();
            layouts.background = backgroundPanel.AddLayoutY();

            GUIButton catchAll = new GUIButton("", EditorStyles.Blank);

            catchAll.Bounds   = new Rect2I(0, 0, width, height - header.Bounds.height);
            catchAll.OnClick += () => OnEntrySelected(null);

            underlayPanel.AddElement(catchAll);

            layouts.main.AddSpace(5);
            layouts.underlay.AddSpace(5);
            layouts.overlay.AddSpace(5);
            layouts.background.AddSpace(3); // Minor hack: Background starts heigher to get it to center better

            fields = new GUIAnimFieldEntry[fieldInfos.Count];
            for (int i = 0; i < fieldInfos.Count; i++)
            {
                if (string.IsNullOrEmpty(fieldInfos[i].path))
                {
                    continue;
                }

                bool entryIsMissing;
                if (fieldInfos[i].isUserCurve)
                {
                    string pathSuffix;
                    SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix);
                    entryIsMissing = property == null;
                }
                else
                {
                    entryIsMissing = false;
                }

                if (!entryIsMissing)
                {
                    Color[] colors = new Color[fieldInfos[i].curveGroup.curveInfos.Length];
                    for (int j = 0; j < fieldInfos[i].curveGroup.curveInfos.Length; j++)
                    {
                        colors[j] = fieldInfos[i].curveGroup.curveInfos[j].color;
                    }

                    switch (fieldInfos[i].curveGroup.type)
                    {
                    case SerializableProperty.FieldType.Vector2:
                        fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Vector3:
                        fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Vector4:
                        fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Color:
                        fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Bool:
                    case SerializableProperty.FieldType.Int:
                    case SerializableProperty.FieldType.Float:
                    {
                        Color color;
                        if (colors.Length > 0)
                        {
                            color = colors[0];
                        }
                        else
                        {
                            color = Color.White;
                        }

                        fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color);
                        break;
                    }
                    }
                }
                else
                {
                    fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path);
                }

                if (fields[i] != null)
                {
                    fields[i].OnEntrySelected += OnEntrySelected;
                }
            }

            if (fieldInfos.Count == 0)
            {
                GUILabel warningLbl = new GUILabel(new LocEdString("No properties. Add a new property to begin animating."));

                GUILayoutY vertLayout = layouts.main.AddLayoutY();
                vertLayout.AddFlexibleSpace();
                GUILayoutX horzLayout = vertLayout.AddLayoutX();
                vertLayout.AddFlexibleSpace();

                horzLayout.AddFlexibleSpace();
                horzLayout.AddElement(warningLbl);
                horzLayout.AddFlexibleSpace();
            }

            layouts.main.AddSpace(5);
            layouts.underlay.AddSpace(5);
            layouts.overlay.AddSpace(5);
            layouts.background.AddSpace(5);

            layouts.main.AddFlexibleSpace();
            layouts.underlay.AddFlexibleSpace();
            layouts.overlay.AddFlexibleSpace();
            layouts.background.AddFlexibleSpace();
        }
        /// <summary>
        /// Rebuilds the entire GUI based on the current field list and their properties.
        /// </summary>
        private void Rebuild()
        {
            scrollArea.Layout.Clear();
            fields = null;

            if (fieldInfos == null || root == null)
                return;

            GUILabel header = new GUILabel(new LocEdString("Properties"), EditorStyles.Header);
            scrollArea.Layout.AddElement(header);

            layouts = new GUIAnimFieldLayouts();
            GUIPanel rootPanel = scrollArea.Layout.AddPanel();
            GUIPanel mainPanel = rootPanel.AddPanel();
            GUIPanel underlayPanel = rootPanel.AddPanel(1);
            GUIPanel overlayPanel = rootPanel.AddPanel(-1);
            GUIPanel backgroundPanel = rootPanel.AddPanel(2);

            layouts.main = mainPanel.AddLayoutY();
            layouts.underlay = underlayPanel.AddLayoutY();
            layouts.overlay = overlayPanel.AddLayoutY();
            layouts.background = backgroundPanel.AddLayoutY();

            GUIButton catchAll = new GUIButton("", EditorStyles.Blank);
            catchAll.Bounds = new Rect2I(0, 0, width, height - header.Bounds.height);
            catchAll.OnClick += () => OnEntrySelected(null);

            underlayPanel.AddElement(catchAll);

            layouts.main.AddSpace(5);
            layouts.underlay.AddSpace(5);
            layouts.overlay.AddSpace(5);
            layouts.background.AddSpace(3); // Minor hack: Background starts heigher to get it to center better

            fields = new GUIAnimFieldEntry[fieldInfos.Count];
            for (int i = 0; i < fieldInfos.Count; i++)
            {
                if (string.IsNullOrEmpty(fieldInfos[i].path))
                    continue;

                bool entryIsMissing;
                if (fieldInfos[i].curveGroup.isPropertyCurve)
                {
                    string pathSuffix;
                    SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix);
                    entryIsMissing = property == null;
                }
                else
                    entryIsMissing = false;

                if (!entryIsMissing)
                {
                    Color[] colors = new Color[fieldInfos[i].curveGroup.curveInfos.Length];
                    for (int j = 0; j < fieldInfos[i].curveGroup.curveInfos.Length; j++)
                        colors[j] = fieldInfos[i].curveGroup.curveInfos[j].color;

                    switch (fieldInfos[i].curveGroup.type)
                    {
                        case SerializableProperty.FieldType.Vector2:
                            fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors);
                            break;
                        case SerializableProperty.FieldType.Vector3:
                            fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors);
                            break;
                        case SerializableProperty.FieldType.Vector4:
                            fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors);
                            break;
                        case SerializableProperty.FieldType.Color:
                            fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors);
                            break;
                        case SerializableProperty.FieldType.Bool:
                        case SerializableProperty.FieldType.Int:
                        case SerializableProperty.FieldType.Float:
                        {
                            Color color;
                            if (colors.Length > 0)
                                color = colors[0];
                            else
                                color = Color.White;

                            fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color);
                            break;
                        }
                    }
                }
                else
                {
                    fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path);
                }

                if (fields[i] != null)
                    fields[i].OnEntrySelected += OnEntrySelected;
            }

            if (fieldInfos.Count == 0)
            {
                GUILabel warningLbl = new GUILabel(new LocEdString("No properties. Add a new property to begin animating."));

                GUILayoutY vertLayout = layouts.main.AddLayoutY();
                vertLayout.AddFlexibleSpace();
                GUILayoutX horzLayout = vertLayout.AddLayoutX();
                vertLayout.AddFlexibleSpace();

                horzLayout.AddFlexibleSpace();
                horzLayout.AddElement(warningLbl);
                horzLayout.AddFlexibleSpace();
            }

            layouts.main.AddSpace(5);
            layouts.underlay.AddSpace(5);
            layouts.overlay.AddSpace(5);
            layouts.background.AddSpace(5);

            layouts.main.AddFlexibleSpace();
            layouts.underlay.AddFlexibleSpace();
            layouts.overlay.AddFlexibleSpace();
            layouts.background.AddFlexibleSpace();
        }