namespace ChivaXR.VR
{
using Sirenix.OdinInspector;
using UnityEngine;
[System.Serializable]
///
/// CVR_触发点动画抽象类
///
public abstract class CVR_TriggerAniBase
{
[PropertyOrder(-1)]
[LabelText("隐藏模拟工具模型")]
public bool closeSimulationTool;
protected CVR_SimulationTool simulationTool;
protected CVR_SimulationPoint simulationPoint
{
get
{
if (simulationTool != null)
{
if (simulationTool.simulationPoint == null)
{
simulationTool.CreatSimulationPoint();
}
return simulationTool.simulationPoint;
}
return null;
}
}
protected IVR_Interactable Interactable
{
get
{
if (simulationTool != null)
{
return simulationTool.Interactable;
}
return null;
}
}
protected GameObject CurrentHand
{
get
{
if (simulationTool != null)
{
return simulationTool.Interactable.CVR_GetInteractableObject();
}
return null;
}
}
protected CVR_TriggerElement triggerElement;
private float value;
protected float Value
{
get { return value; }
set
{
if (this.value != value)
{
this.value = value;
triggerElement.Value = this.value;
}
}
}
///
/// SimulationAni初始化
///
///
public virtual void Init(CVR_TriggerElement trigger, CVR_SimulationTool tool)
{
triggerElement = trigger;
simulationTool = tool;
SimulationEnter();
}
///
/// 开始模拟动画
///
public virtual void SimulationEnter()
{
if (closeSimulationTool) CloseOrOpenSimulationToolMesh(false);
}
///
/// 每帧模拟动画
///
public abstract void SimulationUpdate();
///
/// 结束模拟动画
///
public virtual void SimulationExit()
{
if (closeSimulationTool) CloseOrOpenSimulationToolMesh(true);
}
public virtual void CloseSimulation()
{
SimulationExit();
simulationTool = null;
}
private void CloseOrOpenSimulationToolMesh(bool open)
{
MeshRenderer[] renders = simulationTool.gameObject.GetComponentsInChildren();
foreach (var item in renders)
{
item.enabled = open;
}
}
}
}