diff --git a/Assets/UIEffect/UIFlip.cs b/Assets/UIEffect/UIFlip.cs new file mode 100644 index 00000000..008fbde3 --- /dev/null +++ b/Assets/UIEffect/UIFlip.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace Coffee.UIExtensions +{ + + [RequireComponent(typeof(Graphic))] + [DisallowMultipleComponent] + public class UIFlip : BaseMeshEffect + { + //################################ + // Serialize Members. + //################################ + [SerializeField] private bool m_Horizontal = false; + [SerializeField] private bool m_Veritical = false; + + //################################ + // Public Members. + //################################ + /// + /// Gets or sets a value indicating whether this should be flipped horizontally. + /// + /// true if be flipped horizontally; otherwise, false. + public bool horizontal { get { return this.m_Horizontal; } set { this.m_Horizontal = value; } } + + /// + /// Gets or sets a value indicating whether this should be flipped vertically. + /// + /// true if be flipped horizontally; otherwise, false. + public bool vertical { get { return this.m_Veritical; } set { this.m_Veritical = value; } } + + /// + /// Call used to modify mesh. + /// + /// VertexHelper. + public override void ModifyMesh(VertexHelper vh) + { + RectTransform rt = graphic.rectTransform; + UIVertex vt = default(UIVertex); + Vector3 pos; + Vector2 center = rt.rect.center; + for (int i = 0; i < vh.currentVertCount; i++) + { + vh.PopulateUIVertex(ref vt, i); + pos = vt.position; + vt.position = new Vector3( + m_Horizontal ? -pos.x : pos.x, + m_Veritical ? -pos.y : pos.y +// m_Horizontal ? (pos.x + (center.x - pos.x) * 2) : pos.x, +// m_Veritical ? (pos.y + (center.y - pos.y) * 2) : pos.y + ); + vh.SetUIVertex(vt, i); + } + } + } +} \ No newline at end of file diff --git a/Assets/UIEffect/UIFlip.cs.meta b/Assets/UIEffect/UIFlip.cs.meta new file mode 100644 index 00000000..86d3ecba --- /dev/null +++ b/Assets/UIEffect/UIFlip.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9bb4e59514e90489d985e9a17c838085 +timeCreated: 1525607243 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: