123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using System;
- using UnityEngine;
- public class VREventNotifierGrab : VREventNotifier
- {
- protected override void Start()
- {
- this.LookTimeCountDownStop();
- }
- public void Init(OvrMgr.OvrObject.Controller f_ViveController)
- {
- f_ViveController.grip_collider.on_grab_obj_callback = new OvrGripCollider.OnGrabObject(this.GrabObj);
- f_ViveController.grip_collider.on_release_obj_callback = new OvrGripCollider.OnReleaseObject(this.ReleaseObj);
- }
- private void GrabTimeCountDownStart()
- {
- this.m_fMaxTime = this.m_HitGrabTarget.GetTimeOutTime();
- this.m_fNowTime = this.m_fMaxTime;
- this.m_EventText.SetGaugeRate(0f);
- this.m_EventText.Show(VREventText.TYPE.GRAB, this.m_HitGrabTarget.GetEventName(), 0f);
- }
- private void LookTimeCountDownStop()
- {
- this.m_EventText.Hide(VREventText.TYPE.GRAB);
- }
- private void GrabTimeOut()
- {
- Debug.Log("Grab:StartScript");
- this.LookTimeCountDownStop();
- if (this.m_HitGrabTarget != null)
- {
- this.m_HitGrabTarget.StartScript();
- this.m_HitGrabTarget = null;
- }
- }
- public void GrabObj(GameObject f_goTarget)
- {
- if (SceneVRCommunication.Instance == null)
- {
- return;
- }
- if (f_goTarget == null || VREventNotifier.m_clSingle != null || GameMain.Instance.MainCamera.IsFadeProc() || !SceneVRCommunication.Instance.IsFreeMode)
- {
- return;
- }
- this.m_HitGrabTarget = f_goTarget.GetComponent<VREventTriggerGrab>();
- if (this.m_HitGrabTarget != null)
- {
- if (this.m_HitGrabTarget.rigidBody != null)
- {
- Rigidbody rigidBody = this.m_HitGrabTarget.rigidBody;
- Rigidbody rigidbody = rigidBody;
- Vector3 zero = Vector3.zero;
- rigidBody.angularVelocity = zero;
- rigidbody.velocity = zero;
- rigidBody.isKinematic = true;
- }
- if (this.m_HitGrabTarget.IsEnableEvent())
- {
- this.m_HitGrabTarget.OnEvnetCountDownEnter(base.gameObject);
- this.GrabTimeCountDownStart();
- VREventNotifier.m_clSingle = this;
- this.m_HitGrabTarget.m_dgDestroy = new VREventTriggerGrab.dgDestroy(this.ReleaseObj);
- }
- else
- {
- this.m_HitGrabTarget.m_dgDestroy = null;
- this.m_HitGrabTarget = null;
- }
- }
- }
- public void ReleaseObj(GameObject gripObject, Vector3 linearVelocity, Vector3 angularVelocity)
- {
- if (gripObject != null)
- {
- VREventTriggerGrab component = gripObject.GetComponent<VREventTriggerGrab>();
- if (component != null && component.rigidBody != null)
- {
- Rigidbody rigidBody = component.rigidBody;
- rigidBody.isKinematic = false;
- rigidBody.velocity = linearVelocity;
- rigidBody.angularVelocity = angularVelocity;
- }
- }
- if (this.m_HitGrabTarget != null)
- {
- this.m_HitGrabTarget.m_dgDestroy = null;
- this.m_HitGrabTarget.OnEventCountDownExit(base.gameObject);
- this.m_HitGrabTarget = null;
- }
- VREventNotifier.m_clSingle = null;
- this.LookTimeCountDownStop();
- }
- private void Update()
- {
- if (SceneVRCommunication.Instance == null)
- {
- return;
- }
- if (GameMain.Instance.MainCamera.IsFadeOut())
- {
- this.m_HitBackGrabTarget = false;
- if (this.m_HitGrabTarget != null)
- {
- this.m_HitGrabTarget.m_dgDestroy = null;
- this.m_HitGrabTarget = null;
- }
- this.LookTimeCountDownStop();
- return;
- }
- if (this.m_HitGrabTarget != null)
- {
- this.m_fNowTime -= Time.deltaTime;
- if (this.m_fNowTime <= 0f)
- {
- this.GrabTimeOut();
- this.m_EventText.SetGaugeRate(1f);
- }
- else
- {
- this.m_EventText.SetGaugeRate(1f - this.m_fNowTime / this.m_fMaxTime);
- }
- }
- if (this.m_HitBackGrabTarget && this.m_HitGrabTarget == null)
- {
- this.LookTimeCountDownStop();
- }
- this.m_HitBackGrabTarget = (this.m_HitGrabTarget != null);
- }
- public VREventText m_EventText;
- private float m_fMaxTime = 5f;
- private float m_fNowTime;
- private VREventTriggerGrab m_HitGrabTarget;
- private bool m_HitBackGrabTarget;
- }
|