| | |
| | | using UnityEngine.Sprites; |
| | | using System; |
| | | |
| | | namespace vnxbqy.UI { |
| | | |
| | | [DisallowMultipleComponent] |
| | | [RequireComponent(typeof(Image))] |
| | | public class CustomImage:BaseMeshEffect { |
| | | [DisallowMultipleComponent] |
| | | [RequireComponent(typeof(Image))] |
| | | public class CustomImage:BaseMeshEffect { |
| | | |
| | | [SerializeField] |
| | | Vector2[] m_Points; |
| | | public Vector2[] points { |
| | | get { |
| | | return this.m_Points; |
| | | } |
| | | set { |
| | | this.m_Points = value; |
| | | SetVerticesDirty(); |
| | | } |
| | | [SerializeField] |
| | | Vector2[] m_Points; |
| | | public Vector2[] points { |
| | | get { |
| | | return this.m_Points; |
| | | } |
| | | set { |
| | | this.m_Points = value; |
| | | SetVerticesDirty(); |
| | | } |
| | | } |
| | | |
| | | private Image m_Image; |
| | | public Image image { |
| | | get { |
| | | return this.m_Image ?? (this.m_Image = this.AddMissingComponent<Image>()); |
| | | } |
| | | } |
| | | |
| | | public void SetVerticesDirty() { |
| | | this.graphic.SetVerticesDirty(); |
| | | } |
| | | |
| | | public override void ModifyMesh(VertexHelper vh) { |
| | | vh.Clear(); |
| | | |
| | | if(this.image == null) { |
| | | throw new NullReferenceException(); |
| | | } |
| | | |
| | | private Image m_Image; |
| | | public Image image { |
| | | get { |
| | | return this.m_Image ?? (this.m_Image = this.AddMissingComponent<Image>()); |
| | | } |
| | | if(this.points == null || this.points.Length < 3) { |
| | | return; |
| | | } |
| | | |
| | | public void SetVerticesDirty() { |
| | | this.graphic.SetVerticesDirty(); |
| | | var width = this.image.rectTransform.rect.width; |
| | | var height = this.image.rectTransform.rect.height; |
| | | |
| | | var uv = this.image.overrideSprite != null ? DataUtility.GetOuterUV(this.image.overrideSprite) : Vector4.zero; |
| | | var uvcenterX = (uv.x + uv.z) * 0.5f; |
| | | var uvcenterY = (uv.y + uv.w) * 0.5f; |
| | | var uvscaleX = (uv.z - uv.x) / width; |
| | | var uvscaleY = (uv.w - uv.y) / height; |
| | | |
| | | for(var i = 0;i < this.points.Length;i++) { |
| | | var point = this.points[i]; |
| | | |
| | | var position = new Vector2(point.x,point.y); |
| | | var uv0 = new Vector2(position.x * uvscaleX + uvcenterX,position.y * uvscaleY + uvcenterY); |
| | | var vertex = UIUtility.PackageUIVertex(position,uv0,this.image.color); |
| | | vh.AddVert(vertex); |
| | | } |
| | | |
| | | public override void ModifyMesh(VertexHelper vh) { |
| | | vh.Clear(); |
| | | |
| | | if(this.image == null) { |
| | | throw new NullReferenceException(); |
| | | } |
| | | |
| | | if(this.points == null || this.points.Length < 3) { |
| | | return; |
| | | } |
| | | |
| | | var width = this.image.rectTransform.rect.width; |
| | | var height = this.image.rectTransform.rect.height; |
| | | |
| | | var uv = this.image.overrideSprite != null ? DataUtility.GetOuterUV(this.image.overrideSprite) : Vector4.zero; |
| | | var uvcenterX = (uv.x + uv.z) * 0.5f; |
| | | var uvcenterY = (uv.y + uv.w) * 0.5f; |
| | | var uvscaleX = (uv.z - uv.x) / width; |
| | | var uvscaleY = (uv.w - uv.y) / height; |
| | | |
| | | for(var i = 0;i < this.points.Length;i++) { |
| | | var point = this.points[i]; |
| | | |
| | | var position = new Vector2(point.x,point.y); |
| | | var uv0 = new Vector2(position.x * uvscaleX + uvcenterX,position.y * uvscaleY + uvcenterY); |
| | | var vertex = UIUtility.PackageUIVertex(position,uv0,this.image.color); |
| | | vh.AddVert(vertex); |
| | | } |
| | | |
| | | var vertexCount = this.points.Length; |
| | | var index = 0; |
| | | for(;index < vertexCount - 2;index++) { |
| | | vh.AddTriangle(index,index + 1,index + 2); |
| | | } |
| | | var vertexCount = this.points.Length; |
| | | var index = 0; |
| | | for(;index < vertexCount - 2;index++) { |
| | | vh.AddTriangle(index,index + 1,index + 2); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |