-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Flip horizontal/vertical #47
- Loading branch information
Takashi Sakai
committed
May 7, 2018
1 parent
bb300be
commit 8ae051b
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
//################################ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether this <see cref="Coffee.UIExtensions.UIFlip"/> should be flipped horizontally. | ||
/// </summary> | ||
/// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value> | ||
public bool horizontal { get { return this.m_Horizontal; } set { this.m_Horizontal = value; } } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether this <see cref="Coffee.UIExtensions.UIFlip"/> should be flipped vertically. | ||
/// </summary> | ||
/// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value> | ||
public bool vertical { get { return this.m_Veritical; } set { this.m_Veritical = value; } } | ||
|
||
/// <summary> | ||
/// Call used to modify mesh. | ||
/// </summary> | ||
/// <param name="vh">VertexHelper.</param> | ||
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); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.