Patch_VideoController.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections.Generic;
  2. using System.Collections;
  3. using Blue;
  4. using SC.XR.Unity.Module_InputSystem;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using static BoundingBox;
  8. public class Patch_VideoController : AbstractController
  9. {
  10. [SerializeField] private BoundingBox boundingBox;
  11. [SerializeField] private ManipulationHandler manipulationHandler;
  12. [SerializeField] private GameObject obj_BoundingBox;
  13. void Start()
  14. {
  15. if (GetComponent<ManipulationHandler>() != null)
  16. {
  17. Destroy(manipulationHandler);
  18. }
  19. if (GetComponent<BoundingBox>() != null)
  20. {
  21. Destroy(boundingBox);
  22. }
  23. /*
  24. this.RegisterEvent<Patch_VideoEvent>(e=>
  25. {
  26. if(e.set)
  27. {
  28. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  29. //Debug.LogError("manipulationHandler:"+manipulationHandler==null);
  30. boundingBox.enabled = true;
  31. manipulationHandler.enabled = true;
  32. }
  33. else
  34. {
  35. if (transform.Find("BoundingBox").gameObject != null)
  36. Destroy(transform.Find("BoundingBox").gameObject);
  37. boundingBox.enabled = false;
  38. Destroy(manipulationHandler);
  39. }
  40. });
  41. */
  42. toggle = GameObject.Find("SetBtn/Canvas/Parent/EditorBtn/Toggle").GetComponent<Toggle>();
  43. }
  44. private Toggle toggle;
  45. private void Update()
  46. {
  47. if(!toggle.isOn)
  48. {
  49. if (transform.Find("BoundingBox").gameObject != null)
  50. Destroy(transform.Find("BoundingBox").gameObject);
  51. if(manipulationHandler!=null)
  52. Destroy(manipulationHandler);
  53. if(boundingBox!=null)
  54. Destroy(boundingBox);
  55. }
  56. else
  57. {
  58. if (manipulationHandler == null)
  59. {
  60. manipulationHandler = gameObject.AddComponent<ManipulationHandler>();
  61. if(manipulationHandler.enabled==false)
  62. {
  63. manipulationHandler.enabled = true;
  64. }
  65. }
  66. if (boundingBox == null)
  67. {
  68. boundingBox = gameObject.AddComponent<BoundingBox>();
  69. if(boundingBox.enabled==false)
  70. {
  71. boundingBox.enabled = true;
  72. StartCoroutine(Set());
  73. Debug.LogError(boundingBox.ActiveHandle);
  74. }
  75. else
  76. {
  77. boundingBox.FlattenAxis = FlattenModeType.FlattenZ;
  78. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  79. }
  80. }
  81. }
  82. }
  83. private IEnumerator Set()
  84. {
  85. yield return null;
  86. boundingBox.FlattenAxis = FlattenModeType.FlattenZ;
  87. boundingBox.ActiveHandle = HandleType.Rotation | HandleType.Scale;
  88. }
  89. }