using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using VRTK; using DG.Tweening; using XFramework.NetOuter; using System; /// /// VR触发类型的 步骤行为基类 /// [RequireComponent(typeof(VRTK_InteractableObject))] public abstract class VRUsableStepActionBase : MonoBehaviour, IStepNodeAction { protected VRTK_InteractableObject interactableObject; public VRTK_InteractableObject InteractableObject { get { return interactableObject; } } protected UnityAction unFixedOver;//拆下动作完成 protected UnityAction fixedOver;//安装动作完成 //外部获取物体开始Use交互事件 public event UnityAction OnUseEvent; //外部获取物体结束Use交互事件 public event UnityAction UnUseEvent; public ProcessEnum processName; // Start is called before the first frame update protected virtual void Awake() { interactableObject = this.GetComponent(); interactableObject.touchHighlightColor = Color.green; interactableObject.touchHighlightColor.a = 0.5f; interactableObject.InteractableObjectUsed += InteractableObjectUsed; interactableObject.InteractableObjectUnused += InteractableObjectUnused; if (GroupLearnHelper.isGroup)//分组训练时 添加为VRusable 添加Handler { this.gameObject.AddComponent(); this.gameObject.AddComponent(); } SetUsable(false); } protected virtual void InteractableObjectUnused(object sender, InteractableObjectEventArgs e) { UnUseEvent?.Invoke(); UnUsed(); } //主动操作时 若开启分组训练 主动发送信息 protected virtual void InteractableObjectUsed(object sender, InteractableObjectEventArgs e) { OnUseEvent?.Invoke(); OnUsed(); } /// /// VRStopUsable/同步时时执行 /// public virtual void UnUsed() { } /// /// VRStartUsable/同步时时执行 /// public abstract void OnUsed(); //protected abstract void InteractableObjectUnused(object sender, InteractableObjectEventArgs e); //是否允许use交互 protected void SetUsable(bool isUsable) { interactableObject.isUsable = isUsable; } public virtual void Active(ProcessEnum stepName, UnityAction nodeFinishedEvent) { SetUsable(true); interactableObject.usingState = 0;//确保每次激活时 只执行InteractableObjectUsed processName = stepName; if (stepName == ProcessEnum.assemble)//安装时 完成安装时执行完成事件 { fixedOver = nodeFinishedEvent; //interactableObject.usingState = 1; } else if (stepName == ProcessEnum.teardown)//拆卸时 完成拆卸时执行完成事件 { unFixedOver = nodeFinishedEvent; //interactableObject.usingState = 0; } } public virtual void UnActive(ProcessEnum stepName) { SetUsable(false); unFixedOver = null; fixedOver = null; } }