using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
[DisallowMultipleComponent]
|
[RequireComponent(typeof(Image))]
|
public class FlipImage : BaseMeshEffect
|
{
|
[SerializeField] bool m_FlipHorizontal = false;
|
[SerializeField] bool m_FlipVertical = false;
|
|
public bool flipHorizontal
|
{
|
get { return m_FlipHorizontal; }
|
set
|
{
|
m_FlipHorizontal = value;
|
graphic.SetVerticesDirty();
|
}
|
}
|
|
public bool flipVertical
|
{
|
get { return m_FlipVertical; }
|
set
|
{
|
m_FlipVertical = value;
|
graphic.SetVerticesDirty();
|
}
|
}
|
|
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;
|
}
|
}
|
}
|