/// <summary> /// Modifies the mesh. /// </summary> public override void ModifyMesh(VertexHelper vh, Graphic graphic) { if (!isActiveAndEnabled) { return; } var normalizedIndex = paramTex.GetNormalizedIndex(this); var rect = m_EffectArea.GetEffectArea(vh, rectTransform.rect); // rotation. var rad = m_Rotation * Mathf.Deg2Rad; var dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)); dir.x *= rect.height / rect.width; dir = dir.normalized; // Calculate vertex position. var vertex = default(UIVertex); var localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix. for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vertex, i); Vector2 normalizedPos; connector.GetNormalizedFactor(m_EffectArea, i, localMatrix, vertex.position, out normalizedPos); vertex.uv0 = new Vector2( Packer.ToFloat(vertex.uv0.x, vertex.uv0.y), Packer.ToFloat(normalizedPos.y, normalizedIndex) ); vh.SetUIVertex(vertex, i); } }
/// <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 + 3) % 4]; } else { nomalizedPos = matrix * position; } }
/// <summary> /// Normalize vertex position by local matrix. /// </summary> public virtual void GetNormalizedFactor(EffectArea area, int index, Matrix2x3 matrix, Vector2 position, out Vector2 normalizedPos) { normalizedPos = matrix * position; }
/// <summary> /// Call used to modify mesh. /// </summary> public override void ModifyMesh(VertexHelper vh, Graphic graphic) { if (!isActiveAndEnabled) { return; } // Gradient space. var rect = default(Rect); var vertex = default(UIVertex); switch (m_GradientStyle) { case GradientStyle.Rect: // RectTransform. rect = graphic.rectTransform.rect; break; case GradientStyle.Split: // Each characters. rect.Set(0, 0, 1, 1); break; case GradientStyle.Fit: { // Fit to contents. rect.xMin = rect.yMin = float.MaxValue; rect.xMax = rect.yMax = float.MinValue; for (var 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); } break; } } // Gradient rotation. var rad = rotation * Mathf.Deg2Rad; var 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. var localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix. for (var i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vertex, i); // Normalize vertex position by local matrix. Vector2 normalizedPos; if (m_GradientStyle == GradientStyle.Split) { // Each characters. normalizedPos = localMatrix * s_SplitedCharacterPosition[i % 4] + offset2; } else { normalizedPos = localMatrix * vertex.position + offset2; } // Interpolate vertex color. Color color; if (direction == Direction.Diagonal) { color = Color.LerpUnclamped( Color.LerpUnclamped(m_Color1, m_Color2, normalizedPos.x), Color.LerpUnclamped(m_Color3, m_Color4, normalizedPos.x), normalizedPos.y); } else { color = Color.LerpUnclamped(m_Color2, m_Color1, normalizedPos.y); } // Correct color. vertex.color *= (m_ColorSpace == ColorSpace.Gamma) ? color.gamma : (m_ColorSpace == ColorSpace.Linear) ? color.linear : color; vh.SetUIVertex(vertex, i); } }