CVR_ValueAniBase.cs 3.3 KB

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