hch
2 天以前 af8dafd75f9a6fae017734d58fc7b34d6bdcd0f4
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
84
85
86
87
88
89
90
91
//--------------------------------------------------------
//    [Author]:           玩个游戏
//    [  Date ]:           Wednesday, August 23, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
 
 
public class OffsetImage:BaseMeshEffect {
 
    [SerializeField]
    Vector2 m_Offset;
    public Vector2 offset {
        get {
            return m_Offset;
        }
        set {
            m_Offset = value;
 
        }
    }
 
    public override void ModifyMesh(VertexHelper vh) {
        List<UIVertex> vertexs = new List<UIVertex>();
        vh.GetUIVertexStream(vertexs);
 
        if(vertexs == null || vertexs.Count == 0) {
            return;
        }
        vh.Clear();
 
        var positions = new Vector3[3];
        var uv0s = new Vector2[3];
 
        var firstQuard = new UIVertex[6] {
            vertexs[0],
            vertexs[1],
            vertexs[2],
            vertexs[3],
            vertexs[4],
            vertexs[5]
        };
 
        for(var i = 0;i < firstQuard.Length;i++) {
            var vertex = firstQuard[i];
            var position = vertex.position + new Vector3(offset.x,offset.y,0);
            vertex.position = position;
            firstQuard[i] = vertex;
 
            if((i % 3) == 2) {
                positions[0] = firstQuard[i - 2].position;
                uv0s[0] = firstQuard[i - 2].uv0;
                positions[1] = firstQuard[i - 1].position;
                uv0s[1] = firstQuard[i - 1].uv0;
                positions[2] = firstQuard[i].position;
                uv0s[2] = firstQuard[i].uv0;
 
                UIUtility.AddTriangle(vh,positions,Color.white,uv0s);
            }
        }
 
 
 
        var index = 5 * 6;
        for(int i = 0;i < vertexs.Count;i++) {
 
            if(i > index) {
 
            }
 
            if((i % 3) == 2) {
                positions[0] = vertexs[i - 2].position;
                uv0s[0] = vertexs[i - 2].uv0;
                positions[1] = vertexs[i - 1].position;
                uv0s[1] = vertexs[i - 1].uv0;
                positions[2] = vertexs[i].position;
                uv0s[2] = vertexs[i].uv0;
 
                UIUtility.AddTriangle(vh,positions,Color.white,uv0s);
            }
        }
 
 
 
 
    }
 
}