|  |  |  | 
|---|
|  |  |  | using UnityEngine; | 
|---|
|  |  |  | using UnityEngine.UI; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace vnxbqy.UI { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 这个组件接收一些顶点,绘制出水平和垂直的线。 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public class PolylineImage:Graphic { | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 这个组件接收一些顶点,绘制出水平和垂直的线。 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public class PolylineImage:Graphic { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | float m_Width; | 
|---|
|  |  |  | public float width { | 
|---|
|  |  |  | get { | 
|---|
|  |  |  | return this.m_Width; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | set { | 
|---|
|  |  |  | this.m_Width = value; | 
|---|
|  |  |  | base.SetVerticesDirty(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | float m_Width; | 
|---|
|  |  |  | public float width { | 
|---|
|  |  |  | get { | 
|---|
|  |  |  | return this.m_Width; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | set { | 
|---|
|  |  |  | this.m_Width = value; | 
|---|
|  |  |  | base.SetVerticesDirty(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | Vector2[] m_Points; | 
|---|
|  |  |  | public Vector2[] points { | 
|---|
|  |  |  | get { | 
|---|
|  |  |  | return this.m_Points; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | set { | 
|---|
|  |  |  | this.m_Points = value; | 
|---|
|  |  |  | base.SetVerticesDirty(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnPopulateMesh(VertexHelper vh) { | 
|---|
|  |  |  | vh.Clear(); | 
|---|
|  |  |  | if(this.points == null || this.points.Length < 2) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | Vector2[] m_Points; | 
|---|
|  |  |  | public Vector2[] points { | 
|---|
|  |  |  | get { | 
|---|
|  |  |  | return this.m_Points; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | set { | 
|---|
|  |  |  | this.m_Points = value; | 
|---|
|  |  |  | base.SetVerticesDirty(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var hw = this.width * 0.5f; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnPopulateMesh(VertexHelper vh) { | 
|---|
|  |  |  | vh.Clear(); | 
|---|
|  |  |  | if(this.points == null || this.points.Length < 2) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(var i = 0;i < this.points.Length - 1;i++) { | 
|---|
|  |  |  | var point = this.points[i]; | 
|---|
|  |  |  | var nextPoint = this.points[i + 1]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var hw = this.width * 0.5f; | 
|---|
|  |  |  | var xReversal = point.x > nextPoint.x; | 
|---|
|  |  |  | var yReversal = point.y > nextPoint.y; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for(var i = 0;i < this.points.Length - 1;i++) { | 
|---|
|  |  |  | var point = this.points[i]; | 
|---|
|  |  |  | var nextPoint = this.points[i + 1]; | 
|---|
|  |  |  | var positions = new Vector3[4]; | 
|---|
|  |  |  | positions[0] = new Vector2(xReversal ? point.x + hw : point.x - hw,yReversal ? point.y + hw : point.y - hw); | 
|---|
|  |  |  | positions[1] = new Vector2(xReversal ? nextPoint.x - hw : nextPoint.x + hw,yReversal ? point.y + hw : point.y - hw); | 
|---|
|  |  |  | positions[2] = new Vector2(xReversal ? nextPoint.x - hw : nextPoint.x + hw,yReversal ? nextPoint.y - hw : nextPoint.y + hw); | 
|---|
|  |  |  | positions[3] = new Vector2(xReversal ? point.x + hw : point.x - hw,yReversal ? nextPoint.y - hw : nextPoint.y + hw); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var xReversal = point.x > nextPoint.x; | 
|---|
|  |  |  | var yReversal = point.y > nextPoint.y; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var positions = new Vector3[4]; | 
|---|
|  |  |  | positions[0] = new Vector2(xReversal ? point.x + hw : point.x - hw,yReversal ? point.y + hw : point.y - hw); | 
|---|
|  |  |  | positions[1] = new Vector2(xReversal ? nextPoint.x - hw : nextPoint.x + hw,yReversal ? point.y + hw : point.y - hw); | 
|---|
|  |  |  | positions[2] = new Vector2(xReversal ? nextPoint.x - hw : nextPoint.x + hw,yReversal ? nextPoint.y - hw : nextPoint.y + hw); | 
|---|
|  |  |  | positions[3] = new Vector2(xReversal ? point.x + hw : point.x - hw,yReversal ? nextPoint.y - hw : nextPoint.y + hw); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UIUtility.AddQuad(vh,positions,color,new Vector2[4] { Vector2.one,Vector2.one,Vector2.one,Vector2.one }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UIUtility.AddQuad(vh,positions,color,new Vector2[4] { Vector2.one,Vector2.one,Vector2.one,Vector2.one }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|