少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, August 10, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Sprites;
using System;
 
namespace vnxbqy.UI {
 
    [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();
            }
        }
 
        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();
            }
 
            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);
            }
        }
 
    }
 
}