CVR_TriggerAniBase.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. namespace ChivaXR.VR
  2. {
  3. using Sirenix.OdinInspector;
  4. using UnityEngine;
  5. [System.Serializable]
  6. /// <summary>
  7. /// CVR_触发点动画抽象类
  8. /// </summary>
  9. public abstract class CVR_TriggerAniBase
  10. {
  11. [PropertyOrder(-1)]
  12. [LabelText("隐藏模拟工具模型")]
  13. public bool closeSimulationTool;
  14. protected CVR_SimulationTool simulationTool;
  15. protected CVR_SimulationPoint simulationPoint
  16. {
  17. get
  18. {
  19. if (simulationTool != null)
  20. {
  21. if (simulationTool.simulationPoint == null)
  22. {
  23. simulationTool.CreatSimulationPoint();
  24. }
  25. return simulationTool.simulationPoint;
  26. }
  27. return null;
  28. }
  29. }
  30. protected IVR_Interactable Interactable
  31. {
  32. get
  33. {
  34. if (simulationTool != null)
  35. {
  36. return simulationTool.Interactable;
  37. }
  38. return null;
  39. }
  40. }
  41. protected GameObject CurrentHand
  42. {
  43. get
  44. {
  45. if (simulationTool != null)
  46. {
  47. return simulationTool.Interactable.CVR_GetInteractableObject();
  48. }
  49. return null;
  50. }
  51. }
  52. protected CVR_TriggerElement triggerElement;
  53. private float value;
  54. protected float Value
  55. {
  56. get { return value; }
  57. set
  58. {
  59. if (this.value != value)
  60. {
  61. this.value = value;
  62. triggerElement.Value = this.value;
  63. }
  64. }
  65. }
  66. /// <summary>
  67. /// SimulationAni初始化
  68. /// </summary>
  69. /// <param name="tool"></param>
  70. public virtual void Init(CVR_TriggerElement trigger, CVR_SimulationTool tool)
  71. {
  72. triggerElement = trigger;
  73. simulationTool = tool;
  74. SimulationEnter();
  75. }
  76. /// <summary>
  77. /// 开始模拟动画
  78. /// </summary>
  79. public virtual void SimulationEnter()
  80. {
  81. if (closeSimulationTool) CloseOrOpenSimulationToolMesh(false);
  82. }
  83. /// <summary>
  84. /// 每帧模拟动画
  85. /// </summary>
  86. public abstract void SimulationUpdate();
  87. /// <summary>
  88. /// 结束模拟动画
  89. /// </summary>
  90. public virtual void SimulationExit()
  91. {
  92. if (closeSimulationTool) CloseOrOpenSimulationToolMesh(true);
  93. }
  94. public virtual void CloseSimulation()
  95. {
  96. SimulationExit();
  97. simulationTool = null;
  98. }
  99. private void CloseOrOpenSimulationToolMesh(bool open)
  100. {
  101. MeshRenderer[] renders = simulationTool.gameObject.GetComponentsInChildren<MeshRenderer>();
  102. foreach (var item in renders)
  103. {
  104. item.enabled = open;
  105. }
  106. }
  107. }
  108. }