hch
5 小时以前 1f7688ee049312e095eb9eee2388fa58fa15ff81
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
[DisallowMultipleComponent]
[RequireComponent(typeof(Image))]
public class FlipImage : BaseMeshEffect
{
    [SerializeField] bool m_FlipHorizontal = false;
    [SerializeField] bool m_FlipVertical = false;
 
    public bool flipHorizontal
    {
        get { return m_FlipHorizontal; }
        set
        {
            m_FlipHorizontal = value;
            graphic.SetVerticesDirty();
        }
    }
 
    public bool flipVertical
    {
        get { return m_FlipVertical; }
        set
        {
            m_FlipVertical = value;
            graphic.SetVerticesDirty();
        }
    }
 
    public override void ModifyMesh(VertexHelper vh)
    {
        if (!IsActive() || vh.currentVertCount == 0)
        {
            return;
        }
        var vertexs = new List<UIVertex>();
        vh.GetUIVertexStream(vertexs);
        if (flipHorizontal || flipVertical)
        {
            Flip(vertexs);
        }
        vh.Clear();
        vh.AddUIVertexTriangleStream(vertexs);
    }
 
    void Flip(List<UIVertex> vertexs)
    {
        var rect = graphic.GetPixelAdjustedRect();
        var count = vertexs.Count;
        for (int i = 0; i < count; i++)
        {
            var vertex = vertexs[i];
            var position = vertex.position;
            if (flipHorizontal)
            {
                position.x = -position.x + rect.max.x + rect.min.x;
            }
            if (flipVertical)
            {
                position.y = -position.y + rect.max.y + rect.min.y;
            }
            vertex.position = position;
            vertexs[i] = vertex;
        }
    }
}