namespace ChivaXR.VR
{
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// CVR_触发点Value动画抽象类
///
public abstract class CVR_ValueAniBase
{
[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_ValueElement valueElement;
private float value;
protected float Value
{
get { return value; }
set
{
if (this.value != value)
{
this.value = value;
if (valueElement != null)
valueElement.Value = this.value;
}
}
}
public virtual void SetValueState(float value)
{
this.Value = value;
}
///
/// SimulationAni初始化
///
///
public virtual void Init(CVR_ValueElement trigger, CVR_SimulationTool tool)
{
valueElement = 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;
}
}
}
}