void StringToCurve(string data)
        {
            points = new List <FloatString4>();

            string[] lines = data.Split('\n');
            foreach (string line in lines)
            {
                string[] pcs = line.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if ((pcs.Length >= 3) && (pcs[0] == "key"))
                {
                    FloatString4 nv = new FloatString4();
                    if (pcs.Length >= 5)
                    {
                        nv.strings = new string[] { pcs[1], pcs[2], pcs[3], pcs[4] };
                        nv.twoMode = false;
                    }
                    else
                    {
                        nv.strings = new string[] { pcs[1], pcs[2], "0", "0" };
                        nv.twoMode = true;
                    }
                    nv.UpdateFloats();
                    points.Add(nv);
                }
            }

            if (!textChanged)
            {
                textVersion = CurveToString();
            }

            curveNeedsUpdate = true;
        }
        void Update()
        {
            if (textChanged)
            {
                StringToCurve(textVersion);
            }

            if (curveNeedsUpdate)
            {
                UpdateCurve();
            }

            float newCurve = HashAnimationCurve(curve);

            if (lastCurve != newCurve)
            {
                points = new List <FloatString4>();

                for (int i = 0; i < curve.keys.Length; i++)
                {
                    FloatString4 nv = new FloatString4(curve.keys[i].time, curve.keys[i].value, curve.keys[i].inTangent, curve.keys[i].outTangent, (curve.keys[i].tangentMode == 10));
                    nv.UpdateStrings();
                    points.Add(nv);
                }

                if (!textChanged)
                {
                    textVersion = CurveToString();
                }

                lastCurve = newCurve;
            }
        }
Beispiel #3
0
        void StringToCurve(string data)
        {
            points = new List <FloatString4>();

            string[] lines = data.Split('\n');
            foreach (string line in lines)
            {
                string[] pcs = line.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if ((pcs.Length >= 5) && (pcs[0] == "key"))
                {
                    FloatString4 nv = new FloatString4();
                    nv.strings = new string[] { pcs[1], pcs[2], pcs[3], pcs[4] };
                    nv.UpdateFloats();
                    points.Add(nv);
                }
            }

            curveNeedsUpdate = true;
        }
Beispiel #4
0
        void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();
            GUILayout.Label(graph, GUILayout.Width(512), GUILayout.Height(128));
            GUILayout.EndVertical();

            FloatString4 excludePoint = null;

            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true), GUILayout.Height(200));
            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
            GUILayout.BeginVertical();
            GUILayout.Label("X");
            foreach (FloatString4 p in points)
            {
                string ns = GUILayout.TextField(p.strings[0]);
                if (ns != p.strings[0])
                {
                    p.strings[0] = ns;
                    p.UpdateFloats();
                    curveNeedsUpdate = true;
                }
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Y");
            foreach (FloatString4 p in points)
            {
                string ns = GUILayout.TextField(p.strings[1]);
                if (ns != p.strings[1])
                {
                    p.strings[1] = ns;
                    p.UpdateFloats();
                    curveNeedsUpdate = true;
                }
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("In Tangent");
            foreach (FloatString4 p in points)
            {
                string ns = GUILayout.TextField(p.strings[2]);
                if (ns != p.strings[2])
                {
                    p.strings[2] = ns;
                    p.UpdateFloats();
                    curveNeedsUpdate = true;
                }
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Out Tangent");
            foreach (FloatString4 p in points)
            {
                string ns = GUILayout.TextField(p.strings[3]);
                if (ns != p.strings[3])
                {
                    p.strings[3] = ns;
                    p.UpdateFloats();
                    curveNeedsUpdate = true;
                }
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Remove");
            foreach (FloatString4 p in points)
            {
                if (GUILayout.Button("X"))
                {
                    excludePoint = p;
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            if (excludePoint != null)
            {
                points.Remove(excludePoint);
                curveNeedsUpdate = true;
            }

            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
            if (GUILayout.Button("Add Node"))
            {
                points.Add(new FloatString4(points.Last().floats.x + 1, points.Last().floats.y, points.Last().floats.z, points.Last().floats.w));
                curveNeedsUpdate = true;
            }
            GUILayout.EndHorizontal();

            string newT = GUILayout.TextArea(textVersion, GUILayout.ExpandWidth(true), GUILayout.Height(100));

            if (newT != textVersion)
            {
                StringToCurve(newT);
            }

            GUI.DragWindow();
        }