Exemple #1
0
        /// <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);
            }
        }
Exemple #2
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 + 3) % 4];
     }
     else
     {
         nomalizedPos = matrix * position;
     }
 }
Exemple #3
0
//		public void OnBeforeSerialize()
//		{
//		}
//
//		public void OnAfterDeserialize()
//		{
//			var obj = this;
//			EditorApplication.delayCall += () =>
//			{
//				if (Application.isPlaying || !obj)
//					return;
//
//				var mat = GetMaterial(shaderName);
//				if (m_EffectMaterial == mat && graphic.material == mat)
//					return;
//
//				graphic.material = m_EffectMaterial = mat;
//				EditorUtility.SetDirty(this);
//				EditorUtility.SetDirty(graphic);
//				EditorApplication.delayCall += AssetDatabase.SaveAssets;
//			};
//		}
//
//		public static Material GetMaterial(string shaderName)
//		{
//			string name = Path.GetFileName(shaderName);
//			return AssetDatabase.FindAssets("t:Material " + name)
//				.Select(x => AssetDatabase.GUIDToAssetPath(x))
//				.SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
//				.OfType<Material>()
//				.FirstOrDefault(x => x.name == name);
//		}
#endif

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

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

            // rotation.
            float   rad = 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.
            bool effectEachCharacter = graphic is Text && m_EffectArea == EffectArea.Character;

            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);

                // Normalize vertex position by local matrix.
                nomalizedPos = localMatrix * vertex.position;

                // Normalize vertex position by local matrix.
                if (effectEachCharacter)
                {
                    // Each characters.
                    nomalizedPos = localMatrix * splitedCharacterPosition[i % 4];
                }
                else
                {
                    nomalizedPos = localMatrix * vertex.position;
                }

                vertex.uv1 = new Vector2(
                    Packer.ToFloat(Mathf.Clamp01(nomalizedPos.y), softness, width, brightness),
                    Packer.ToFloat(location, highlight)
                    );

                vh.SetUIVertex(vertex, i);
            }
        }
Exemple #4
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);

                if (isTMPro)
                {
                    vertex.uv2 = new Vector2(
                        Packer.ToFloat(nomalizedPos.y, normalizedIndex), 0
                        );
                }
                else
                {
                    vertex.uv0 = new Vector2(
                        Packer.ToFloat(vertex.uv0.x, vertex.uv0.y),
                        Packer.ToFloat(nomalizedPos.y, normalizedIndex)
                        );
                }

                vh.SetUIVertex(vertex, i);
            }
        }
Exemple #5
0
        /// <summary>
        /// Modifies the mesh.
        /// </summary>
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
            {
                return;
            }

            // rect.
            Rect rect = graphic.rectTransform.rect;

            // rotation.
            float   rad = 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);

                // Normalize vertex position by local matrix.
                nomalizedPos = localMatrix * vertex.position;

                vertex.uv1 = new Vector2(
                    _PackToFloat(Mathf.Clamp01(nomalizedPos.y), location, width, alpha),
                    0
                    );

                vh.SetUIVertex(vertex, i);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
0
 /// <summary>
 /// Normalize vertex position by local matrix.
 /// </summary>
 public void GetNormalizedFactor(EffectArea area, int index, Matrix2x3 matrix, Vector2 position,
                                 out Vector2 normalizedPos)
 {
     normalizedPos = matrix * position;
 }