コード例 #1
0
        public static Rect TitleText(Rect container, string text)
        {
            Color oldColor = GUI.color;

            Rect rect = new Rect(container.x + 5, container.y + 5, container.width - 10, 20);

            EaserEditorUtils.DrawOutsetBox(rect, 2, 3);

            Rect textRect = rect;

            textRect.xMin += 5;
            textRect.yMin += 3;
            GUI.color      = new Color(0, 0, 0, 0.35f);
            if (EditorGUIUtility.isProSkin)
            {
                GUI.Label(textRect, text);
            }

            textRect.xMin -= 1;
            textRect.yMin -= 1;
            GUI.color      = Color.white;
            GUI.Label(textRect, text);

            GUI.color = oldColor;

            return(rect);
        }
コード例 #2
0
        private void OnDraw(Rect rect)
        {
            _scrollPos = GUI.BeginScrollView(rect, _scrollPos,
                                             new Rect(0, 0, position.width, max * row));

            int tmpRow = 0, tmpColumn = 0; // 留一个格子 写配置

            DrawConfig(new Rect(tmpColumn * max, tmpRow * max, max, max));
            tmpColumn++;

            if (_easer.data.eases.Any())
            {
                for (var i = 0; i < _easer.data.eases.Length; i++)
                {
                    var tt = new Rect(tmpColumn * max, tmpRow * max, max, max);
                    DrawAnimationCurve(EaserEditorUtils.InsetRect(tt, 45), i);
                    drawCurve(tt, i);
                    tmpColumn++;
                    if (tmpColumn >= column)
                    {
                        tmpColumn = 0;
                        tmpRow++;
                    }
                }
            }

            GUI.EndScrollView();
        }
コード例 #3
0
        private void drawCurve(Rect rect, int index)
        {
            if (_texture == null)
            {
                _texture            = new Texture2D(1, 1);
                _texture.filterMode = FilterMode.Point;
                _texture.SetPixel(0, 0, new Color(1, 1, 1, 1));
                _texture.Apply();
            }

            if (EditorGUIUtility.isProSkin)
            {
                GUI.color = new Color(0.2f, 0.2f, 0.2f, 1);
            }
            else
            {
                GUI.color = new Color(0.6f, 0.6f, 0.6f, 1);
            }

            Rect bgRect = rect;

            bgRect.yMin += 1;
            bgRect.xMin += 1;
            GUI.DrawTexture(bgRect, _texture);
            EaserEditorUtils.DrawOutlineBox(bgRect, Color.black);

            if (index < _easer.constTotal)
            {
                EditorGUI.TextField(new Rect(rect.x + 5, rect.y + 5, 150, 20), "Ease." + _easer.data.eases[index].name);
            }
            else
            {
                _easer.data.eases[index].name = EditorGUI.TextField(new Rect(rect.x + 5, rect.y + 5, 150, 20),
                                                                    _easer.data.eases[index].name);
            }

            rect = EaserEditorUtils.InsetRect(rect, 45);
            if (EditorGUIUtility.isProSkin)
            {
                EaserEditorUtils.DrawShadowBox(rect);
            }

            Color lineColor    = new Color(0.15f, 0.15f, 0.15f, 1);
            Color offLineColor = new Color(0.15f, 0.15f, 0.15f, 0.3f);

            EaserEditorUtils.DrawGrid(rect, lineColor, offLineColor);

            AnimationCurve curve = _easer.data.eases[index].curve;
            //GUI.color = Color.red;
            //EditorGUIUtility.DrawCurveSwatch(rect, curve, null, Color.red, new Color(0, 0, 0, 0), new Rect(0, 0, 1, 1));
            //GUI.color = GUI.contentColor;

            float inc = 0.01f;

            for (float i = 0; i < 1; i += inc)
            {
                float val  = curve.Evaluate(i);
                float next = curve.Evaluate(i + inc);

                Vector2 start = new Vector2(rect.x + (i * rect.width), (rect.y + rect.height) - (val * rect.height));
                Vector2 end   = new Vector2(rect.x + ((i + inc) * rect.width),
                                            (rect.y + rect.height) - (next * rect.height));
                if (EditorGUIUtility.isProSkin)
                {
                    Handles.color = Color.white;
                }
                else
                {
                    Handles.color = Color.white;
                }

                Handles.DrawLine(start, end);
            }

            // 动画
            if (rect.Contains(_mousePos + _scrollPos))
            {
                float deltaTime = Time.realtimeSinceStartup - _lastTime;
                float value     = curve.Evaluate(_dotValue);
                _dotValue += deltaTime * 0.5f;
                if (_dotValue > 1)
                {
                    _dotValue = 0;
                }
                _lastTime = Time.realtimeSinceStartup;

                float   x   = rect.x + (_dotValue * rect.width);
                float   y   = (rect.y + rect.height) - (value * rect.height);
                Vector2 pos = new Vector2(x - (DOT_SIZE * 0.5f), y - (DOT_SIZE * 0.5f));
                //Vector2 xPos = new Vector2(x - (DOT_SIZE * 0.5f), (rect.yMax + 10) - (DOT_SIZE * 0.5f));
                Vector2 yPos = new Vector2((rect.xMax + 10) - (DOT_SIZE * 0.5f), y - (DOT_SIZE * 0.5f));

                //Handles.color = offLineColor;
                //Handles.DrawLine(new Vector2(x, y), new Vector3(x, xPos.y));
                //Handles.DrawLine(new Vector2(x, y), new Vector3(yPos.x, y));

                Handles.color = lineColor;
                Handles.DrawLine(new Vector2(rect.xMax + 10, rect.y), new Vector2(rect.xMax + 10, rect.yMax));

                Rect dotRect = new Rect(pos.x, pos.y, DOT_SIZE, DOT_SIZE);
                //Rect dotRectX = new Rect(xPos.x, xPos.y, DOT_SIZE, DOT_SIZE);
                Rect dotRectY = new Rect(yPos.x, yPos.y, DOT_SIZE, DOT_SIZE);

                if (EditorGUIUtility.isProSkin)
                {
                    GUI.color = Color.red;
                }
                else
                {
                    GUI.color = new Color(0.6f, 0, 0, 1);
                }

                GUI.DrawTexture(EaserEditorUtils.OutsetRect(dotRect, 1), _texture);
                //GUI.DrawTexture(EaserEditorUtils.OutsetRect(dotRectX, 1), _texture);
                GUI.DrawTexture(EaserEditorUtils.OutsetRect(dotRectY, 1), _texture);

                if (EditorGUIUtility.isProSkin)
                {
                    GUI.color = new Color(0.6f, 0, 0, 1);
                }
                else
                {
                    GUI.color = Color.red;
                }

                GUI.DrawTexture(dotRect, _texture);
                //GUI.DrawTexture(dotRectX, _texture);
                GUI.DrawTexture(dotRectY, _texture);
            }

            _repaint = true;

            /*
             * EaseUtility.EaseType ease = EaseUtility.EaseType.easeInCirc;
             * for (float i = 0; i < 1; i += inc)
             * {
             *  float val = EaseUtility.Ease(ease, 0, 1, i);
             *  float next = EaseUtility.Ease(ease, 0, 1, i + inc);
             *
             *  Vector2 start = new Vector2(rect.x + (i * rect.width), (rect.y + rect.height) - (val * rect.height));
             *  Vector2 end = new Vector2(rect.x + ((i + inc) * rect.width), (rect.y + rect.height) - (next * rect.height));
             *  Handles.color = Color.green;
             *  Handles.DrawLine(start, end);
             * }
             */
        }