Exemplo n.º 1
0
            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();
            }
Exemplo n.º 2
0
            private void Right(Rect position)
            {
                GUI.BeginGroup(position);
                Rect pos = new Rect(new Vector2(50, 10), new Vector2(300, 600));

                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++;
                }
                if (_curve != null)
                {
                    float count  = 1 / delta;
                    float pixels = cellsize * count;
                    float per    = _curve.step;
                    while (per < 1)
                    {
                        Handles.color = Color.Lerp(window._curveHeadColor, window._curveTrailColor, per);
                        var p = _curve.GetPercent(per);
                        per += _curve.step;
                        var p2 = _curve.GetPercent(per);

                        if (_type.HasFlag(LineType.X_Y))
                        {
                            Handles.DrawLine(new Vector2(p.x * pixels, pos.height - p.y * pixels) + pos.position,
                                             new Vector2(p2.x * pixels, pos.height - p2.y * pixels) + pos.position);
                        }
                        if (_type.HasFlag(LineType.Percent_Y))
                        {
                            Handles.DrawLine(new Vector2((per - _curve.step) * pixels, pos.height - (p.y) * pixels) + pos.position,
                                             new Vector2(per * pixels, pos.height - (p2.y) * pixels) + pos.position);
                        }
                        if (_type.HasFlag(LineType.Y_Speed))
                        {
                            float _a = (p2 - p).y / _curve.step;
                            Handles.DrawLine(new Vector2((per - _curve.step) * pixels, pos.height - _a * pixels) + pos.position,
                                             new Vector2(per * pixels, pos.height - _a * pixels) + pos.position);
                        }
                    }
                    {
                        if (_type.HasFlag(LineType.X_Y))
                        {
                            var  point = _curve.GetPercent(_percent);
                            Rect cone  = new Rect(Vector2.zero, Vector2.one * 10);

                            cone.center = new Vector2(point.x * pixels, pos.height - point.y * 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);
                        }
                    }
                    {
                        if (_type.HasFlag(LineType.Percent_Y))
                        {
                            var  point = _curve.GetPercent(_percent);
                            Rect cone  = new Rect(Vector2.zero, Vector2.one * 10);

                            cone.center = new Vector2(_percent * pixels, pos.height - point.y * 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);
                        }
                    }
                    {
                        if (_type.HasFlag(LineType.Y_Speed))
                        {
                            var point = _curve.GetPercent(_percent);

                            var  p2   = _curve.GetPercent(_percent + _curve.step);
                            Rect cone = new Rect(Vector2.zero, Vector2.one * 10);

                            cone.center = new Vector2(_percent * pixels, pos.height - ((p2 - point).y / _curve.step) * 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);
                        }
                    }
                }
                var rect = new Rect(pos.BottomLeft() + new Vector2(0, 30), new Vector2(pos.width, 20));
                var rs   = rect.VerticalSplit(pos.width / 4 * 3, 20);

                using (new EditorGUI.DisabledScope(_curve == null))
                {
                    _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)
                                .SetCurve(_curve)
                                .OnCompelete(() => {
                            _percent = 1;
                        })
                                .SetDeltaTime((float)EditorEnv.env.deltaTime.TotalMilliseconds);
                    }
                }

                GUI.EndGroup();
            }