using UnityEngine; using System.Collections; using UnityEngine.Networking; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections.Generic; public class Argos_VR_Navigate : MonoBehaviour { public float ArrowSpeed = 1f; public float MouseLLnearSpeed = 60f; public float MouseAngularSpeed = 60f; public float damping = 0.1f; public float ReleaseTime = 1.2f; bool bLMButtonisDown = false; bool bRMButtonisDown = false; bool bMMMouseButtonisDown = false; bool bLMButtonWasDown = false; bool bRMButtonWasDown = false; bool bMMMouseButtonWasDown = false; bool bAnyMouseButton = false; float xMouse_Damped; float yMouse_Damped; float[] arrowsDamped = new float[4]; bool[] bArrow = new bool[4]; bool[] bArrowWasDown = new bool[4]; float[] MTimer = new float[3]; float[] ATimer = new float[4]; GameObject argosSphere; //GameObject userMovement; //GameObject NavSphere_Pivot; //GameObject NavSphere; //UI_Control ui_control; public Text txtInputIndicator; Vector2 touchPos; Vector3 vHoldPivot; bool bRotaPivot_On = false; bool m_bAllowInput = true; public RMF_RadialMenu rmf_Radial_Menu; public enum Arrows { UP = 0, DOWN, LEFT, RIGHT, } public static class Arrow { public const int UP = 0; public const int DOWN = 1; public const int LEFT = 2; public const int RIGHT = 3; } public enum MouseButts { LMB, RMB, MMB, } public static class MouseButt { public const int LMB = 0; public const int RMB = 1; public const int MMB = 2; } public Vector3 baseOVR_Pos; public Quaternion baseOVR_Rota; public int iMode_GearVR; public static class GVR_MODE { public const int LMB = 0; public const int RMB = 1; public const int HOME = 2; public const int MMB = 3; } public GameObject OVR_Main_Cam; public float seeX; public float seeY; public void Start() { argosSphere = GameObject.Find("ARGOS_Fibonacci_Second_Generation"); //userMovement = GameObject.Find("User_Movement"); //ui_control = GameObject.Find("UI_Control_Canvas").GetComponent<UI_Control>(); //NavSphere_Pivot = GameObject.Find("NavSphere_Pivot"); //NavSphere = GameObject.Find("Argos_NavSphere"); OVRTouchpad.Create(); OVRTouchpad.TouchHandler += HandleTouchHandler; baseOVR_Pos = OVR_Main_Cam.transform.position; baseOVR_Rota = OVR_Main_Cam.transform.rotation; } void HandleTouchHandler(object sender, System.EventArgs e) { OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e; OVRTouchpad.TouchEvent touchEvent = touchArgs.TouchType; /*if(touchArgs.TouchType == OVRTouchpad.TouchEvent.SingleTap) { //TODO: Insert code here to handle a single tap. Note that there are other TouchTypes you can check for like directional swipes, but double tap is not currently implemented I believe. }*/ switch (touchEvent) { case OVRTouchpad.TouchEvent.SingleTap: txtInputIndicator.text = "SingleTap"; rmf_Radial_Menu.onNavSelect(); TouchPadHandler(); break; case OVRTouchpad.TouchEvent.Left: txtInputIndicator.text = "Left"; break; case OVRTouchpad.TouchEvent.Right: txtInputIndicator.text = "Right"; break; case OVRTouchpad.TouchEvent.Up: txtInputIndicator.text = "Up"; break; case OVRTouchpad.TouchEvent.Down: txtInputIndicator.text = "Down"; break; } } public void onGreenButton() { m_bAllowInput = true; } public void onRedButton() { m_bAllowInput = !m_bAllowInput; } void TouchPadHandler() { if (rmf_Radial_Menu.idxSelected == GVR_MODE.HOME) { OVR_Main_Cam.transform.position = baseOVR_Pos; OVR_Main_Cam.transform.rotation = baseOVR_Rota; } if (rmf_Radial_Menu.idxSelected == GVR_MODE.LMB) { bLMButtonisDown = true; bLMButtonWasDown = true; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } else { bLMButtonisDown = false; } if (rmf_Radial_Menu.idxSelected == GVR_MODE.RMB) { bRMButtonisDown = true; bRMButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } else { bRMButtonisDown = false; } if (rmf_Radial_Menu.idxSelected == GVR_MODE.MMB) { bMMMouseButtonisDown = true; bMMMouseButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; } else { bMMMouseButtonisDown = false; } bAnyMouseButton = bLMButtonisDown || bRMButtonisDown || bMMMouseButtonisDown || Input.GetKey("right ctrl") || Input.GetKey("e"); } void checkMouseButts() { if (Input.GetMouseButtonDown(0)) { bLMButtonisDown = true; bLMButtonWasDown = true; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } if (Input.GetMouseButtonUp(0)) { bLMButtonisDown = false; } if (Input.GetMouseButtonDown(1)) { bRMButtonisDown = true; bRMButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } if (Input.GetMouseButtonUp(1)) { bRMButtonisDown = false; } if (Input.GetMouseButtonDown(2)) { bMMMouseButtonisDown = true; bMMMouseButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; } if (Input.GetMouseButtonUp(2)) { bMMMouseButtonisDown = false; } bAnyMouseButton = bLMButtonisDown || bRMButtonisDown || bMMMouseButtonisDown || Input.GetKey("right ctrl") || Input.GetKey("e"); } void Update() { //test OVR single tap if(Input.GetMouseButtonDown(0)) { rmf_Radial_Menu.onNavSelect(); } iMode_GearVR = rmf_Radial_Menu.idxSelected; MouseHandler(); if (!EventSystem.current.IsPointerOverGameObject()) { //NavSphere_Pivot.transform.position = transform.position; //if(ui_control.isLocked_NavSpheretoCam) //{ // NavSphere_Pivot.transform.rotation = transform.rotation; //} } //if (Input.touchCount > 0) //{ // if (Input.GetTouch(0).phase == TouchPhase.Began) // { // PointerEventData ped = new PointerEventData(null); // ped.position = Input.GetTouch(0).position; // List<RaycastResult> results = new List<RaycastResult>(); // GR.Raycast(ped, results); // if (results.Count == 0) // { // } // } //} } void MouseHandler() { //checkMouseButts(); float x = GearVRInput.GetAxisX; float y = GearVRInput.GetAxisY; seeX = x; seeY = y; if (bAnyMouseButton) { xMouse_Damped = Mathf.Lerp(xMouse_Damped, x, damping); yMouse_Damped = Mathf.Lerp(yMouse_Damped, y, damping); //MTimer[MouseButt.LMB] = MTimer[MouseButt.RMB] = MTimer[MouseButt.MMB] = 0f; } else { xMouse_Damped = Mathf.Lerp(xMouse_Damped, 0f, damping); yMouse_Damped = Mathf.Lerp(yMouse_Damped, 0f, damping); } float xMD_TimeScaled_AngVel = xMouse_Damped * MouseAngularSpeed * Time.deltaTime; float yMD_TimeScaled_AngVel = yMouse_Damped * MouseAngularSpeed * Time.deltaTime; float xMD_TimeScaled_LinVel = xMouse_Damped * MouseLLnearSpeed * Time.deltaTime; float yMD_TimeScaled_LinVel = yMouse_Damped * MouseLLnearSpeed * Time.deltaTime; //bArrow[Arrow.UP] = Input.GetKey(KeyCode.UpArrow); //bArrow[Arrow.DOWN] = Input.GetKey(KeyCode.DownArrow); //bArrow[Arrow.LEFT] = Input.GetKey(KeyCode.LeftArrow); //bArrow[Arrow.RIGHT] = Input.GetKey(KeyCode.RightArrow); //arrowsDamped[Arrow.UP] = Mathf.Lerp(arrowsDamped[Arrow.UP], ArrowSpeed*(bArrow[Arrow.UP] ?1f:0f), damping); //arrowsDamped[Arrow.DOWN] = Mathf.Lerp(arrowsDamped[Arrow.DOWN], ArrowSpeed * (bArrow[Arrow.DOWN] ? 1f : 0f), damping); //arrowsDamped[Arrow.LEFT] = Mathf.Lerp(arrowsDamped[Arrow.LEFT], ArrowSpeed * (bArrow[Arrow.LEFT] ? 1f : 0f), damping); //arrowsDamped[Arrow.RIGHT] = Mathf.Lerp(arrowsDamped[Arrow.RIGHT], ArrowSpeed * (bArrow[Arrow.RIGHT] ? 1f : 0f), damping); for (int i = 0; i<4; i++) { if (bArrow[i]) { if (ATimer[i] > 0.0f) { bArrowWasDown[i] = false; ATimer[i] = 0f; } else { bArrowWasDown[i] = true; } } } if (bLMButtonisDown || bLMButtonWasDown) { OVR_Main_Cam.transform.Translate(0, -yMD_TimeScaled_LinVel, xMD_TimeScaled_LinVel); if (!bLMButtonisDown) { MTimer[MouseButt.LMB] += Time.deltaTime; if (MTimer[MouseButt.LMB] > ReleaseTime) { MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; } } } if (bRMButtonisDown || bRMButtonWasDown) { OVR_Main_Cam.transform.Translate(-xMD_TimeScaled_LinVel, -yMD_TimeScaled_LinVel, 0); if (!bRMButtonisDown) { MTimer[MouseButt.RMB] += Time.deltaTime; if (MTimer[MouseButt.RMB] > ReleaseTime) { MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; } } } if (bMMMouseButtonisDown || bMMMouseButtonWasDown) { OVR_Main_Cam.transform.Translate(0, 0, yMD_TimeScaled_LinVel); OVR_Main_Cam.transform.RotateAround(argosSphere.transform.position, OVR_Main_Cam.transform.up, xMD_TimeScaled_AngVel); if (!bMMMouseButtonisDown) { MTimer[MouseButt.MMB] += Time.deltaTime; if (MTimer[MouseButt.MMB] > ReleaseTime) { MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } } } if (Input.GetKey("right ctrl") || Input.GetKey("left ctrl")) { //if (!bRotaPivot_On) //{ // vHoldPivot = userMovement.GetComponent<UserMovement>().getCursorPostiion() + argosSphere.transform.position; // bRotaPivot_On = true; //} OVR_Main_Cam.transform.RotateAround(vHoldPivot, OVR_Main_Cam.transform.up, xMD_TimeScaled_AngVel); OVR_Main_Cam.transform.RotateAround(vHoldPivot, OVR_Main_Cam.transform.right, yMD_TimeScaled_AngVel); return; } else { bRotaPivot_On = false; } if (Input.GetKey("e")) { Vector3 pos = argosSphere.transform.position; OVR_Main_Cam.transform.RotateAround(pos, OVR_Main_Cam.transform.up, xMD_TimeScaled_AngVel); OVR_Main_Cam.transform.RotateAround(pos, transform.right, -yMD_TimeScaled_AngVel); return; } if (bArrow[Arrow.UP] || bArrowWasDown[Arrow.UP]) { //transform.Translate(0,arrowsDamped[Arrow.UP]*Time.deltaTime, 0); Vector3 pos = argosSphere.transform.position; //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.right, -arrowsDamped[Arrow.UP] * Time.deltaTime); //} //else //{ OVR_Main_Cam.transform.RotateAround(pos, transform.right, -arrowsDamped[Arrow.UP] * Time.deltaTime); //} if (!bArrow[Arrow.UP]) { ATimer[Arrow.UP] += Time.deltaTime; if (ATimer[Arrow.UP] > ReleaseTime) { ATimer[Arrow.UP] = 0f; bArrowWasDown[Arrow.UP] = false; } } } if (bArrow[Arrow.DOWN] || bArrowWasDown[Arrow.DOWN]) { //transform.Translate(0, -arrowsDamped[Arrow.DOWN] * Time.deltaTime, 0); Vector3 pos = argosSphere.transform.position; transform.RotateAround(pos, transform.right, arrowsDamped[Arrow.DOWN] * Time.deltaTime); //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.right, arrowsDamped[Arrow.DOWN] * Time.deltaTime); //} //else //{ transform.RotateAround(pos, transform.right, arrowsDamped[Arrow.DOWN] * Time.deltaTime); //} if (!bArrow[Arrow.DOWN]) { ATimer[Arrow.DOWN] += Time.deltaTime; if (ATimer[Arrow.DOWN] > ReleaseTime) { ATimer[Arrow.DOWN] = 0f; bArrowWasDown[Arrow.DOWN] = false; } } } if (bArrow[Arrow.LEFT] || bArrowWasDown[Arrow.LEFT]) { //transform.Translate(-arrowsDamped[Arrow.LEFT] * Time.deltaTime, 0, 0); Vector3 pos = argosSphere.transform.position; //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.up, arrowsDamped[Arrow.LEFT] * Time.deltaTime); //} //else //{ transform.RotateAround(pos, transform.up, arrowsDamped[Arrow.LEFT] * Time.deltaTime); //} if (!bArrow[Arrow.LEFT]) { ATimer[Arrow.LEFT] += Time.deltaTime; if (ATimer[Arrow.LEFT] > ReleaseTime) { ATimer[Arrow.LEFT] = 0f; bArrowWasDown[Arrow.LEFT] = false; } } } if (bArrow[Arrow.RIGHT] || bArrowWasDown[Arrow.RIGHT]) { //transform.Translate(arrowsDamped[Arrow.RIGHT] * Time.deltaTime, 0, 0); Vector3 pos = argosSphere.transform.position; transform.RotateAround(pos, transform.up, -arrowsDamped[Arrow.RIGHT] * Time.deltaTime); //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.up, -arrowsDamped[Arrow.RIGHT] * Time.deltaTime); //} //else //{ transform.RotateAround(pos, transform.up, -arrowsDamped[Arrow.RIGHT] * Time.deltaTime); //} if (!bArrow[Arrow.RIGHT]) { ATimer[Arrow.RIGHT] += Time.deltaTime; if (ATimer[Arrow.RIGHT] > ReleaseTime) { ATimer[Arrow.RIGHT] = 0f; bArrowWasDown[Arrow.RIGHT] = false; } } } } }