using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using VRTK; //车轮交互类 激活时先按照whellCollider 位置显示能交互的车轮 public class CheLun : SimpleGrabGO { //public Transform thisChezhou; //public Transform targetPosCheZhou; public Transform onCarWheel; HingeJoint thisHingeJoint; float lastFrameRotateValue; //与本物体协同旋转 public List rotateWithGOs= new List(); //开始时隐藏可交互车轮 等激活时显示 private void Start() { thisHingeJoint = this.GetComponent(); this.gameObject.SetActive(false); lastFrameRotateValue = this.transform.localEulerAngles.x; } public override void Active(ProcessEnum stepName, UnityAction finishedEven) { onCarWheel.gameObject.SetActive(false);//隐藏原有车轮 this.gameObject.SetActive(true);//显示车轮 thisHingeJoint.connectedAnchor = onCarWheel.transform.position; ProcessManager.Instance.RegisterStepFinishedEvent("制动螺栓", RealUnActive); ProcessManager.Instance.RegisterStepFinishedEvent("千斤顶", RealUnActive); thisCollider.enabled = true; SetGrabInteractable(true); } //安装流程某些流程完成后 真正失去激活状态 void RealUnActive() { ProcessManager.Instance.RemoveStepFinishedEvent("制动螺栓", RealUnActive); ProcessManager.Instance.RemoveStepFinishedEvent("千斤顶", RealUnActive); this.gameObject.SetActive(false);//隐藏可交互车轮 onCarWheel.gameObject.SetActive(true);//显示原有车轮 SetGrabInteractable(false); } //车轮比较特殊 只要满足条件可以一直转动,无法通过流程退出激活 public override void UnActive(ProcessEnum stepName) { Debug.Log("车轮失去激活状态不做处理"); } private void FixedUpdate() { //Debug.LogWarning(this.transform.localEulerAngles.x); float changeValue = this.transform.localEulerAngles.x - lastFrameRotateValue; if (Mathf.Abs(changeValue)>0.1f) { if (changeValue > 180) { //Debug.LogError(changeValue); changeValue -= 360; } else if (changeValue < -180) { //Debug.LogError(changeValue); changeValue += 360; } //Debug.Log(changeValue); foreach (var item in rotateWithGOs) { item.DoRotate(changeValue); } } lastFrameRotateValue = this.transform.localEulerAngles.x; } }