Ver Fonte

Added color tags to animated field display

BearishSun há 9 anos atrás
pai
commit
c366b3f9bc

+ 26 - 15
Source/MBansheeEditor/Windows/Animation/EditorAnimInfo.cs

@@ -18,7 +18,7 @@ namespace BansheeEditor
     internal struct FieldAnimCurves
     {
         public SerializableProperty.FieldType type;
-        public EdAnimationCurve[] curves;
+        public CurveDrawInfo[] curveInfos;
     }
 
     /// <summary>
@@ -107,6 +107,7 @@ namespace BansheeEditor
             if (editorCurveData == null)
                 editorCurveData = new EditorAnimClipTangents();
 
+            int globalCurveIdx = 0;
             Action<NamedVector3Curve[], EditorVector3CurveTangents[], string> loadVector3Curve =
                 (curves, tangents, subPath) =>
                 {
@@ -132,11 +133,19 @@ namespace BansheeEditor
 
                         FieldAnimCurves fieldCurves = new FieldAnimCurves();
                         fieldCurves.type = SerializableProperty.FieldType.Vector3;
-                        fieldCurves.curves = new EdAnimationCurve[3];
+                        fieldCurves.curveInfos = new CurveDrawInfo[3];
 
-                        fieldCurves.curves[0] = new EdAnimationCurve(curveEntry.X, tangentsX);
-                        fieldCurves.curves[1] = new EdAnimationCurve(curveEntry.Y, tangentsY);
-                        fieldCurves.curves[2] = new EdAnimationCurve(curveEntry.Z, tangentsZ);
+                        fieldCurves.curveInfos[0] = new CurveDrawInfo();
+                        fieldCurves.curveInfos[0].curve = new EdAnimationCurve(curveEntry.X, tangentsX);
+                        fieldCurves.curveInfos[0].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);
+
+                        fieldCurves.curveInfos[1] = new CurveDrawInfo();
+                        fieldCurves.curveInfos[1].curve = new EdAnimationCurve(curveEntry.Y, tangentsY);
+                        fieldCurves.curveInfos[1].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);
+
+                        fieldCurves.curveInfos[2] = new CurveDrawInfo();
+                        fieldCurves.curveInfos[2].curve = new EdAnimationCurve(curveEntry.Z, tangentsZ);
+                        fieldCurves.curveInfos[2].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);
 
                         string curvePath = curveEntry.Name.TrimEnd('/') + subPath;
                         clipInfo.curves[curvePath] = fieldCurves;
@@ -232,7 +241,7 @@ namespace BansheeEditor
                         fieldCurves.type = SerializableProperty.FieldType.Color;
                 }
 
-                fieldCurves.curves = new EdAnimationCurve[numCurves];
+                fieldCurves.curveInfos = new CurveDrawInfo[numCurves];
 
                 for (int i = 0; i < numCurves; i++)
                 {
@@ -243,7 +252,9 @@ namespace BansheeEditor
                     if (tangentIdx != -1)
                         tangents = editorCurveData.floatCurves[tangentIdx].tangents;
 
-                    fieldCurves.curves[i] = new EdAnimationCurve(clipCurves.FloatCurves[curveIdx].Curve, tangents);
+                    fieldCurves.curveInfos[i] = new CurveDrawInfo();
+                    fieldCurves.curveInfos[i].curve = new EdAnimationCurve(clipCurves.FloatCurves[curveIdx].Curve, tangents);
+                    fieldCurves.curveInfos[i].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);
                 }
 
                 string curvePath = KVP.Key;
@@ -305,15 +316,15 @@ namespace BansheeEditor
                         string curvePath = sb.ToString();
 
                         NamedVector3Curve curve = new NamedVector3Curve(curvePath,
-                            new AnimationCurve(kvp.Value.curves[0].KeyFrames),
-                            new AnimationCurve(kvp.Value.curves[1].KeyFrames),
-                            new AnimationCurve(kvp.Value.curves[2].KeyFrames));
+                            new AnimationCurve(kvp.Value.curveInfos[0].curve.KeyFrames),
+                            new AnimationCurve(kvp.Value.curveInfos[1].curve.KeyFrames),
+                            new AnimationCurve(kvp.Value.curveInfos[2].curve.KeyFrames));
 
                         EditorVector3CurveTangents tangents = new EditorVector3CurveTangents();
                         tangents.name = curvePath;
-                        tangents.tangentsX = kvp.Value.curves[0].TangentModes;
-                        tangents.tangentsY = kvp.Value.curves[1].TangentModes;
-                        tangents.tangentsZ = kvp.Value.curves[2].TangentModes;
+                        tangents.tangentsX = kvp.Value.curveInfos[0].curve.TangentModes;
+                        tangents.tangentsY = kvp.Value.curveInfos[1].curve.TangentModes;
+                        tangents.tangentsZ = kvp.Value.curveInfos[2].curve.TangentModes;
 
                         if (lastEntry == "Position")
                         {
@@ -338,11 +349,11 @@ namespace BansheeEditor
                             string path = kvp.Key + subPath;
 
                             NamedFloatCurve curve = new NamedFloatCurve(path,
-                            new AnimationCurve(kvp.Value.curves[idx].KeyFrames));
+                            new AnimationCurve(kvp.Value.curveInfos[idx].curve.KeyFrames));
 
                             EditorFloatCurveTangents tangents = new EditorFloatCurveTangents();
                             tangents.name = path;
-                            tangents.tangents = kvp.Value.curves[idx].TangentModes;
+                            tangents.tangents = kvp.Value.curveInfos[idx].curve.TangentModes;
 
                             floatCurves.Add(curve);
                             floatTangents.Add(tangents);

+ 46 - 21
Source/MBansheeEditor/Windows/Animation/GUIAnimFieldDisplay.cs

@@ -164,25 +164,37 @@ namespace BansheeEditor
 
                 if (!entryIsMissing)
                 {
-                    switch (fieldInfos[i].type)
+                    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);
+                            fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors);
                             break;
                         case SerializableProperty.FieldType.Vector3:
-                            fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path);
+                            fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors);
                             break;
                         case SerializableProperty.FieldType.Vector4:
-                            fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path);
+                            fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors);
                             break;
                         case SerializableProperty.FieldType.Color:
-                            fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path);
+                            fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors);
                             break;
                         case SerializableProperty.FieldType.Bool:
                         case SerializableProperty.FieldType.Int:
                         case SerializableProperty.FieldType.Float:
-                            fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path);
+                        {
+                            Color color;
+                            if (colors.Length > 0)
+                                color = colors[0];
+                            else
+                                color = Color.White;
+
+                            fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color);
                             break;
+                        }
                     }
                 }
                 else
@@ -240,7 +252,7 @@ namespace BansheeEditor
             this.path = path;
 
             GUILayoutX toggleLayout = layouts.main.AddLayoutX();
-            toggleLayout.AddSpace(child ? 30 : 15);
+            toggleLayout.AddSpace(child ? 45 : 30);
 
             selectionBtn = new GUIButton(GetDisplayName(path, child), EditorStyles.Label, GUIOption.FlexibleWidth());
             selectionBtn.OnClick += () =>
@@ -409,11 +421,18 @@ namespace BansheeEditor
         private GUILayoutX underlayLayout;
         private GUILabel overlaySpacing;
 
-        public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, bool child = false)
+        public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, Color color, bool child = false)
             : base(layouts, path, child)
         {
             valueDisplay = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
             underlayLayout = layouts.underlay.AddLayoutX();
+            underlayLayout.AddSpace(child ? 30 : 15);
+
+            GUITexture colorSquare = new GUITexture(Builtin.WhiteTexture, 
+                GUIOption.FixedWidth(10), GUIOption.FixedHeight(10));
+            colorSquare.SetTint(color);
+
+            underlayLayout.AddElement(colorSquare);
             underlayLayout.AddFlexibleSpace();
             underlayLayout.AddElement(valueDisplay);
             underlayLayout.AddSpace(50);
@@ -448,7 +467,7 @@ namespace BansheeEditor
 
         protected GUIAnimSimpleEntry[] children;
 
-        public GUIAnimComplexEntry(GUIAnimFieldLayouts layouts, string path, string[] childEntries)
+        public GUIAnimComplexEntry(GUIAnimFieldLayouts layouts, string path, string[] childEntries, Color[] colors)
             : base(layouts, path, false)
         {
             foldout = new GUIToggle("", EditorStyles.Expand);
@@ -468,7 +487,13 @@ namespace BansheeEditor
             children = new GUIAnimSimpleEntry[childEntries.Length];
             for (int i = 0; i < childEntries.Length; i++)
             {
-                children[i] = new GUIAnimSimpleEntry(layouts, path + childEntries[i], true);
+                Color color;
+                if (i < colors.Length)
+                    color = colors[i];
+                else
+                    color = Color.White;
+
+                children[i] = new GUIAnimSimpleEntry(layouts, path + childEntries[i], color, true);
                 children[i].OnEntrySelected += x => { OnEntrySelected?.Invoke(x); };
             }
 
@@ -489,8 +514,8 @@ namespace BansheeEditor
 
     internal class GUIAnimVec2Entry : GUIAnimComplexEntry
     {
-        public GUIAnimVec2Entry(GUIAnimFieldLayouts layouts, string path)
-            : base(layouts, path,  new[] { ".x", ".y" })
+        public GUIAnimVec2Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
+            : base(layouts, path,  new[] { ".x", ".y" }, colors)
         { }
 
         public override void SetValue(object value)
@@ -506,8 +531,8 @@ namespace BansheeEditor
 
     internal class GUIAnimVec3Entry : GUIAnimComplexEntry
     {
-        public GUIAnimVec3Entry(GUIAnimFieldLayouts layouts, string path)
-            : base(layouts, path, new[] { ".x", ".y", ".z" })
+        public GUIAnimVec3Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
+            : base(layouts, path, new[] { ".x", ".y", ".z" }, colors)
         { }
 
         public override void SetValue(object value)
@@ -524,8 +549,8 @@ namespace BansheeEditor
 
     internal class GUIAnimVec4Entry : GUIAnimComplexEntry
     {
-        public GUIAnimVec4Entry(GUIAnimFieldLayouts layouts, string path)
-            : base(layouts, path,  new[] { ".x", ".y", ".z", ".w" })
+        public GUIAnimVec4Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
+            : base(layouts, path,  new[] { ".x", ".y", ".z", ".w" }, colors)
         { }
 
         public override void SetValue(object value)
@@ -543,8 +568,8 @@ namespace BansheeEditor
 
     internal class GUIAnimColorEntry : GUIAnimComplexEntry
     {
-        public GUIAnimColorEntry(GUIAnimFieldLayouts layouts, string path)
-            : base(layouts, path, new[] { ".r", ".g", ".b", ".a" })
+        public GUIAnimColorEntry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
+            : base(layouts, path, new[] { ".r", ".g", ".b", ".a" }, colors)
         { }
 
         public override void SetValue(object value)
@@ -590,15 +615,15 @@ namespace BansheeEditor
 
     internal struct AnimFieldInfo
     {
-        public AnimFieldInfo(string path, SerializableProperty.FieldType type, bool isUserCurve)
+        public AnimFieldInfo(string path, FieldAnimCurves curveGroup, bool isUserCurve)
         {
             this.path = path;
-            this.type = type;
+            this.curveGroup = curveGroup;
             this.isUserCurve = isUserCurve;
         }
 
         public string path;
-        public SerializableProperty.FieldType type;
+        public FieldAnimCurves curveGroup;
         public bool isUserCurve;
     }
 

+ 48 - 34
Source/MBansheeEditor/Windows/Animation/GUICurveDrawing.cs

@@ -21,7 +21,7 @@ namespace BansheeEditor
         private static readonly Color COLOR_MID_GRAY = new Color(90.0f / 255.0f, 90.0f / 255.0f, 90.0f / 255.0f, 1.0f);
         private static readonly Color COLOR_DARK_GRAY = new Color(40.0f / 255.0f, 40.0f / 255.0f, 40.0f / 255.0f, 1.0f);
 
-        private EdAnimationCurve[] curves;
+        private CurveDrawInfo[] curveInfos;
         private bool[][] selectedKeyframes;
 
         private float yRange = 20.0f;
@@ -35,12 +35,12 @@ namespace BansheeEditor
         /// <param name="layout">Layout into which to add the GUI element.</param>
         /// <param name="width">Width of the element in pixels.</param>
         /// <param name="height">Height of the element in pixels.</param>
-        /// <param name="curves">Initial set of curves to display. </param>
-        public GUICurveDrawing(GUILayout layout, int width, int height, EdAnimationCurve[] curves)
+        /// <param name="curveInfos">Initial set of curves to display. </param>
+        public GUICurveDrawing(GUILayout layout, int width, int height, CurveDrawInfo[] curveInfos)
             :base(layout, width, height)
         {
             tickHandler = new GUIGraphTicks(GUITickStepType.Time);
-            this.curves = curves;
+            this.curveInfos = curveInfos;
             
             ClearSelectedKeyframes(); // Makes sure the array is initialized
         }
@@ -48,10 +48,10 @@ namespace BansheeEditor
         /// <summary>
         /// Change the set of curves to display.
         /// </summary>
-        /// <param name="curves">New set of curves to draw on the GUI element.</param>
-        public void SetCurves(EdAnimationCurve[] curves)
+        /// <param name="curveInfos">New set of curves to draw on the GUI element.</param>
+        public void SetCurves(CurveDrawInfo[] curveInfos)
         {
-            this.curves = curves;
+            this.curveInfos = curveInfos;
         }
         
         /// <summary>
@@ -100,11 +100,11 @@ namespace BansheeEditor
         /// </summary>
         public void ClearSelectedKeyframes()
         {
-            selectedKeyframes = new bool[curves.Length][];
+            selectedKeyframes = new bool[curveInfos.Length][];
 
-            for (int i = 0; i < curves.Length; i++)
+            for (int i = 0; i < curveInfos.Length; i++)
             {
-                KeyFrame[] keyframes = curves[i].KeyFrames;
+                KeyFrame[] keyframes = curveInfos[i].curve.KeyFrames;
                 selectedKeyframes[i] = new bool[keyframes.Length];
             }
         }
@@ -121,9 +121,9 @@ namespace BansheeEditor
             keyframe = new KeyframeRef();
 
             float nearestDistance = float.MaxValue;
-            for (int i = 0; i < curves.Length; i++)
+            for (int i = 0; i < curveInfos.Length; i++)
             {
-                EdAnimationCurve curve = curves[i];
+                EdAnimationCurve curve = curveInfos[i].curve;
                 KeyFrame[] keyframes = curve.KeyFrames;
 
                 for (int j = 0; j < keyframes.Length; j++)
@@ -160,9 +160,9 @@ namespace BansheeEditor
             tangent = new TangentRef();
 
             float nearestDistance = float.MaxValue;
-            for (int i = 0; i < curves.Length; i++)
+            for (int i = 0; i < curveInfos.Length; i++)
             {
-                EdAnimationCurve curve = curves[i];
+                EdAnimationCurve curve = curveInfos[i].curve;
                 KeyFrame[] keyframes = curve.KeyFrames;
 
                 for (int j = 0; j < keyframes.Length; j++)
@@ -264,6 +264,20 @@ namespace BansheeEditor
             return pixelCoords;
         }
 
+        /// <summary>
+        /// Generates a unique color based on the provided index.
+        /// </summary>
+        /// <param name="idx">Index to use for generating a color. Should be less than 30 in order to guarantee reasonably
+        /// different colors.</param>
+        /// <returns>Unique color.</returns>
+        public static Color GetUniqueColor(int idx)
+        {
+            const int COLOR_SPACING = 359 / 15;
+
+            float hue = ((idx * COLOR_SPACING) % 359) / 359.0f;
+            return Color.HSV2RGB(new Color(hue, 175.0f / 255.0f, 175.0f / 255.0f));
+        }
+
         /// <summary>
         /// Draws a vertical frame marker on the curve area.
         /// </summary>
@@ -419,7 +433,7 @@ namespace BansheeEditor
         {
             canvas.Clear();
 
-            if (curves == null)
+            if (curveInfos == null)
                 return;
 
             tickHandler.SetRange(rangeOffset, rangeOffset + GetRange(true), drawableWidth + GUIGraphTime.PADDING);
@@ -445,13 +459,12 @@ namespace BansheeEditor
 
             // Draw curves
             int curveIdx = 0;
-            foreach (var curve in curves)
+            foreach (var curveInfo in curveInfos)
             {
-                Color color = GetUniqueColor(curveIdx);
-                DrawCurve(curve, color);
+                DrawCurve(curveInfo.curve, curveInfo.color);
 
                 // Draw keyframes
-                KeyFrame[] keyframes = curve.KeyFrames;
+                KeyFrame[] keyframes = curveInfo.curve.KeyFrames;
 
                 for (int i = 0; i < keyframes.Length; i++)
                 {
@@ -460,7 +473,7 @@ namespace BansheeEditor
                     DrawKeyframe(keyframes[i].time, keyframes[i].value, isSelected);
 
                     if (isSelected)
-                        DrawTangents(keyframes[i], curve.TangentModes[i]);
+                        DrawTangents(keyframes[i], curveInfo.curve.TangentModes[i]);
                 }
 
                 curveIdx++;
@@ -471,20 +484,6 @@ namespace BansheeEditor
                 DrawFrameMarker(GetTimeForFrame(markedFrameIdx), Color.BansheeOrange, true);
         }
 
-        /// <summary>
-        /// Generates a unique color based on the provided index.
-        /// </summary>
-        /// <param name="idx">Index to use for generating a color. Should be less than 30 in order to guarantee reasonably
-        /// different colors.</param>
-        /// <returns>Unique color.</returns>
-        private Color GetUniqueColor(int idx)
-        {
-            const int COLOR_SPACING = 359 / 15;
-
-            float hue = ((idx * COLOR_SPACING) % 359) / 359.0f;
-            return Color.HSV2RGB(new Color(hue, 175.0f / 255.0f, 175.0f / 255.0f));
-        }
-
         /// <summary>
         /// Checks is the provided key-frame currently marked as selected.
         /// </summary>
@@ -604,5 +603,20 @@ namespace BansheeEditor
         }
     }
 
+    /// <summary>
+    /// Information necessary to draw a curve.
+    /// </summary>
+    internal struct CurveDrawInfo
+    {
+        public CurveDrawInfo(EdAnimationCurve curve, Color color)
+        {
+            this.curve = curve;
+            this.color = color;
+        }
+
+        public EdAnimationCurve curve;
+        public Color color;
+    }
+
     /** }@ */
 }

+ 18 - 18
Source/MBansheeEditor/Windows/Animation/GUICurveEditor.cs

@@ -79,7 +79,7 @@ namespace BansheeEditor
         private ContextMenu eventContextMenu;
         private Vector2I contextClickPosition;
 
-        private EdAnimationCurve[] curves = new EdAnimationCurve[0];
+        private CurveDrawInfo[] curveInfos = new CurveDrawInfo[0];
         private bool disableCurveEdit = false;
 
         private float xRange = 60.0f;
@@ -273,7 +273,7 @@ namespace BansheeEditor
             drawingPanel = gui.AddPanel();
             drawingPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT);
 
-            guiCurveDrawing = new GUICurveDrawing(drawingPanel, width, height - TIMELINE_HEIGHT - EVENTS_HEIGHT, curves);
+            guiCurveDrawing = new GUICurveDrawing(drawingPanel, width, height - TIMELINE_HEIGHT - EVENTS_HEIGHT, curveInfos);
             guiCurveDrawing.SetRange(60.0f, 20.0f);
 
             GUIPanel sidebarPanel = gui.AddPanel(-10);
@@ -505,7 +505,7 @@ namespace BansheeEditor
                                 draggedKeyframes.Clear();
                                 foreach (var selectedEntry in selectedKeyframes)
                                 {
-                                    EdAnimationCurve curve = curves[selectedEntry.curveIdx];
+                                    EdAnimationCurve curve = curveInfos[selectedEntry.curveIdx].curve;
                                     KeyFrame[] keyFrames = curve.KeyFrames;
 
                                     DraggedKeyframes newEntry = new DraggedKeyframes();
@@ -539,7 +539,7 @@ namespace BansheeEditor
 
                             foreach (var draggedEntry in draggedKeyframes)
                             {
-                                EdAnimationCurve curve = curves[draggedEntry.curveIdx];
+                                EdAnimationCurve curve = curveInfos[draggedEntry.curveIdx].curve;
 
                                 for (int i = 0; i < draggedEntry.keys.Count; i++)
                                 {
@@ -574,7 +574,7 @@ namespace BansheeEditor
                         }
                         else if (isMousePressedOverTangent && !disableCurveEdit)
                         {
-                            EdAnimationCurve curve = curves[draggedTangent.keyframeRef.curveIdx];
+                            EdAnimationCurve curve = curveInfos[draggedTangent.keyframeRef.curveIdx].curve;
                             KeyFrame keyframe = curve.KeyFrames[draggedTangent.keyframeRef.keyIdx];
 
                             Vector2 keyframeCurveCoords = new Vector2(keyframe.time, keyframe.value);
@@ -649,10 +649,10 @@ namespace BansheeEditor
         /// Change the set of curves to display.
         /// </summary>
         /// <param name="curves">New set of curves to draw on the GUI element.</param>
-        public void SetCurves(EdAnimationCurve[] curves)
+        public void SetCurves(CurveDrawInfo[] curveInfos)
         {
-            this.curves = curves;
-            guiCurveDrawing.SetCurves(curves);
+            this.curveInfos = curveInfos;
+            guiCurveDrawing.SetCurves(curveInfos);
 
             Redraw();
         }
@@ -722,13 +722,13 @@ namespace BansheeEditor
 
             if (!disableCurveEdit)
             {
-                foreach (var curve in curves)
+                foreach (var curveInfo in curveInfos)
                 {
                     float t = guiCurveDrawing.GetTimeForFrame(markedFrameIdx);
-                    float value = curve.Evaluate(t);
+                    float value = curveInfo.curve.Evaluate(t);
 
-                    curve.AddKeyframe(t, value);
-                    curve.Apply();
+                    curveInfo.curve.AddKeyframe(t, value);
+                    curveInfo.curve.Apply();
                 }
             }
             else
@@ -805,7 +805,7 @@ namespace BansheeEditor
 
             foreach (var selectedEntry in selectedKeyframes)
             {
-                EdAnimationCurve curve = curves[selectedEntry.curveIdx];
+                EdAnimationCurve curve = curveInfos[selectedEntry.curveIdx].curve;
 
                 foreach (var keyframeIdx in selectedEntry.keyIndices)
                 {
@@ -859,13 +859,13 @@ namespace BansheeEditor
 
                 if (!disableCurveEdit)
                 {
-                    foreach (var curve in curves)
+                    foreach (var curveInfo in curveInfos)
                     {
                         float t = curveCoord.x;
                         float value = curveCoord.y;
 
-                        curve.AddKeyframe(t, value);
-                        curve.Apply();
+                        curveInfo.curve.AddKeyframe(t, value);
+                        curveInfo.curve.Apply();
                     }
                 }
                 else
@@ -913,7 +913,7 @@ namespace BansheeEditor
             {
                 foreach (var selectedEntry in selectedKeyframes)
                 {
-                    EdAnimationCurve curve = curves[selectedEntry.curveIdx];
+                    EdAnimationCurve curve = curveInfos[selectedEntry.curveIdx].curve;
 
                     // Sort keys from highest to lowest so the indices don't change
                     selectedEntry.keyIndices.Sort((x, y) =>
@@ -1038,7 +1038,7 @@ namespace BansheeEditor
             if (selectedKeyframes.Count == 0)
                 return;
 
-            EdAnimationCurve curve = curves[selectedKeyframes[0].curveIdx];
+            EdAnimationCurve curve = curveInfos[selectedKeyframes[0].curveIdx].curve;
             KeyFrame[] keyFrames = curve.KeyFrames;
 
             int keyIndex = selectedKeyframes[0].keyIndices[0];

+ 61 - 42
Source/MBansheeEditor/Windows/AnimationWindow.cs

@@ -561,7 +561,7 @@ namespace BansheeEditor
             persistentData.dirtyAnimClips[clip.UUID] = clipInfo;
 
             foreach (var curve in clipInfo.curves)
-                guiFieldDisplay.AddField(new AnimFieldInfo(curve.Key, curve.Value.type, !clipInfo.isImported));
+                guiFieldDisplay.AddField(new AnimFieldInfo(curve.Key, curve.Value, !clipInfo.isImported));
 
             guiCurveEditor.Events = clipInfo.events;
             guiCurveEditor.DisableCurveEdit = clipInfo.isImported;
@@ -655,7 +655,7 @@ namespace BansheeEditor
                             Vector2 value = new Vector2();
 
                             for (int i = 0; i < 2; i++)
-                                value[i] = kvp.Value.curves[i].Evaluate(time, false);
+                                value[i] = kvp.Value.curveInfos[i].curve.Evaluate(time, false);
 
                             fieldValue.value = value;
                         }
@@ -665,7 +665,7 @@ namespace BansheeEditor
                             Vector3 value = new Vector3();
 
                             for (int i = 0; i < 3; i++)
-                                value[i] = kvp.Value.curves[i].Evaluate(time, false);
+                                value[i] = kvp.Value.curveInfos[i].curve.Evaluate(time, false);
 
                             fieldValue.value = value;
                         }
@@ -675,7 +675,7 @@ namespace BansheeEditor
                             Vector4 value = new Vector4();
 
                             for (int i = 0; i < 4; i++)
-                                value[i] = kvp.Value.curves[i].Evaluate(time, false);
+                                value[i] = kvp.Value.curveInfos[i].curve.Evaluate(time, false);
 
                             fieldValue.value = value;
                         }
@@ -685,7 +685,7 @@ namespace BansheeEditor
                             Color value = new Color();
 
                             for (int i = 0; i < 4; i++)
-                                value[i] = kvp.Value.curves[i].Evaluate(time, false);
+                                value[i] = kvp.Value.curveInfos[i].curve.Evaluate(time, false);
 
                             fieldValue.value = value;
                         }
@@ -693,7 +693,7 @@ namespace BansheeEditor
                     case SerializableProperty.FieldType.Bool:
                     case SerializableProperty.FieldType.Int:
                     case SerializableProperty.FieldType.Float:
-                        fieldValue.value = kvp.Value.curves[0].Evaluate(time, false); ;
+                        fieldValue.value = kvp.Value.curveInfos[0].curve.Evaluate(time, false); ;
                         break;
                 }
 
@@ -703,9 +703,9 @@ namespace BansheeEditor
             guiFieldDisplay.SetDisplayValues(values.ToArray());
         }
 
-        private EdAnimationCurve[] GetDisplayedCurves()
+        private CurveDrawInfo[] GetDisplayedCurves()
         {
-            List<EdAnimationCurve> curvesToDisplay = new List<EdAnimationCurve>();
+            List<CurveDrawInfo> curvesToDisplay = new List<CurveDrawInfo>();
 
             if (selectedFields.Count == 0) // Display all if nothing is selected
             {
@@ -714,17 +714,17 @@ namespace BansheeEditor
 
                 foreach (var curve in clipInfo.curves)
                 {
-                    for (int i = 0; i < curve.Value.curves.Length; i++)
-                        curvesToDisplay.Add(curve.Value.curves[i]);
+                    for (int i = 0; i < curve.Value.curveInfos.Length; i++)
+                        curvesToDisplay.Add(curve.Value.curveInfos[i]);
                 }
             }
             else
             {
                 for (int i = 0; i < selectedFields.Count; i++)
                 {
-                    EdAnimationCurve curve;
-                    if (TryGetCurve(selectedFields[i], out curve))
-                        curvesToDisplay.Add(curve);
+                    CurveDrawInfo curveInfo;
+                    if (TryGetCurve(selectedFields[i], out curveInfo))
+                        curvesToDisplay.Add(curveInfo);
                 }
             }
 
@@ -733,7 +733,7 @@ namespace BansheeEditor
 
         private Vector2 GetOptimalRange()
         {
-            EdAnimationCurve[] curvesToDisplay = GetDisplayedCurves();
+            CurveDrawInfo[] curvesToDisplay = GetDisplayedCurves();
 
             float xRange;
             float yRange;
@@ -752,9 +752,19 @@ namespace BansheeEditor
             return new Vector2(xRange, yRange);
         }
 
+        private void UpdateCurveColors()
+        {
+            int globalCurveIdx = 0;
+            foreach (var curveGroup in clipInfo.curves)
+            {
+                for (int i = 0; i < curveGroup.Value.curveInfos.Length; i++)
+                    curveGroup.Value.curveInfos[i].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);
+            }
+        }
+
         private void UpdateDisplayedCurves(bool allowReduce = false)
         {
-            EdAnimationCurve[] curvesToDisplay = GetDisplayedCurves();
+            CurveDrawInfo[] curvesToDisplay = GetDisplayedCurves();
             guiCurveEditor.SetCurves(curvesToDisplay);
 
             Vector2 newRange = GetOptimalRange();
@@ -768,6 +778,7 @@ namespace BansheeEditor
             guiCurveEditor.Range = newRange;
             UpdateScrollBarSize();
         }
+
         #endregion 
 
         #region Field display
@@ -776,21 +787,20 @@ namespace BansheeEditor
         private void AddNewField(string path, SerializableProperty.FieldType type)
         {
             bool noSelection = selectedFields.Count == 0;
-            guiFieldDisplay.AddField(new AnimFieldInfo(path, type, !clipInfo.isImported));
-
+            
             switch (type)
             {
                 case SerializableProperty.FieldType.Vector4:
                     {
                         FieldAnimCurves fieldCurves = new FieldAnimCurves();
                         fieldCurves.type = type;
-                        fieldCurves.curves = new EdAnimationCurve[4];
+                        fieldCurves.curveInfos = new CurveDrawInfo[4];
 
                         string[] subPaths = { ".x", ".y", ".z", ".w" };
                         for (int i = 0; i < subPaths.Length; i++)
                         {
                             string subFieldPath = path + subPaths[i];
-                            fieldCurves.curves[i] = new EdAnimationCurve();
+                            fieldCurves.curveInfos[i].curve = new EdAnimationCurve();
                             selectedFields.Add(subFieldPath);
                         }
 
@@ -801,13 +811,13 @@ namespace BansheeEditor
                     {
                         FieldAnimCurves fieldCurves = new FieldAnimCurves();
                         fieldCurves.type = type;
-                        fieldCurves.curves = new EdAnimationCurve[3];
+                        fieldCurves.curveInfos = new CurveDrawInfo[3];
 
                         string[] subPaths = { ".x", ".y", ".z" };
                         for (int i = 0; i < subPaths.Length; i++)
                         {
                             string subFieldPath = path + subPaths[i];
-                            fieldCurves.curves[i] = new EdAnimationCurve();
+                            fieldCurves.curveInfos[i].curve = new EdAnimationCurve();
                             selectedFields.Add(subFieldPath);
                         }
 
@@ -818,13 +828,13 @@ namespace BansheeEditor
                     {
                         FieldAnimCurves fieldCurves = new FieldAnimCurves();
                         fieldCurves.type = type;
-                        fieldCurves.curves = new EdAnimationCurve[2];
+                        fieldCurves.curveInfos = new CurveDrawInfo[2];
 
                         string[] subPaths = { ".x", ".y" };
                         for (int i = 0; i < subPaths.Length; i++)
                         {
                             string subFieldPath = path + subPaths[i];
-                            fieldCurves.curves[i] = new EdAnimationCurve();
+                            fieldCurves.curveInfos[i].curve = new EdAnimationCurve();
                             selectedFields.Add(subFieldPath);
                         }
 
@@ -835,13 +845,13 @@ namespace BansheeEditor
                     {
                         FieldAnimCurves fieldCurves = new FieldAnimCurves();
                         fieldCurves.type = type;
-                        fieldCurves.curves = new EdAnimationCurve[4];
+                        fieldCurves.curveInfos = new CurveDrawInfo[4];
 
                         string[] subPaths = { ".r", ".g", ".b", ".a" };
                         for (int i = 0; i < subPaths.Length; i++)
                         {
                             string subFieldPath = path + subPaths[i];
-                            fieldCurves.curves[i] = new EdAnimationCurve();
+                            fieldCurves.curveInfos[i].curve = new EdAnimationCurve();
                             selectedFields.Add(subFieldPath);
                         }
 
@@ -852,9 +862,9 @@ namespace BansheeEditor
                     {
                         FieldAnimCurves fieldCurves = new FieldAnimCurves();
                         fieldCurves.type = type;
-                        fieldCurves.curves = new EdAnimationCurve[1];
+                        fieldCurves.curveInfos = new CurveDrawInfo[1];
 
-                        fieldCurves.curves[0] = new EdAnimationCurve();
+                        fieldCurves.curveInfos[0].curve = new EdAnimationCurve();
                         selectedFields.Add(path);
 
                         clipInfo.curves[path] = fieldCurves;
@@ -862,6 +872,9 @@ namespace BansheeEditor
                     break;
             }
 
+            UpdateCurveColors();
+            UpdateDisplayedFields();
+
             EditorApplication.SetProjectDirty();
             UpdateDisplayedCurves(noSelection);
         }
@@ -891,16 +904,22 @@ namespace BansheeEditor
                 clipInfo.curves.Remove(GetSubPathParent(selectedFields[i]));
             }
 
-            List<AnimFieldInfo> existingFields = new List<AnimFieldInfo>();
-            foreach (var KVP in clipInfo.curves)
-                existingFields.Add(new AnimFieldInfo(KVP.Key, KVP.Value.type, !clipInfo.isImported));
-
-            guiFieldDisplay.SetFields(existingFields.ToArray());
+            UpdateCurveColors();
+            UpdateDisplayedFields();
 
             selectedFields.Clear();
             EditorApplication.SetProjectDirty();
             UpdateDisplayedCurves();
         }
+
+        private void UpdateDisplayedFields()
+        {
+            List<AnimFieldInfo> existingFields = new List<AnimFieldInfo>();
+            foreach (var KVP in clipInfo.curves)
+                existingFields.Add(new AnimFieldInfo(KVP.Key, KVP.Value, !clipInfo.isImported));
+
+            guiFieldDisplay.SetFields(existingFields.ToArray());
+        }
         #endregion
 
         #region Helpers
@@ -913,14 +932,14 @@ namespace BansheeEditor
             return output;
         }
 
-        private static void CalculateRange(EdAnimationCurve[] curves, out float xRange, out float yRange)
+        private static void CalculateRange(CurveDrawInfo[] curveInfos, out float xRange, out float yRange)
         {
             xRange = 0.0f;
             yRange = 0.0f;
 
-            foreach (var curve in curves)
+            foreach (var curveInfo in curveInfos)
             {
-                KeyFrame[] keyframes = curve.KeyFrames;
+                KeyFrame[] keyframes = curveInfo.curve.KeyFrames;
 
                 foreach (var key in keyframes)
                 {
@@ -930,7 +949,7 @@ namespace BansheeEditor
             }
         }
 
-        private bool TryGetCurve(string path, out EdAnimationCurve curve)
+        private bool TryGetCurve(string path, out CurveDrawInfo curveInfo)
         {
             int index = path.LastIndexOf(".");
             string parentPath;
@@ -952,33 +971,33 @@ namespace BansheeEditor
                 {
                     if (subPathSuffix == ".x" || subPathSuffix == ".r")
                     {
-                        curve = fieldCurves.curves[0];
+                        curveInfo = fieldCurves.curveInfos[0];
                         return true;
                     }
                     else if (subPathSuffix == ".y" || subPathSuffix == ".g")
                     {
-                        curve = fieldCurves.curves[1];
+                        curveInfo = fieldCurves.curveInfos[1];
                         return true;
                     }
                     else if (subPathSuffix == ".z" || subPathSuffix == ".b")
                     {
-                        curve = fieldCurves.curves[2];
+                        curveInfo = fieldCurves.curveInfos[2];
                         return true;
                     }
                     else if (subPathSuffix == ".w" || subPathSuffix == ".a")
                     {
-                        curve = fieldCurves.curves[3];
+                        curveInfo = fieldCurves.curveInfos[3];
                         return true;
                     }
                 }
                 else
                 {
-                    curve = fieldCurves.curves[0];
+                    curveInfo = fieldCurves.curveInfos[0];
                     return true;
                 }
             }
 
-            curve = null;
+            curveInfo = new CurveDrawInfo();
             return false;
         }