Patch_ModelController.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. void Start()
  10. {
  11. if (GetComponent<ManipulationHandler>() != null)
  12. {
  13. Destroy(manipulationHandler);
  14. }
  15. if (GetComponent<BoundingBox>() != null)
  16. {
  17. Destroy(boundingBox);
  18. }
  19. toggle = GameObject.Find("SetBtn/Canvas/Parent/EditorBtn/Toggle").GetComponent<Toggle>();
  20. }
  21. private Toggle toggle;
  22. private void Update()
  23. {
  24. if(!toggle.isOn)
  25. {
  26. if(manipulationHandler!=null)
  27. Destroy(manipulationHandler);
  28. if (boundingBox != null)
  29. {
  30. Destroy(boundingBox);
  31. if (transform.Find("BoundingBox").gameObject != null)
  32. Destroy(transform.Find("BoundingBox").gameObject);
  33. }
  34. }
  35. else
  36. {
  37. if (manipulationHandler == null)
  38. {
  39. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  40. }
  41. if (boundingBox == null)
  42. {
  43. boundingBox = gameObject.AddComponent<BoundingBox>();
  44. boundingBox.FlattenAxis = FlattenModeType.DoNotFlatten;
  45. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  46. }
  47. }
  48. }
  49. }