Patch_ModelController.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. Destroy(manipulationHandler);
  39. if (boundingBox != null)
  40. {
  41. Destroy(boundingBox);
  42. if (transform.Find("BoundingBox").gameObject != null)
  43. Destroy(transform.Find("BoundingBox").gameObject);
  44. }
  45. if (boxCollider != null)
  46. boxCollider.enabled = false;
  47. }
  48. else
  49. {
  50. if (manipulationHandler == null)
  51. {
  52. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  53. }
  54. if (boundingBox == null)
  55. {
  56. boundingBox = gameObject.AddComponent<BoundingBox>();
  57. boundingBox.FlattenAxis = FlattenModeType.DoNotFlatten;
  58. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  59. }
  60. if (boxCollider != null)
  61. boxCollider.enabled = true;
  62. else
  63. {
  64. boxCollider = gameObject.AddComponent<BoxCollider>();
  65. }
  66. }
  67. }
  68. else if (UserInfo.Instance.is20)
  69. {
  70. if (!GameManager.m_IsStart20Editor)
  71. {
  72. if (manipulationHandler != null)
  73. manipulationHandler.enabled = false;
  74. if (boundingBox != null)
  75. {
  76. boundingBox.enabled = false;
  77. if (transform.Find("BoundingBox") && transform.Find("BoundingBox").gameObject != null)
  78. transform.Find("BoundingBox").gameObject.SetActive(false);
  79. }
  80. if (boxCollider != null)
  81. boxCollider.enabled = false;
  82. }
  83. else
  84. {
  85. if (manipulationHandler == null)
  86. {
  87. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  88. }
  89. else
  90. {
  91. manipulationHandler.enabled = true;
  92. }
  93. if (boundingBox == null)
  94. {
  95. boundingBox = gameObject.AddComponent<BoundingBox>();
  96. boundingBox.FlattenAxis = FlattenModeType.DoNotFlatten;
  97. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  98. }
  99. else
  100. {
  101. boundingBox.enabled = true;
  102. if (transform.Find("BoundingBox") && transform.Find("BoundingBox").gameObject != null)
  103. transform.Find("BoundingBox").gameObject.SetActive(true);
  104. }
  105. if (boxCollider != null)
  106. boxCollider.enabled = true;
  107. else
  108. {
  109. boxCollider = gameObject.AddComponent<BoxCollider>();
  110. }
  111. }
  112. }
  113. }
  114. }