From af1f9beeb0ca1eeca687a8e23f1b2ea943cb4bc6 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 2 Jul 2017 15:36:39 +0100 Subject: [PATCH] Fix for UIFlippable when used in combination with other BaseMeshEffects Unity is very fussy about the order now, so script updated to ensure it's above other base mesh effects on Validate. (can't solve for stupid if you reorder manually, so updating docs) Resolves #133 --- Scripts/Effects/UIFlippable.cs | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Scripts/Effects/UIFlippable.cs b/Scripts/Effects/UIFlippable.cs index f2294a4..d06dbb0 100644 --- a/Scripts/Effects/UIFlippable.cs +++ b/Scripts/Effects/UIFlippable.cs @@ -5,11 +5,18 @@ namespace UnityEngine.UI.Extensions { [RequireComponent(typeof(RectTransform), typeof(Graphic)), DisallowMultipleComponent] [AddComponentMenu("UI/Effects/Extensions/Flippable")] - public class UIFlippable : MonoBehaviour, IMeshModifier + public class UIFlippable : BaseMeshEffect { [SerializeField] private bool m_Horizontal = false; [SerializeField] private bool m_Veritical = false; - + +#if UNITY_EDITOR + protected override void Awake() + { + OnValidate(); + } +#endif + /// /// Gets or sets a value indicating whether this should be flipped horizontally. /// @@ -29,13 +36,8 @@ namespace UnityEngine.UI.Extensions get { return this.m_Veritical; } set { this.m_Veritical = value; } } - - protected void OnValidate() - { - this.GetComponent().SetVerticesDirty(); - } - - public void ModifyMesh(VertexHelper verts) + + public override void ModifyMesh(VertexHelper verts) { RectTransform rt = this.transform as RectTransform; @@ -56,9 +58,21 @@ namespace UnityEngine.UI.Extensions } } - public void ModifyMesh(Mesh mesh) +#if UNITY_EDITOR + protected override void OnValidate() { - //Obsolete member implementation + var components = gameObject.GetComponents(typeof(BaseMeshEffect)); + foreach (var comp in components) + { + if (comp.GetType() != typeof(UIFlippable)) + { + UnityEditorInternal.ComponentUtility.MoveComponentUp(this); + } + else break; + } + this.GetComponent().SetVerticesDirty(); + base.OnValidate(); } +#endif } } \ No newline at end of file