Tanoda
UIFlippable.cs
Go to the documentation of this file.
1
3
5{
6 [RequireComponent(typeof(RectTransform), typeof(Graphic)), DisallowMultipleComponent]
7 [AddComponentMenu("UI/Effects/Extensions/Flippable")]
8 public class UIFlippable : BaseMeshEffect
9 {
10 [SerializeField] private bool m_Horizontal = false;
11 [SerializeField] private bool m_Veritical = false;
12
13#if UNITY_EDITOR
14 protected override void Awake()
15 {
16 OnValidate();
17 }
18#endif
19
24 public bool horizontal
25 {
26 get { return this.m_Horizontal; }
27 set { this.m_Horizontal = value; }
28 }
29
34 public bool vertical
35 {
36 get { return this.m_Veritical; }
37 set { this.m_Veritical = value; }
38 }
39
40 public override void ModifyMesh(VertexHelper verts)
41 {
42 RectTransform rt = this.transform as RectTransform;
43
44 for (int i = 0; i < verts.currentVertCount; ++i)
45 {
46 UIVertex uiVertex = new UIVertex();
47 verts.PopulateUIVertex(ref uiVertex,i);
48
49 // Modify positions
50 uiVertex.position = new Vector3(
51 (this.m_Horizontal ? (uiVertex.position.x + (rt.rect.center.x - uiVertex.position.x) * 2) : uiVertex.position.x),
52 (this.m_Veritical ? (uiVertex.position.y + (rt.rect.center.y - uiVertex.position.y) * 2) : uiVertex.position.y),
53 uiVertex.position.z
54 );
55
56 // Apply
57 verts.SetUIVertex(uiVertex, i);
58 }
59 }
60
61#if UNITY_EDITOR
62 protected override void OnValidate()
63 {
64 var components = gameObject.GetComponents(typeof(BaseMeshEffect));
65 foreach (var comp in components)
66 {
67 if (comp.GetType() != typeof(UIFlippable))
68 {
69 UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
70 }
71 else break;
72 }
73 this.GetComponent<Graphic>().SetVerticesDirty();
74 base.OnValidate();
75 }
76#endif
77 }
78}
bool horizontal
Gets or sets a value indicating whether this UnityEngine.UI.UIFlippable should be flipped horizontall...
Definition: UIFlippable.cs:25
bool vertical
Gets or sets a value indicating whether this UnityEngine.UI.UIFlippable should be flipped vertically.
Definition: UIFlippable.cs:35
override void ModifyMesh(VertexHelper verts)
Definition: UIFlippable.cs:40
Credit Erdener Gonenc - @PixelEnvision.