123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- public class OvrControllerBehavior : AVRControllerBehavior
- {
- public override AVRControllerBehavior.BEH_TYPE BehaviourType
- {
- get
- {
- return AVRControllerBehavior.BEH_TYPE.LEGACY;
- }
- }
- public override bool HandCameraMode
- {
- get
- {
- return this.m_eMode == OvrControllerBehavior.OvrControllerMode.CAMERA;
- }
- set
- {
- if (value)
- {
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.CAMERA);
- }
- }
- }
- public override bool IsHandCameraMode
- {
- get
- {
- return this.m_eMode == OvrControllerBehavior.OvrControllerMode.CAMERA;
- }
- }
- public override bool IsHandPenMode
- {
- get
- {
- return false;
- }
- }
- public override bool HandDanceMode
- {
- get
- {
- return this.m_bHandDanceMode && this.m_eMode == OvrControllerBehavior.OvrControllerMode.DANCE;
- }
- set
- {
- this.m_bHandDanceMode = value;
- if (value)
- {
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.DANCE);
- }
- else if (!value && this.m_eMode == OvrControllerBehavior.OvrControllerMode.DANCE)
- {
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
- }
- }
- }
- public override bool HandVRIKMode
- {
- get
- {
- return false;
- }
- set
- {
- }
- }
- public override bool HandYotogiMode
- {
- get
- {
- return false;
- }
- set
- {
- }
- }
- protected override void Awake()
- {
- base.Awake();
- GameMain.Instance.CMSystem.OvrPointerMode = Mathf.Max(Mathf.Min(0, GameMain.Instance.CMSystem.OvrPointerMode), 0);
- GameMain.Instance.CMSystem.OvrMoveMode = Mathf.Max(Mathf.Min(2, GameMain.Instance.CMSystem.OvrMoveMode), 0);
- this.m_txMode = base.transform.Find("UI/Canvas/Text").GetComponent<Text>();
- this.m_goHandCamera = base.transform.Find("HandCamera").gameObject;
- this.m_HandCamera = this.m_goHandCamera.GetComponent<OvrHandCamera>();
- this.m_HandCamera.m_ctrl = this;
- this.m_goHandModel = base.transform.Find("HandPlayer").gameObject;
- this.m_HandAnim = this.m_goHandModel.GetComponent<OvrHandAnimator>();
- NDebug.Assert(this.m_HandAnim != null);
- this.m_HandAnim.Init(this.m_buttons);
- this.m_HandItem = base.transform.Find("HandItem").GetComponent<OvrHandItemMgr>();
- this.m_HandItem.m_ctrl = this;
- this.m_HandItem.gameObject.SetActive(false);
- this.m_ArcTeleport = base.transform.Find("ArcTeleport").GetComponentInChildren<ArcTeleport>(true);
- this.m_ArcTeleport.SetCallBackOnMove(new ArcTeleport.dgOnMove(this.OnWarpMove));
- this.m_fCursorEasing = GameMain.Instance.CMSystem.OvrCursorStabilization;
- this.m_fCursorBoost = GameMain.Instance.CMSystem.OvrCursorBoostSpeed;
- this.m_fCursorLaserEasing = GameMain.Instance.CMSystem.OvrViveCursorLaserEasing;
- }
- private void Start()
- {
- GameMain.Instance.OvrMgr.OvrCamera.m_bWheelToZoom = false;
- if (this.m_bHandL)
- {
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOVE);
- }
- else
- {
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
- }
- }
- private void OnEnable()
- {
- this.ChangeMode(this.m_eMode);
- }
- private void OnDisable()
- {
- this.m_HandItem.gameObject.SetActive(false);
- }
- private void ChangeMode(OvrControllerBehavior.OvrControllerMode f_eNewMode)
- {
- if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.GRAB)
- {
- this.m_obj_controller.grip_collider.enabled = true;
- }
- else
- {
- this.m_obj_controller.grip_collider.enabled = false;
- }
- bool flag = false;
- if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.CAMERA)
- {
- this.m_goHandCamera.SetActive(true);
- flag = true;
- }
- else
- {
- this.m_goHandCamera.SetActive(false);
- }
- if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.ITEM)
- {
- this.m_HandItem.gameObject.SetActive(true);
- flag = true;
- }
- else
- {
- this.m_HandItem.gameObject.SetActive(false);
- }
- if (flag)
- {
- this.m_goHandModel.SetActive(false);
- this.m_txMode.enabled = false;
- }
- else
- {
- this.m_goHandModel.SetActive(true);
- this.m_txMode.enabled = true;
- }
- GameMain.Instance.OvrMgr.SystemUICamera.SetActiveVirtualCursorObjByNocurrent((!this.m_bHandL) ? UICamera.VCURSOR.RIGHT : UICamera.VCURSOR.LEFT, f_eNewMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
- this.m_txMode.text = this.m_strMode[(int)f_eNewMode];
- if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER)
- {
- Text txMode = this.m_txMode;
- txMode.text += this.m_strPointerMode[GameMain.Instance.CMSystem.OvrPointerMode];
- }
- else if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.MOVE)
- {
- Text txMode2 = this.m_txMode;
- txMode2.text += this.m_strMoveMode[GameMain.Instance.CMSystem.OvrMoveMode];
- }
- this.m_eMode = f_eNewMode;
- Debug.Log("コントローラモード変更:" + this.m_eMode.ToString());
- }
- private void ChangePointerMode(OvrControllerBehavior.PointerSubMode f_ePMode)
- {
- GameMain.Instance.CMSystem.OvrPointerMode = (int)f_ePMode;
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
- }
- private void ChangeMoveMode(OvrControllerBehavior.MoveSubMode f_eSubMode)
- {
- GameMain.Instance.CMSystem.OvrMoveMode = (int)f_eSubMode;
- this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOVE);
- }
- private void TouchPadToClick()
- {
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) || this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_R_CLICK))
- {
- this.m_bCursorMoveEnable = false;
- GameMain.Instance.OvrMgr.SystemUICamera.SetCurrentCursorSide((!this.m_bHandL) ? UICamera.VCURSOR.RIGHT : UICamera.VCURSOR.LEFT);
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK))
- {
- NUty.EmurateMouseButton(2);
- this.m_bPressLeft = true;
- }
- else if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_R_CLICK))
- {
- NUty.EmurateMouseButton(8);
- this.m_bPressLeft = false;
- }
- if (this.m_coCursorMoveWait != null)
- {
- base.StopCoroutine(this.m_coCursorMoveWait);
- }
- this.m_coCursorMoveWait = base.StartCoroutine(this.CoCursorMoveWait());
- }
- else if (this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) || this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_R_CLICK))
- {
- if (this.m_bPressLeft)
- {
- NUty.EmurateMouseButton(4);
- }
- else
- {
- NUty.EmurateMouseButton(16);
- }
- }
- }
- private IEnumerator CoCursorMoveWait()
- {
- yield return new WaitForSeconds(0.3f);
- this.m_bCursorMoveEnable = true;
- yield break;
- }
- private void TouchPadWheel()
- {
- float y = this.m_buttons.GetAxis().y;
- if (0.1f < Mathf.Abs(y))
- {
- if (this.m_bWheelFirst)
- {
- NUty.EmurateMouseWheel((y >= 0f) ? 1 : -1);
- this.m_fWheel = 0f;
- this.m_bWheelFirst = false;
- }
- else
- {
- this.m_fWheel += y * (Time.deltaTime * 5f);
- if (this.m_fWheel <= -1f || 1f <= this.m_fWheel)
- {
- NUty.EmurateMouseWheel((int)this.m_fWheel);
- this.m_fWheel = 0f;
- }
- }
- }
- else
- {
- this.m_bWheelFirst = true;
- }
- }
- private void OnWarpMove(Vector3 f_vPosWorld, Vector3 f_vRotWorld)
- {
- GameMain.Instance.MainCamera.SetFootPos(f_vPosWorld, CameraMain.STAND_SIT.STAND);
- GameMain.Instance.MainCamera.SetRealHeadRot(f_vRotWorld, true);
- }
- protected virtual void Update()
- {
- if (!this.m_controller.HandEnable)
- {
- return;
- }
- this.m_vMoveCam.x = (this.m_vMoveCam.y = (this.m_vMoveCam.z = (this.m_fRotCam = 0f)));
- this.m_vMoveVelocity.x = (this.m_vMoveVelocity.y = (this.m_vMoveVelocity.z = 0f));
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_MENU))
- {
- this.m_bPressMenuBtnLong = false;
- this.m_fMenuPressBeforeTime = Time.realtimeSinceStartup;
- }
- else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.VIRTUAL_MENU))
- {
- if (!this.m_bPressMenuBtnLong && Time.realtimeSinceStartup - this.m_fMenuPressBeforeTime > 1f)
- {
- if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER)
- {
- int num = GameMain.Instance.CMSystem.OvrPointerMode + 1;
- if (1 <= num)
- {
- num = 0;
- }
- this.ChangePointerMode((OvrControllerBehavior.PointerSubMode)num);
- }
- else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE)
- {
- int num2 = GameMain.Instance.CMSystem.OvrMoveMode + 1;
- if (3 <= num2)
- {
- num2 = 0;
- }
- this.ChangeMoveMode((OvrControllerBehavior.MoveSubMode)num2);
- }
- else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.ITEM)
- {
- this.m_HandItem.NextModel();
- }
- this.m_bPressMenuBtnLong = true;
- }
- }
- else if (this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_MENU) && !this.m_bPressMenuBtnLong)
- {
- if (this.m_buttons.GetPress(AVRControllerButtons.BTN.MENU))
- {
- GameMain.Instance.OvrMgr.OvrCamera.ReCallcOffset();
- GameMain.Instance.OvrMgr.OvrCamera.ShowUI(true);
- GameMain.Instance.OvrMgr.OvrCamera.UIPosReset(0f);
- }
- else
- {
- int num3 = (int)(this.m_eMode + 1);
- if (num3 == 5 && !this.m_bHandDanceMode)
- {
- num3++;
- }
- if (6 <= num3)
- {
- num3 = 0;
- }
- this.ChangeMode((OvrControllerBehavior.OvrControllerMode)num3);
- }
- }
- if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER)
- {
- if (GameMain.Instance.CMSystem.OvrPointerMode == 0)
- {
- RaycastHit raycastHit;
- if (this.m_bCursorMoveEnable && Physics.Raycast(base.transform.position, base.transform.rotation * Vector3.forward, out raycastHit, float.PositiveInfinity, 33554432))
- {
- Vector2 textureCoord = raycastHit.textureCoord;
- Vector2 a = new Vector2(1280f * ((textureCoord.x - this.m_fUiCursorMargin) / (1f - this.m_fUiCursorMargin * 2f)), 720f * ((textureCoord.y - this.m_fUiCursorMargin) / (1f - this.m_fUiCursorMargin * 2f)));
- Vector2 vector = GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMousePos(this.m_bHandL);
- Vector2 a2 = a - vector;
- Vector2 b = a2 * this.m_fCursorLaserEasing;
- Vector2 v = vector + b;
- GameMain.Instance.OvrMgr.SystemUICamera.SetOvrVirtualMousePos(this.m_bHandL, v);
- }
- Debug.DrawLine(base.transform.position, base.transform.position + base.transform.rotation * (Vector3.forward * 10f), new Color(1f, 0f, 0f));
- this.TouchPadToClick();
- this.TouchPadWheel();
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.GRIP))
- {
- GameMain.Instance.OvrMgr.OvrCamera.ToggleUI();
- }
- }
- }
- else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE)
- {
- if (GameMain.Instance.CMSystem.OvrMoveMode == 0)
- {
- Vector2 vector2 = this.m_buttons.GetAxis() * this.m_fMoveSpeed;
- if (this.m_buttons.GetPress(AVRControllerButtons.BTN.TRIGGER))
- {
- this.m_vMoveCam.y = vector2.y;
- }
- else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.GRIP))
- {
- this.m_fRotCam = vector2.x;
- }
- else
- {
- this.m_vMoveCam.x = -vector2.x;
- this.m_vMoveCam.z = vector2.y;
- }
- }
- else if (GameMain.Instance.CMSystem.OvrMoveMode == 2)
- {
- }
- }
- else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.CAMERA)
- {
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.TRIGGER))
- {
- this.m_HandCamera.Snap();
- }
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.STICK_PAD))
- {
- GameMain.Instance.OvrMgr.OvrCamera.ToggleUI();
- }
- }
- }
- public override Vector3 GetVelocityHand()
- {
- Vector3 result = default(Vector3);
- if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE && GameMain.Instance.CMSystem.OvrMoveMode == 1)
- {
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.GRIP))
- {
- this.m_vMoveTugPosBack = base.transform.position;
- }
- else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.GRIP))
- {
- if (this.m_goTestObj != null)
- {
- this.m_goTestObj.transform.position = base.transform.position;
- }
- Vector3 a = base.transform.position - this.m_vMoveTugPosBack;
- result = a * -1f;
- }
- }
- return result;
- }
- public override float GetRotHandY()
- {
- float num = 0f;
- if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE && GameMain.Instance.CMSystem.OvrMoveMode == 1)
- {
- if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.STICK_PAD))
- {
- Transform baseHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetBaseHeadTransform();
- Vector3 position = baseHeadTransform.position;
- position.y = 0f;
- Vector3 vector = baseHeadTransform.rotation * Vector3.forward;
- vector.y = 0f;
- Vector3 position2 = base.transform.position;
- position2.y = 0f;
- Vector3 vector2 = position2 - position;
- this.m_fRotBack = Quaternion.FromToRotation(vector.normalized, vector2.normalized).eulerAngles.y;
- }
- else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.STICK_PAD))
- {
- Transform baseHeadTransform2 = GameMain.Instance.OvrMgr.OvrCamera.GetBaseHeadTransform();
- Vector3 position3 = baseHeadTransform2.position;
- position3.y = 0f;
- Vector3 vector3 = baseHeadTransform2.rotation * Vector3.forward;
- vector3.y = 0f;
- Vector3 position4 = base.transform.position;
- position4.y = 0f;
- Vector3 vector4 = position4 - position3;
- num = Quaternion.FromToRotation(vector3.normalized, vector4.normalized).eulerAngles.y - this.m_fRotBack;
- num *= -1f;
- }
- }
- return num;
- }
- protected virtual void LateUpdate()
- {
- if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE && GameMain.Instance.CMSystem.OvrMoveMode == 1 && this.m_buttons.GetPress(AVRControllerButtons.BTN.STICK_PAD))
- {
- Transform baseHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetBaseHeadTransform();
- Vector3 position = baseHeadTransform.position;
- position.y = 0f;
- Vector3 vector = baseHeadTransform.rotation * Vector3.forward;
- vector.y = 0f;
- Vector3 position2 = base.transform.position;
- position2.y = 0f;
- Vector3 vector2 = position2 - position;
- this.m_fRotBack = Quaternion.FromToRotation(vector.normalized, vector2.normalized).eulerAngles.y;
- }
- }
- public float m_fPointerSpeed = 10f;
- public float m_fMoveSpeed = 10f;
- public Vector3 m_vMoveVelocity;
- public float m_fCursorEasing = 6f;
- public float m_fCursorBoost = 0.1f;
- public float m_fMenuPressBeforeTime;
- public float m_fCursorLaserEasing = 0.3f;
- public float m_fUiCursorMargin = 0.2f;
- public GameObject m_goTestObj;
- private readonly string[] m_strMode = new string[]
- {
- "GRAB",
- "POINTER",
- "MOVE",
- "CAMERA",
- "ITEM",
- "DANCE"
- };
- private readonly string[] m_strPointerMode = new string[]
- {
- "-LASER"
- };
- private readonly string[] m_strMoveMode = new string[]
- {
- "-DIR",
- "-DRAW",
- "-ARC"
- };
- [NonSerialized]
- private OvrControllerBehavior.OvrControllerMode m_eMode;
- protected bool m_bPressLeft;
- protected Text m_txMode;
- protected GameObject m_goModeCanvas;
- protected bool m_bPressMenuBtnLong;
- protected GameObject m_goHandCamera;
- protected OvrHandCamera m_HandCamera;
- protected Vector3 m_vMoveTugPosBack;
- protected Vector3 m_vMoveTugRotHnadPosBack;
- protected Vector3 m_vMoveTugRotHeadPosBack;
- protected Vector3 m_vMoveTugVector;
- protected ArcTeleport m_ArcTeleport;
- protected GameObject m_goHandModel;
- protected OvrHandAnimator m_HandAnim;
- protected bool m_bWheelFirst;
- protected float m_fWheel;
- protected OvrHandItemMgr m_HandItem;
- protected bool m_bCursorMoveEnable = true;
- protected float m_fRotBack;
- protected Coroutine m_coCursorMoveWait;
- private enum OvrControllerMode
- {
- GRAB,
- MOUSE_POINTER,
- MOVE,
- CAMERA,
- ITEM,
- DANCE,
- MAX
- }
- private enum PointerSubMode
- {
- LASER,
- MAX
- }
- private enum MoveSubMode
- {
- DIRECTIONAL,
- DRAW,
- ARC,
- MAX
- }
- private enum TouchSubMode
- {
- MAN,
- WOMAN
- }
- }
|