Patch_ModelController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using SC.XR.Unity.Module_InputSystem;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using static BoundingBox;
  5. public class Patch_ModelController : AbstractController
  6. {
  7. [SerializeField] private BoundingBox boundingBox;
  8. [SerializeField] private ManipulationHandler manipulationHandler;
  9. [SerializeField] private BoxCollider boxCollider;
  10. void Start()
  11. {
  12. boundingBox = GetComponent<BoundingBox>();
  13. manipulationHandler = GetComponent<ManipulationHandler>();
  14. boxCollider = GetComponent<BoxCollider>();
  15. if (manipulationHandler != null)
  16. {
  17. manipulationHandler.enabled = false;
  18. }
  19. if (boundingBox != null)
  20. {
  21. boundingBox.enabled = false;
  22. }
  23. if (boxCollider != null)
  24. {
  25. boxCollider.enabled = false;
  26. }
  27. if (GameObject.Find("SetBtn/2.1/Canvas/Parent/EditorBtn/Toggle"))
  28. toggle = GameObject.Find("SetBtn/2.1/Canvas/Parent/EditorBtn/Toggle").GetComponent<Toggle>();
  29. }
  30. private Toggle toggle;
  31. private void Update()
  32. {
  33. if (toggle && !UserInfo.Instance.is20)
  34. {
  35. if (!toggle.isOn)
  36. {
  37. if (manipulationHandler != null)
  38. {
  39. Destroy(manipulationHandler);
  40. manipulationHandler = null;
  41. }
  42. if (boundingBox != null)
  43. {
  44. Destroy(boundingBox);
  45. boundingBox = null;
  46. if (transform.Find("BoundingBox")!=null&&transform.Find("BoundingBox").gameObject != null)
  47. Destroy(transform.Find("BoundingBox").gameObject);
  48. }
  49. if (boxCollider != null)
  50. boxCollider.enabled = false;
  51. }
  52. else
  53. {
  54. if (manipulationHandler == null)
  55. {
  56. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  57. }
  58. if (boundingBox == null)
  59. {
  60. boundingBox = gameObject.AddComponent<BoundingBox>();
  61. boundingBox.FlattenAxis = FlattenModeType.DoNotFlatten;
  62. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  63. }
  64. if (boxCollider != null)
  65. boxCollider.enabled = true;
  66. else
  67. {
  68. boxCollider = gameObject.AddComponent<BoxCollider>();
  69. }
  70. }
  71. }
  72. else if (UserInfo.Instance.is20)
  73. {
  74. if (!GameManager.m_IsStart20Editor)
  75. {
  76. if (manipulationHandler != null)
  77. manipulationHandler.enabled = false;
  78. if (boundingBox != null)
  79. {
  80. boundingBox.enabled = false;
  81. if (transform.Find("BoundingBox") && transform.Find("BoundingBox").gameObject != null)
  82. transform.Find("BoundingBox").gameObject.SetActive(false);
  83. }
  84. if (boxCollider != null)
  85. boxCollider.enabled = false;
  86. }
  87. else
  88. {
  89. if (manipulationHandler == null)
  90. {
  91. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  92. }
  93. else
  94. {
  95. manipulationHandler.enabled = true;
  96. }
  97. if (boundingBox == null)
  98. {
  99. boundingBox = gameObject.AddComponent<BoundingBox>();
  100. boundingBox.FlattenAxis = FlattenModeType.DoNotFlatten;
  101. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  102. }
  103. else
  104. {
  105. boundingBox.enabled = true;
  106. if (transform.Find("BoundingBox") && transform.Find("BoundingBox").gameObject != null)
  107. transform.Find("BoundingBox").gameObject.SetActive(true);
  108. }
  109. if (boxCollider != null)
  110. boxCollider.enabled = true;
  111. else
  112. {
  113. boxCollider = gameObject.AddComponent<BoxCollider>();
  114. }
  115. }
  116. }
  117. }
  118. }