private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { tc.Rewind(1); } if (Input.GetKey(KeyCode.A)) { tc.ReStart(); } if (Input.GetKey(KeyCode.Q)) { tc.Complete(false); } }
public override void OnGUI(Rect position) { base.OnGUI(position); GUI.BeginGroup(position); Rect pos = new Rect(new Vector2(50, 10), new Vector2(400, 400)); GUI.Box(pos, ""); Handles.color = window._backgroundColor; Vector2 end = new Vector2(pos.width, pos.height) + pos.position; Handles.DrawLine(new Vector2(0, pos.height) + pos.position, end); end = new Vector2(0, pos.height) + pos.position; Handles.DrawLine(new Vector2(0, 0) + pos.position, end); float hCount = pos.width / cellsize; float vCount = pos.height / cellsize; hCount = Math.Min(hCount, vCount); Handles.DrawLine(pos.BottomLeft(), new Vector2(hCount * cellsize, pos.height - hCount * cellsize) + pos.position); int _index = 0; while (pos.height >= _index * cellsize) { float y = pos.height - _index * cellsize; Vector2 left = new Vector2(0, y) + pos.position; Vector2 right = new Vector2(pos.width, y) + pos.position; Handles.DrawLine(left, right); GUI.Label(new Rect(left + new Vector2(-20, -6), Vector2.one * 80), (_index * delta).ToString("0.0")); _index++; } _index = 0; while (pos.width >= _index * cellsize) { float x = _index * cellsize; Vector2 top = new Vector2(x, 0) + pos.position; Vector2 buttom = new Vector2(x, pos.height) + pos.position; Handles.DrawLine(top, buttom); GUI.Label(new Rect(buttom + new Vector2(-8, 0), Vector2.one * 80), (_index * delta).ToString("0.0")); _index++; } float per = 0; float _p = 0.002f; float pixels = cellsize * 1 / delta; while (per < 1) { var p1 = _converter.Convert(per / 1, per, 1); per += _p; var p2 = _converter.Convert(per / 1, per, 1); Handles.color = Color.Lerp(window._curveHeadColor, window._curveTrailColor, per); Handles.DrawLine(new Vector2((per - _p) * pixels, pos.height - p1 * pixels) + pos.position, new Vector2(per * pixels, pos.height - p2 * pixels) + pos.position); } var rect = new Rect(pos.BottomLeft() + new Vector2(0, 30), new Vector2(pos.width, 20)); var rs = rect.VerticalSplit(pos.width / 4 * 3, 20); _percent = EditorGUI.Slider(rs[0], "Percent", _percent, 0, 1); if (GUI.Button(rs[1], "Watch Curve")) { _percent = 0; if (tween != null) { tween.Complete(false); tween = null; } tween = TweenEx.DoGoto(0, 1, 5f, () => { return(_percent); }, (value) => { _percent = value; window.Repaint(); }, false, EditorEnv.envType) .SetEase(_ease) .OnCompelete(() => { _percent = 1; }) .SetDeltaTime((float)EditorEnv.env.deltaTime.TotalMilliseconds); } { var point = _converter.Convert(_percent, _percent, 1); Rect cone = new Rect(Vector2.zero, Vector2.one * 10); cone.center = new Vector2(_percent * pixels, pos.height - point * pixels) + pos.position; GUI.Box(cone, new GUIContent("", point.ToString()), GUIStyles.Get("U2D.createRect")); var content = new GUIContent(point.ToString()); var size = GUIStyles.Get("label").CalcSize(content); GUI.Label(new Rect(cone.position + Vector2.one * 10, size), content); } GUI.EndGroup(); }