少年修仙传客户端代码仓库
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
79
80
81
82
83
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
 
[DisallowMultipleComponent]
[AddComponentMenu("UI/Effects/Reflection")]
public class Reflection:BaseMeshEffect {
 
    [Range(0,30)]
    [SerializeField]
    float m_Distance;
    public float distance {
        get {
            return m_Distance;
        }
    }
 
    [Range(0,1)]
    [SerializeField]
    float m_HeightScale = 1f;
    public float heightScale {
        get {
            return m_HeightScale;
        }
    }
 
    [Range(0,1)]
    [SerializeField]
    float m_Virtualness;
    public float virtualness {
        get {
            return m_Virtualness;
        }
    }
 
    [SerializeField]
    float m_OffsetX = 0;
    public float offsetX {
        get {
            return m_OffsetX;
        }
    }
 
 
    public override void ModifyMesh(VertexHelper vh) {
        if(!IsActive() || vh.currentVertCount == 0) {
            return;
        }
 
        var vertexs = new List<UIVertex>();
        vh.GetUIVertexStream(vertexs);
 
        var count = vertexs.Count;
        var edge = UIUtility.GetEdge(vertexs,1);
        var height = (edge[1] - edge[0]) * heightScale;
        if(height == 0) {
            return;
        }
 
        var mirrorMinY = (edge[0] - edge[1]) * heightScale + edge[0] - distance;
        var color = this.graphic.color;
        var top = color.SetA(1 - virtualness);
        var bottom = color.SetA(0);
 
        for(var i = 0;i < count;i++) {
            var vertex = vertexs[i];
            vertexs.Add(vertex);
            var position = vertex.position;
            position.y = edge[0] - distance + (edge[0] - position.y) * heightScale;
            position.x += offsetX * (1 - Mathf.Abs((position.y - mirrorMinY) / height));
            vertex.position = position;
 
            var colort = Mathf.Abs((position.y - mirrorMinY) / height);
            vertex.color = Color32.Lerp(bottom,top,colort);
            vertexs[i + count] = vertex;
        }
 
        vh.Clear();
        vh.AddUIVertexTriangleStream(vertexs);
    }
}