Exemple #1
0
        // MSG
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            toFill.Clear();

            var rect = GetPixelAdjustedRect();

            if (color.a < GadgetUtil.FLOAT_GAP || rect.width <= GadgetUtil.FLOAT_GAP || rect.height <= GadgetUtil.FLOAT_GAP)
            {
                return;
            }

            float   border = Mathf.Max(m_Border, 0f);
            float   round  = Mathf.Max(m_Round, 0f);
            int     detail = Mathf.Clamp(m_Detail, 3, 1024);
            Vector2 a      = new Vector2(
                Mathf.LerpUnclamped(rect.xMin, rect.xMax, m_A.x),
                Mathf.LerpUnclamped(rect.yMin, rect.yMax, m_A.y)
                );
            Vector2 b = new Vector2(
                Mathf.LerpUnclamped(rect.xMin, rect.xMax, m_B.x),
                Mathf.LerpUnclamped(rect.yMin, rect.yMax, m_B.y)
                );
            Vector2 c = new Vector2(
                Mathf.LerpUnclamped(rect.xMin, rect.xMax, m_C.x),
                Mathf.LerpUnclamped(rect.yMin, rect.yMax, m_C.y)
                );

            if (Mathf.Repeat(Quaternion.FromToRotation(b - a, c - a).eulerAngles.z, 360f) > 180f)
            {
                var temp = b;
                b = c;
                c = temp;
            }

            Vector2 deltaAB = Vector3.Cross(a - b, Vector3.back).normalized;
            Vector2 deltaBC = Vector3.Cross(b - c, Vector3.back).normalized;
            Vector2 deltaCA = Vector3.Cross(c - a, Vector3.back).normalized;
            float   rotAB   = Mathf.Repeat(Quaternion.FromToRotation(deltaAB, Vector2.up).eulerAngles.z, 360f);
            float   rotBC   = Mathf.Repeat(Quaternion.FromToRotation(deltaBC, Vector2.up).eulerAngles.z, 360f);
            float   rotCA   = Mathf.Repeat(Quaternion.FromToRotation(deltaCA, Vector2.up).eulerAngles.z, 360f);

            // Fill
            if (color.a > GadgetUtil.FLOAT_GAP)
            {
                GadgetUtil.SetCacheColor(color);
                GadgetUtil.FillTriangle(toFill, a, b, c);
                if (round > GadgetUtil.FLOAT_GAP)
                {
                    GadgetUtil.FillQuad(toFill, a, b, b + deltaAB * round, a + deltaAB * round);
                    GadgetUtil.FillQuad(toFill, b, c, c + deltaBC * round, b + deltaBC * round);
                    GadgetUtil.FillQuad(toFill, c, a, a + deltaCA * round, c + deltaCA * round);
                    GadgetUtil.FillDisc(toFill,
                                        rotAB < rotCA ? rotAB : rotAB - 360f,
                                        rotCA,
                                        detail, round, a
                                        );
                    GadgetUtil.FillDisc(toFill,
                                        rotBC < rotAB ? rotBC : rotBC - 360f,
                                        rotAB,
                                        detail, round, b
                                        );
                    GadgetUtil.FillDisc(toFill,
                                        rotCA < rotBC ? rotCA : rotCA - 360f,
                                        rotBC,
                                        detail, round, c
                                        );
                }
            }

            // Border
            if (m_BorderColor.a > GadgetUtil.FLOAT_GAP && border > GadgetUtil.FLOAT_GAP)
            {
                GadgetUtil.SetCacheColor(m_BorderColor);
                GadgetUtil.FillQuad(toFill,
                                    a + deltaAB * round,
                                    b + deltaAB * round,
                                    b + deltaAB * (round + border),
                                    a + deltaAB * (round + border)
                                    );
                GadgetUtil.FillQuad(toFill,
                                    b + deltaBC * round,
                                    c + deltaBC * round,
                                    c + deltaBC * (round + border),
                                    b + deltaBC * (round + border)
                                    );
                GadgetUtil.FillQuad(toFill,
                                    c + deltaCA * round,
                                    a + deltaCA * round,
                                    a + deltaCA * (round + border),
                                    c + deltaCA * (round + border)
                                    );
                GadgetUtil.FillDisc(toFill,
                                    rotAB < rotCA ? rotAB : rotAB - 360f,
                                    rotCA,
                                    detail, round, round + border, a
                                    );
                GadgetUtil.FillDisc(toFill,
                                    rotBC < rotAB ? rotBC : rotBC - 360f,
                                    rotAB,
                                    detail, round, round + border, b
                                    );
                GadgetUtil.FillDisc(toFill,
                                    rotCA < rotBC ? rotCA : rotCA - 360f,
                                    rotBC,
                                    detail, round, round + border, c
                                    );
            }
        }
Exemple #2
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            if (m_Gradien == null)
            {
                base.OnPopulateMesh(toFill);
                return;
            }

            var cKeys = m_Gradien.colorKeys;
            var aKeys = m_Gradien.alphaKeys;

            if ((cKeys == null || cKeys.Length == 0) && (aKeys == null || aKeys.Length == 0))
            {
                base.OnPopulateMesh(toFill);
                return;
            }

            bool blend = m_Gradien.mode == GradientMode.Blend;
            var  rect  = GetPixelAdjustedRect();

            toFill.Clear();

            int   cLen      = cKeys != null ? cKeys.Length : 0;
            int   aLen      = aKeys != null ? aKeys.Length : 0;
            float cTime     = cLen > 0 ? cKeys[0].time : 0f;
            float aTime     = aLen > 0 ? aKeys[0].time : 0f;
            float prevTime  = 0f;
            float prevX     = m_Horizontal ? rect.xMin : rect.yMin;
            Color prevColor = m_Gradien.Evaluate(0f) * color;

            for (int cIndex = 0, aIndex = 0; cIndex < cLen || aIndex < aLen;)
            {
                if (cTime <= aTime)
                {
                    float x = Mathf.Lerp(
                        m_Horizontal ? rect.xMin : rect.yMin,
                        m_Horizontal ? rect.xMax : rect.yMax,
                        cTime
                        );
                    var _color = m_Gradien.Evaluate(cTime) * color;
                    if (!blend)
                    {
                        prevColor = _color;
                    }
                    if (Mathf.Abs(cTime - prevTime) > GadgetUtil.FLOAT_GAP)
                    {
                        if (m_Horizontal)
                        {
                            GadgetUtil.SetCacheColor(prevColor, prevColor, _color, _color);
                            GadgetUtil.FillQuad(toFill, prevX, x, rect.yMin, rect.yMax);
                        }
                        else
                        {
                            GadgetUtil.SetCacheColor(prevColor, _color, _color, prevColor);
                            GadgetUtil.FillQuad(toFill, rect.xMin, rect.xMax, prevX, x);
                        }
                    }
                    prevColor = _color;
                    prevTime  = cTime;
                    prevX     = x;
                    cIndex++;
                    if (cTime == aTime)
                    {
                        aIndex++;
                    }
                    cTime = cIndex < cLen ? cKeys[cIndex].time : 1f;
                }
                else
                {
                    float x = Mathf.Lerp(
                        m_Horizontal ? rect.xMin : rect.yMin,
                        m_Horizontal ? rect.xMax : rect.yMax,
                        aTime
                        );
                    var _color = m_Gradien.Evaluate(aTime) * color;
                    if (!blend)
                    {
                        prevColor = _color;
                    }
                    if (Mathf.Abs(aTime - prevTime) > GadgetUtil.FLOAT_GAP)
                    {
                        if (m_Horizontal)
                        {
                            GadgetUtil.SetCacheColor(prevColor, prevColor, _color, _color);
                            GadgetUtil.FillQuad(toFill, prevX, x, rect.yMin, rect.yMax);
                        }
                        else
                        {
                            GadgetUtil.SetCacheColor(prevColor, _color, _color, prevColor);
                            GadgetUtil.FillQuad(toFill, rect.xMin, rect.xMax, prevX, x);
                        }
                    }
                    prevColor = _color;
                    prevTime  = aTime;
                    prevX     = x;
                    aIndex++;
                    aTime = aIndex < aLen ? aKeys[aIndex].time : 1f;
                }
            }
            // End
            if (prevTime < 1f - GadgetUtil.FLOAT_GAP)
            {
                var _color = m_Gradien.Evaluate(1f) * color;
                if (!blend)
                {
                    prevColor = _color;
                }
                if (m_Horizontal)
                {
                    GadgetUtil.SetCacheColor(prevColor, prevColor, _color, _color);
                    GadgetUtil.FillQuad(toFill, prevX, rect.xMax, rect.yMin, rect.yMax);
                }
                else
                {
                    GadgetUtil.SetCacheColor(prevColor, _color, _color, prevColor);
                    GadgetUtil.FillQuad(toFill, rect.xMin, rect.xMax, prevX, rect.yMax);
                }
            }
        }