//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, August 23, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System; using System.Collections.Generic; public class OffsetImage:BaseMeshEffect { [SerializeField] Vector2 m_Offset; public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } } public override void ModifyMesh(VertexHelper vh) { List vertexs = new List(); vh.GetUIVertexStream(vertexs); if(vertexs == null || vertexs.Count == 0) { return; } vh.Clear(); var positions = new Vector3[3]; var uv0s = new Vector2[3]; var firstQuard = new UIVertex[6] { vertexs[0], vertexs[1], vertexs[2], vertexs[3], vertexs[4], vertexs[5] }; for(var i = 0;i < firstQuard.Length;i++) { var vertex = firstQuard[i]; var position = vertex.position + new Vector3(offset.x,offset.y,0); vertex.position = position; firstQuard[i] = vertex; if((i % 3) == 2) { positions[0] = firstQuard[i - 2].position; uv0s[0] = firstQuard[i - 2].uv0; positions[1] = firstQuard[i - 1].position; uv0s[1] = firstQuard[i - 1].uv0; positions[2] = firstQuard[i].position; uv0s[2] = firstQuard[i].uv0; UIUtility.AddTriangle(vh,positions,Color.white,uv0s); } } var index = 5 * 6; for(int i = 0;i < vertexs.Count;i++) { if(i > index) { } if((i % 3) == 2) { positions[0] = vertexs[i - 2].position; uv0s[0] = vertexs[i - 2].uv0; positions[1] = vertexs[i - 1].position; uv0s[1] = vertexs[i - 1].uv0; positions[2] = vertexs[i].position; uv0s[2] = vertexs[i].uv0; UIUtility.AddTriangle(vh,positions,Color.white,uv0s); } } } }