少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, August 23, 2017
//--------------------------------------------------------
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    [RequireComponent(typeof(RectTransform))]
    public class Rhombus : BaseMeshEffect
    {
        const float SQUARE_ROOT_THREE = 1f;
        Vector3[] positions = new Vector3[3];
 
        RectTransform m_RectTransform;
        public RectTransform rectTransform {
            get {
                return m_RectTransform ?? (m_RectTransform = this.transform as RectTransform);
            }
        }
 
        Image m_Image;
        public Image image {
            get {
                return m_Image ?? (m_Image = this.GetComponent<Image>());
            }
        }
 
        public override void ModifyMesh(VertexHelper vh)
        {
            vh.Clear();
 
            var uv = this.image != 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) / this.rectTransform.rect.width;
            var uvScaleY = (uv.w - uv.y) / this.rectTransform.rect.height;
 
            var xoffset = this.rectTransform.rect.width * 0.5f;
            var yoffset = this.rectTransform.rect.height * 0.5f;
 
            this.positions[0] = new Vector3(0, yoffset);
            this.positions[1] = new Vector3(-xoffset, yoffset * (1f - SQUARE_ROOT_THREE));
            this.positions[2] = new Vector3(xoffset, yoffset * (1f - SQUARE_ROOT_THREE));
 
            for (var i = 0; i < 3; i++)
            {
                var position = this.positions[i];
                var uv0 = new Vector2(position.x * uvScaleX + uvCenterX, position.y * uvScaleY + uvCenterY);
                var vertex = UIUtility.PackageUIVertex(position, uv0, this.image.color);
                vh.AddVert(vertex);
 
                position = this.positions[i] * -1f;
                uv0 = new Vector2(position.x * uvScaleX + uvCenterX, position.y * uvScaleY + uvCenterY);
                vertex = UIUtility.PackageUIVertex(position, uv0, this.image.color);
                vh.AddVert(vertex);
            }
 
            vh.AddTriangle(0, 2, 4);
            vh.AddTriangle(1, 3, 5);
        }
 
    }
 
}