Exemple #1
0
 /// <summary>
 /// Normalize vertex position by local matrix.
 /// </summary>
 public static void GetNormalizedFactor(this EffectArea area, int index, Matrix2x3 matrix, Vector2 position, bool isText, out Vector2 nomalizedPos)
 {
     if (isText && area == EffectArea.Character)
     {
         nomalizedPos = matrix * splitedCharacterPosition [index % 4];
     }
     else
     {
         nomalizedPos = matrix * position;
     }
 }
Exemple #2
0
                #pragma warning restore 0612
#endif

        /// <summary>
        /// Modifies the mesh.
        /// </summary>
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            bool  isText          = isTMPro || graphic is Text;
            float normalizedIndex = ptex.GetNormalizedIndex(this);

            // rect.
            Rect rect = m_EffectArea.GetEffectArea(vh, rectTransform.rect);

            // rotation.
            float   rad = m_Rotation * Mathf.Deg2Rad;
            Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));

            dir.x *= rect.height / rect.width;
            dir    = dir.normalized;

            // Calculate vertex position.
            UIVertex  vertex = default(UIVertex);
            Vector2   nomalizedPos;
            Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y);                  // Get local matrix.

            for (int i = 0; i < vh.currentVertCount; i++)
            {
                vh.PopulateUIVertex(ref vertex, i);
                m_EffectArea.GetNormalizedFactor(i, localMatrix, vertex.position, isText, out nomalizedPos);

                vertex.uv0 = new Vector2(
                    Packer.ToFloat(vertex.uv0.x, vertex.uv0.y),
                    Packer.ToFloat(nomalizedPos.y, normalizedIndex)
                    );

                vh.SetUIVertex(vertex, i);
            }
        }
Exemple #3
0
        /// <summary>
        /// Call used to modify mesh.
        /// </summary>
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
            {
                return;
            }

            // Gradient space.
            Rect     rect   = default(Rect);
            UIVertex vertex = default(UIVertex);

            if (m_GradientStyle == GradientStyle.Rect)
            {
                // RectTransform.
                rect = graphic.rectTransform.rect;
            }
            else if (m_GradientStyle == GradientStyle.Split)
            {
                // Each characters.
                rect.Set(0, 0, 1, 1);
            }
            else if (m_GradientStyle == GradientStyle.Fit)
            {
                // Fit to contents.
                rect.xMin = rect.yMin = float.MaxValue;
                rect.xMax = rect.yMax = float.MinValue;
                for (int i = 0; i < vh.currentVertCount; i++)
                {
                    vh.PopulateUIVertex(ref vertex, i);
                    rect.xMin = Mathf.Min(rect.xMin, vertex.position.x);
                    rect.yMin = Mathf.Min(rect.yMin, vertex.position.y);
                    rect.xMax = Mathf.Max(rect.xMax, vertex.position.x);
                    rect.yMax = Mathf.Max(rect.yMax, vertex.position.y);
                }
            }

            // Gradient rotation.
            float   rad = rotation * Mathf.Deg2Rad;
            Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));

            if (!m_IgnoreAspectRatio && Direction.Angle <= m_Direction)
            {
                dir.x *= rect.height / rect.width;
                dir    = dir.normalized;
            }

            // Calculate vertex color.
            Color     color;
            Vector2   nomalizedPos;
            Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y);                  // Get local matrix.

            for (int i = 0; i < vh.currentVertCount; i++)
            {
                vh.PopulateUIVertex(ref vertex, i);

                // Normalize vertex position by local matrix.
                if (m_GradientStyle == GradientStyle.Split)
                {
                    // Each characters.
                    nomalizedPos = localMatrix * s_SplitedCharacterPosition[i % 4] + offset2;
                }
                else
                {
                    nomalizedPos = localMatrix * vertex.position + offset2;
                }

                // Interpolate vertex color.
                if (direction == Direction.Diagonal)
                {
                    color = Color.LerpUnclamped(
                        Color.LerpUnclamped(m_Color1, m_Color2, nomalizedPos.x),
                        Color.LerpUnclamped(m_Color3, m_Color4, nomalizedPos.x),
                        nomalizedPos.y);
                }
                else
                {
                    color = Color.LerpUnclamped(m_Color2, m_Color1, nomalizedPos.y);
                }

                // Correct color.
                vertex.color *= (m_ColorSpace == ColorSpace.Gamma) ? color.gamma
                                        : (m_ColorSpace == ColorSpace.Linear) ? color.linear
                                        : color;

                vh.SetUIVertex(vertex, i);
            }
        }