UIFlip.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Coffee.UIEffects
  6. {
  7. [DisallowMultipleComponent]
  8. [AddComponentMenu("UI/UIEffects/UIFlip", 102)]
  9. public class UIFlip : BaseMeshEffect
  10. {
  11. [Tooltip("Flip horizontally.")] [SerializeField]
  12. private bool m_Horizontal = false;
  13. [Tooltip("Flip vertically.")] [SerializeField]
  14. private bool m_Veritical = false;
  15. /// <summary>
  16. /// Gets or sets a value indicating whether this <see cref="Coffee.UIEffects.UIFlip"/> should be flipped horizontally.
  17. /// </summary>
  18. /// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value>
  19. public bool horizontal
  20. {
  21. get { return m_Horizontal; }
  22. set
  23. {
  24. if (m_Horizontal == value) return;
  25. m_Horizontal = value;
  26. SetEffectParamsDirty();
  27. }
  28. }
  29. /// <summary>
  30. /// Gets or sets a value indicating whether this <see cref="Coffee.UIEffects.UIFlip"/> should be flipped vertically.
  31. /// </summary>
  32. /// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value>
  33. public bool vertical
  34. {
  35. get { return m_Veritical; }
  36. set
  37. {
  38. if (m_Veritical == value) return;
  39. m_Veritical = value;
  40. SetEffectParamsDirty();
  41. }
  42. }
  43. /// <summary>
  44. /// Call used to modify mesh.
  45. /// </summary>
  46. /// <param name="vh">VertexHelper.</param>
  47. public override void ModifyMesh(VertexHelper vh, Graphic graphic)
  48. {
  49. if (!isActiveAndEnabled) return;
  50. var vt = default(UIVertex);
  51. for (var i = 0; i < vh.currentVertCount; i++)
  52. {
  53. vh.PopulateUIVertex(ref vt, i);
  54. var pos = vt.position;
  55. vt.position = new Vector3(
  56. m_Horizontal ? -pos.x : pos.x,
  57. m_Veritical ? -pos.y : pos.y
  58. );
  59. vh.SetUIVertex(vt, i);
  60. }
  61. }
  62. }
  63. }