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

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

            curveNeedsUpdate = true;
        }
        private void WindowGUI(int windowID)
        {
            GUILayout.BeginHorizontal(GUILayout.Height(texHeight));

            Vector2 sizeMax = GUI.skin.label.CalcSize(new GUIContent(maxY.ToString("F3")));
            Vector2 sizeMin = GUI.skin.label.CalcSize(new GUIContent(minY.ToString("F3")));

            GUILayout.BeginVertical(GUILayout.MinWidth(Mathf.Max(sizeMin.x, sizeMax.x)));

            for (int i = 0; i <= GraphLabels; i++)
            {
                GUILayout.Label((maxY - (maxY - minY) * i / GraphLabels).ToString("F3"), new GUIStyle(GUI.skin.label)
                {
                    wordWrap = false
                });
                if (i != GraphLabels) //only do it if it's not the last one
                {
                    GUILayout.Space(texHeight / GraphLabels - labelSpace);
                }
            }
            GUILayout.EndVertical();

            GUILayout.Box(graph);

            GUILayout.EndHorizontal();

            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));
            sort = GUILayout.Toggle(sort, "Sort");
            if (GUILayout.Button("New Curve"))
            {
                points.Clear();
                textVersion      = "";
                curveNeedsUpdate = true;
            }
            if (GUILayout.Button("Smooth Tangents"))
            {
                SmoothTangents();
            }
            if (GUILayout.Button("Copy out"))
            {
                GUIUtility.systemCopyBuffer = textVersion;
            }
            if (GUILayout.Button("Paste in"))
            {
                textVersion = GUIUtility.systemCopyBuffer;
                StringToCurve(textVersion);
                curveNeedsUpdate = true;
            }
            if (GUILayout.Button("Add Node"))
            {
                if (points.Count > 0)
                {
                    points.Add(new FloatString4(points.Last().floats.x + 1, points.Last().floats.y, points.Last().floats.z, points.Last().floats.w));
                }
                else
                {
                    points.Add(new FloatString4(0, 0, 0, 0));
                }
                curveNeedsUpdate = true;
            }
            keyName = GUILayout.TextField(keyName, GUILayout.Width(80));

            GUILayout.EndHorizontal();

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

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

            GUI.DragWindow();
        }