| New file |
| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine;
|
| | | using UnityEngine.UI;
|
| | |
|
| | | [DisallowMultipleComponent]
|
| | | [RequireComponent(typeof(Image))]
|
| | | public class FlipImage : BaseMeshEffect
|
| | | {
|
| | | [SerializeField] bool flipHorizontal = false;
|
| | | [SerializeField] bool flipVertical = false;
|
| | |
|
| | | public override void ModifyMesh(VertexHelper vh)
|
| | | {
|
| | | if (!IsActive() || vh.currentVertCount == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | var vertexs = new List<UIVertex>();
|
| | | vh.GetUIVertexStream(vertexs);
|
| | | if (flipHorizontal || flipVertical)
|
| | | {
|
| | | Flip(vertexs);
|
| | | }
|
| | | vh.Clear();
|
| | | vh.AddUIVertexTriangleStream(vertexs);
|
| | | }
|
| | |
|
| | | void Flip(List<UIVertex> vertexs)
|
| | | {
|
| | | var rect = graphic.GetPixelAdjustedRect();
|
| | | var count = vertexs.Count;
|
| | | for (int i = 0; i < count; i++)
|
| | | {
|
| | | var vertex = vertexs[i];
|
| | | var position = vertex.position;
|
| | | if (flipHorizontal)
|
| | | {
|
| | | position.x = -position.x + rect.max.x + rect.min.x;
|
| | | }
|
| | | if (flipVertical)
|
| | | {
|
| | | position.y = -position.y + rect.max.y + rect.min.y;
|
| | | }
|
| | | vertex.position = position;
|
| | | vertexs[i] = vertex;
|
| | | }
|
| | | }
|
| | | }
|
| | | |