using System; using System.Collections; using UnityEngine; using UnityEngine.UI; public class OvrControllerBehavior2 : OvrControllerBehavior { public override AVRControllerBehavior.BEH_TYPE BehaviourType { get { return AVRControllerBehavior.BEH_TYPE.NEW; } } public override bool HandCameraMode { get { return this.m_eMode == OvrControllerBehavior2.OvrControllerMode.CAMERA; } set { if (value) { this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.CAMERA); } } } public override bool IsHandCameraMode { get { return this.m_eModeBack == OvrControllerBehavior2.OvrControllerMode.CAMERA; } } public override bool IsHandPenMode { get { return this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN; } } public override bool HandModelVisible { get { return this.m_bHandModelVisible; } set { this.m_bHandModelVisible = value; this.ChangeMode(this.m_eMode); } } public override AVRControllerBehavior.LIMIT_MODE HandLimitMode { set { if (value == AVRControllerBehavior.LIMIT_MODE.HAND_ONLY) { this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.HAND); } base.HandLimitMode = value; } } public override bool HandDanceMode { get { return this.m_bHandDanceMode && this.m_eMode == OvrControllerBehavior2.OvrControllerMode.DANCE; } set { this.m_bHandDanceMode = value; if (value) { this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.DANCE); } else if (!value) { if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN) { this.m_eModeBack = OvrControllerBehavior2.OvrControllerMode.HAND; } else if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.DANCE) { this.m_eModeBack = OvrControllerBehavior2.OvrControllerMode.HAND; this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.HAND); } } } } public override bool HandVRIKMode { get { return this.m_bHandVRIKMode; } set { this.m_bHandVRIKMode = value; if (value) { this.m_bModeHide[5] = false; this.m_bModeHide[6] = false; this.m_bModeHide[7] = false; this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.VRIK_FACE); } else if (!value) { if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN) { this.m_eModeBack = OvrControllerBehavior2.OvrControllerMode.HAND; } else if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.VRIK_FACE) { this.m_eModeBack = OvrControllerBehavior2.OvrControllerMode.HAND; this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.HAND); } this.m_bModeHide[5] = true; this.m_bModeHide[6] = true; this.m_bModeHide[7] = true; } } } public override bool HandYotogiMode { get { return this.m_bHandYotogiMode && this.m_eMode == OvrControllerBehavior2.OvrControllerMode.YOTOGI; } set { this.m_bHandYotogiMode = value; if (value) { this.m_bModeHide[8] = false; this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.YOTOGI); } else if (!value) { if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN) { this.m_eModeBack = OvrControllerBehavior2.OvrControllerMode.HAND; } else if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.YOTOGI) { this.m_eModeBack = OvrControllerBehavior2.OvrControllerMode.HAND; this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.HAND); } this.m_bModeHide[8] = true; } } } protected override void Awake() { base.Awake(); NDebug.Assert(this.m_Pair != null, "Pairコントローラがありません。"); 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(); this.m_goModeCanvas = this.m_txMode.transform.parent.gameObject; this.m_goHandCamera = base.transform.Find("HandCamera").gameObject; this.m_HandCamera = this.m_goHandCamera.GetComponent(); this.m_HandCamera.m_ctrl = this; this.m_goHandModel = base.transform.Find("HandPlayer").gameObject; this.m_HandAnim = this.m_goHandModel.GetComponent(); NDebug.Assert(this.m_HandAnim != null); this.m_HandAnim.Init(this.m_buttons); this.m_HandItem = base.transform.Find("HandItem").GetComponent(); this.m_HandItem.m_ctrl = this; this.m_HandItem.SetButtons(this.m_buttons); this.m_HandItem.gameObject.SetActive(false); this.m_ArcTeleport = base.transform.Find("ArcTeleport").GetComponentInChildren(true); this.m_ArcTeleport.SetCallBackOnMove(new ArcTeleport.dgOnMove(this.OnWarpMove)); this.m_fCursorLaserEasing = GameMain.Instance.CMSystem.OvrViveCursorLaserEasing; this.m_trTabletPenRoot = base.transform.Find("UIRay"); NDebug.Assert(this.m_trTabletPenRoot != null, "UIRayが見つかりません。"); this.m_goTabletPen = base.transform.Find("UIRay/Odogu_Styluspen_red").gameObject; NDebug.Assert(this.m_goTabletPen != null, "UI用タブレットペンモデルが見つかりません。"); OvrUIPen component = this.m_goTabletPen.GetComponent(); if (component != null) { component.m_ctrl = this; } this.m_bIsInit = true; } private void Start() { GameMain.Instance.OvrMgr.OvrCamera.m_bWheelToZoom = false; this.ChangeMode(this.m_eMode); } private void OnEnable() { this.m_trTabletPenRoot.gameObject.SetActive(true); this.ChangeMode(this.m_eMode); } private void OnDisable() { this.m_trTabletPenRoot.gameObject.SetActive(false); this.m_goTabletPen.SetActive(false); } private void ChangeMode(OvrControllerBehavior2.OvrControllerMode f_eNewMode) { if (this.m_bIsInit) { bool active = false; bool enabled = false; bool active2 = false; bool flag = false; bool enabled2 = true; bool active3 = false; bool isEnableHandUI = false; bool isEnableHandUI2 = false; bool isEnableHandUI3 = false; if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.HAND || f_eNewMode == OvrControllerBehavior2.OvrControllerMode.YOTOGI) { enabled = true; active = this.m_bHandModelVisible; } if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.CAMERA) { active2 = true; enabled2 = false; } if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.PEN) { enabled = true; flag = true; } if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.ITEM) { active3 = true; } if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.VRIK_FACE) { enabled = true; isEnableHandUI = true; } if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.VRIK_HAND) { enabled = true; isEnableHandUI2 = true; } if (f_eNewMode == OvrControllerBehavior2.OvrControllerMode.VRIK_OTHER) { enabled = true; isEnableHandUI3 = true; } PhotoFaceDataShortcutParent componentInChildren = base.gameObject.GetComponentInChildren(); if (componentInChildren != null) { componentInChildren.isEnableHandUI = isEnableHandUI; } HandSignShortcut componentInChildren2 = base.gameObject.GetComponentInChildren(); if (componentInChildren2 != null) { componentInChildren2.isEnableHandUI = isEnableHandUI2; } OtherCommandShortcut componentInChildren3 = base.gameObject.GetComponentInChildren(); if (componentInChildren3 != null) { componentInChildren3.isEnableHandUI = isEnableHandUI3; } this.m_goHandModel.SetActive(active); this.m_obj_controller.grip_collider.enabled = enabled; this.m_goHandCamera.SetActive(active2); this.m_goTabletPen.SetActive(flag); this.m_controller.UIRayEnable = flag; this.m_HandItem.gameObject.SetActive(active3); GameMain.Instance.OvrMgr.SystemUICamera.SetActiveVirtualCursorObjByNocurrent((!this.m_bHandL) ? UICamera.VCURSOR.RIGHT : UICamera.VCURSOR.LEFT, flag); this.m_txMode.enabled = enabled2; this.m_txMode.text = this.m_strMode[(int)f_eNewMode]; } this.m_eMode = f_eNewMode; } private void ChangePointerMode(OvrControllerBehavior2.PointerSubMode f_ePMode) { this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.HAND); } private void ChangeMoveMode(OvrControllerBehavior2.MoveSubMode f_eSubMode) { this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.HAND); } 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 { GameMain.Instance.OvrMgr.OvrCamera.m_bRightClickUIToggle = false; 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); } public bool IsGrabTablet() { return this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN && this.m_buttons.GetPress(AVRControllerButtons.BTN.VIRTUAL_GRUB); } private void TabletSizeChange() { if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN) { if (this.m_Pair.IsGrabTablet()) { if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_GRUB)) { this.m_fOtherDistanceOne = Vector3.Distance(this.m_Pair.transform.position, base.transform.position); this.m_fTabletScaleBef = GameMain.Instance.OvrMgr.OvrCamera.OvrTablet.Size; this.m_bTabletScaleGrab = true; } else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.VIRTUAL_GRUB)) { if (this.m_bTabletScaleGrab) { float num = Vector3.Distance(this.m_Pair.transform.position, base.transform.position) / this.m_fOtherDistanceOne; GameMain.Instance.OvrMgr.OvrCamera.OvrTablet.Size = this.m_fTabletScaleBef * num; } } else { this.m_bTabletScaleGrab = false; } } else { this.m_bTabletScaleGrab = false; } } else { this.m_bTabletScaleGrab = false; } } protected override void Update() { GameMain.Instance.OvrMgr.OvrCamera.m_bRightClickUIToggle = true; if (OvrIK.IsModeVRIK) { if (this.m_goModeCanvas.layer != 17) { this.m_goModeCanvas.layer = 17; } } else if (this.m_goModeCanvas.layer != 0) { this.m_goModeCanvas.layer = 0; } 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)); this.m_fCamRotNow = 0f; if (!this.m_controller.HandEnable) { return; } 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 != OvrControllerBehavior2.OvrControllerMode.HAND) { if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.CAMERA) { } } this.m_bPressMenuBtnLong = true; } } else if (this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_MENU)) { if (!this.m_bPressMenuBtnLong && this.HandLimitMode != AVRControllerBehavior.LIMIT_MODE.HAND_ONLY) { int num = (int)this.m_eMode; do { num++; if (9 <= num) { num = 0; } } while (this.m_bModeHide[num] || (num == 3 && !this.m_bHandDanceMode)); this.ChangeMode((OvrControllerBehavior2.OvrControllerMode)num); this.m_eModeBack = this.m_eMode; } } else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.MENU) && this.m_buttons.GetPressUp(AVRControllerButtons.BTN.GRIP)) { GameMain.Instance.OvrMgr.OvrCamera.ReCallcOffset(); GameMain.Instance.OvrMgr.OvrCamera.ShowUI(true); GameMain.Instance.OvrMgr.OvrCamera.UIPosReset(0f); } this.m_bTabletArea = GameMain.Instance.OvrMgr.OvrCamera.OvrTablet.IsHitPointerArea(base.transform.position); if (this.m_bTabletArea && !this.m_ArcTeleport.IsWarpSelecting() && !this.m_bMoveDrawMode && GameMain.Instance.OvrMgr.OvrCamera.IsUIShow) { if (this.m_eMode != OvrControllerBehavior2.OvrControllerMode.PEN) { this.m_eModeBack = this.m_eMode; this.ChangeMode(OvrControllerBehavior2.OvrControllerMode.PEN); } } else if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN) { this.ChangeMode(this.m_eModeBack); } this.TabletSizeChange(); if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.PEN) { RaycastHit raycastHit; if (Physics.Raycast(this.m_controller.UIRayTrans.position, this.m_controller.UIRayTrans.rotation * Vector3.forward, out raycastHit, float.PositiveInfinity, 33554432)) { if (this.m_bCursorMoveEnable) { Vector2 textureCoord = raycastHit.textureCoord; Vector2 a = new Vector2(1280f * (textureCoord.x / 1f), 720f * (textureCoord.y / 1f)); 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); } this.TouchPadToClick(); this.TouchPadWheel(); } Debug.DrawLine(this.m_controller.UIRayTrans.position, this.m_controller.UIRayTrans.position + base.transform.rotation * (Vector3.forward * 10f), new Color(1f, 0f, 0f)); } else if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.HAND) { if (GameMain.Instance.CMSystem.SConfig.OvrMoveType == CMSystem.SerializeConfig.OVR_MOVE_TYPE.WARP_DRAW_STEPROT) { if (this.HandLimitMode == AVRControllerBehavior.LIMIT_MODE.HAND_ONLY) { this.m_ArcTeleport.WarpCancel(); this.m_bMoveDrawMode = false; } else { bool flag = false; if (this.HandLimitMode == AVRControllerBehavior.LIMIT_MODE.NO_WARP) { this.m_ArcTeleport.WarpCancel(); flag = true; } if (this.m_buttons.GetPress(AVRControllerButtons.BTN.VIRTUAL_L_CLICK)) { if (!this.m_bMoveDrawMode && !flag) { this.m_ArcTeleport.WarpSelecting(); } if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.TRIGGER)) { this.m_ArcTeleport.WarpCancel(); this.m_bMoveDrawMode = true; } } else { if (!this.m_bMoveDrawMode && !flag) { this.m_ArcTeleport.WarpDicide(); } this.m_bMoveDrawMode = false; } } if (GameMain.Instance.CMSystem.OvrUseSnapRotate) { Vector2 axis = this.m_buttons.GetAxis(); if (axis.x < -(1f - (float)GameMain.Instance.CMSystem.OvrUseSnapRotateRate * 0.01f)) { if (!this.m_bSnapRot) { this.m_fCamRotNow = -30f; this.m_bSnapRot = true; } } else if (1f - (float)GameMain.Instance.CMSystem.OvrUseSnapRotateRate * 0.01f < axis.x) { if (!this.m_bSnapRot) { this.m_fCamRotNow = 30f; this.m_bSnapRot = true; } } else { this.m_bSnapRot = false; } } else { this.m_bSnapRot = false; } } else if (GameMain.Instance.CMSystem.SConfig.OvrMoveType == CMSystem.SerializeConfig.OVR_MOVE_TYPE.DIRECTION && this.HandLimitMode != AVRControllerBehavior.LIMIT_MODE.HAND_ONLY) { Vector2 vector2 = this.m_buttons.GetAxis() * GameMain.Instance.CMSystem.SConfig.OvrMoveDirSpeed; if (this.m_buttons.GetPress(AVRControllerButtons.BTN.TRIGGER) && GameMain.Instance.CMSystem.SConfig.OvrRiftTriggerStickUpDown) { this.m_vMoveCam.y = vector2.y; } else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.GRIP) && GameMain.Instance.CMSystem.SConfig.OvrRiftGripStickRotate) { this.m_fRotCam = vector2.x; } else { this.m_vMoveCam.x = -vector2.x; this.m_vMoveCam.z = vector2.y; } } } else if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.CAMERA && this.m_buttons.GetPressDown(AVRControllerButtons.BTN.TRIGGER)) { this.m_HandCamera.Snap(); } if (this.m_eMode != OvrControllerBehavior2.OvrControllerMode.HAND) { this.m_bSnapRot = false; } if (this.m_buttons.GetPress(AVRControllerButtons.BTN.STICK_PAD)) { this.m_fGripTime += Time.deltaTime; if (this.m_fGripTime >= 1f && !this.m_bGripDown) { GameMain.Instance.OvrMgr.OvrCamera.ShowUI(true); GameMain.Instance.OvrMgr.OvrCamera.UIPosReset(0f); this.m_bGripDown = true; } } else if (this.m_buttons.GetPressUp(AVRControllerButtons.BTN.STICK_PAD)) { if (!this.m_bGripDown && this.m_eMode != OvrControllerBehavior2.OvrControllerMode.PEN) { GameMain.Instance.OvrMgr.OvrCamera.ToggleUI(); } this.m_bGripDown = false; this.m_fGripTime = 0f; } } public override Vector3 GetVelocityHand() { Vector3 result = default(Vector3); if (this.m_eMode == OvrControllerBehavior2.OvrControllerMode.HAND && this.HandLimitMode != AVRControllerBehavior.LIMIT_MODE.HAND_ONLY && !GameMain.Instance.MainCamera.IsFadeOut()) { if (!this.m_bPressTrigger && this.m_buttons.GetPressDown(AVRControllerButtons.BTN.TRIGGER)) { this.m_vMoveTugPosBack = base.transform.position; this.m_bPressTrigger = true; } else if (this.m_bPressTrigger && this.m_buttons.GetPress(AVRControllerButtons.BTN.TRIGGER)) { if (this.m_bMoveDrawMode) { if (this.m_goTestObj != null) { this.m_goTestObj.transform.position = base.transform.position; } Vector3 a = base.transform.position - this.m_vMoveTugPosBack; result = a * -1f; } } else { this.m_bPressTrigger = false; } } else { this.m_bPressTrigger = false; } return result; } public override float GetRotHandY() { return this.m_fCamRotNow; } protected override void LateUpdate() { } public OvrControllerBehavior2 m_Pair; private readonly string[] m_strMode = new string[] { "HAND", "CAMERA", "PEN", "DANCE", string.Empty, string.Empty, string.Empty, string.Empty, "COMMAND" }; private bool[] m_bModeHide = new bool[] { false, false, true, false, false, true, true, true, true }; private readonly string[] m_strPointerMode = new string[] { "-LASER" }; private readonly string[] m_strMoveMode = new string[] { "-DIR", "-DRAW", "-ARC" }; [NonSerialized] private OvrControllerBehavior2.OvrControllerMode m_eMode; private OvrControllerBehavior2.OvrControllerMode m_eModeBack; private bool m_bArcNow; private float m_fGripTime; private bool m_bGripDown; private bool m_bMoveDrawMode; private bool m_bTabletArea; private float m_fTabletScaleBef; private float m_fOtherDistanceOne; private bool m_bTabletScaleGrab; private bool m_bIsInit; private bool m_bPressTrigger; private bool m_bSnapRot; private float m_fCamRotNow; private enum OvrControllerMode { HAND, CAMERA, PEN, DANCE, ITEM, VRIK_FACE, VRIK_HAND, VRIK_OTHER, YOTOGI, MAX } private enum PointerSubMode { LASER, MAX } private enum MoveSubMode { DIRECTIONAL, DRAW, ARC, MAX } private enum TouchSubMode { MAN, WOMAN } }