HandleManager.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. namespace SRDebugger.UI.Other
  2. {
  3. using SRF;
  4. using UnityEngine;
  5. /// <summary>
  6. /// Handles enabling/disabling handle objects for different anchoring modes
  7. /// </summary>
  8. public class HandleManager : SRMonoBehaviour
  9. {
  10. private bool _hasSet;
  11. public GameObject BottomHandle;
  12. public GameObject BottomLeftHandle;
  13. public GameObject BottomRightHandle;
  14. public PinAlignment DefaultAlignment;
  15. public GameObject LeftHandle;
  16. public GameObject RightHandle;
  17. public GameObject TopHandle;
  18. public GameObject TopLeftHandle;
  19. public GameObject TopRightHandle;
  20. private void Start()
  21. {
  22. if (!_hasSet)
  23. {
  24. SetAlignment(DefaultAlignment);
  25. }
  26. }
  27. public void SetAlignment(PinAlignment alignment)
  28. {
  29. _hasSet = true;
  30. switch (alignment)
  31. {
  32. case PinAlignment.TopLeft:
  33. case PinAlignment.TopRight:
  34. SetActive(BottomHandle, true);
  35. SetActive(TopHandle, false);
  36. SetActive(TopLeftHandle, false);
  37. SetActive(TopRightHandle, false);
  38. break;
  39. case PinAlignment.BottomLeft:
  40. case PinAlignment.BottomRight:
  41. SetActive(BottomHandle, false);
  42. SetActive(TopHandle, true);
  43. SetActive(BottomLeftHandle, false);
  44. SetActive(BottomRightHandle, false);
  45. break;
  46. }
  47. switch (alignment)
  48. {
  49. case PinAlignment.TopLeft:
  50. case PinAlignment.BottomLeft:
  51. SetActive(LeftHandle, false);
  52. SetActive(RightHandle, true);
  53. SetActive(TopLeftHandle, false);
  54. SetActive(BottomLeftHandle, false);
  55. break;
  56. case PinAlignment.TopRight:
  57. case PinAlignment.BottomRight:
  58. SetActive(LeftHandle, true);
  59. SetActive(RightHandle, false);
  60. SetActive(TopRightHandle, false);
  61. SetActive(BottomRightHandle, false);
  62. break;
  63. }
  64. switch (alignment)
  65. {
  66. case PinAlignment.TopLeft:
  67. SetActive(BottomLeftHandle, false);
  68. SetActive(BottomRightHandle, true);
  69. break;
  70. case PinAlignment.TopRight:
  71. SetActive(BottomLeftHandle, true);
  72. SetActive(BottomRightHandle, false);
  73. break;
  74. case PinAlignment.BottomLeft:
  75. SetActive(TopLeftHandle, false);
  76. SetActive(TopRightHandle, true);
  77. break;
  78. case PinAlignment.BottomRight:
  79. SetActive(TopLeftHandle, true);
  80. SetActive(TopRightHandle, false);
  81. break;
  82. }
  83. }
  84. private void SetActive(GameObject obj, bool active)
  85. {
  86. if (obj == null)
  87. {
  88. return;
  89. }
  90. obj.SetActive(active);
  91. }
  92. }
  93. }