private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; m_CurrentlySelectedObject = hit.transform.gameObject; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; m_CurrentlySelectedObject = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
protected void HandleOver(VRInteractiveItem interactible) { interactible.Over(); if (m_LastInteractible == null) { OnOverSomething?.Invoke(interactible); } }
protected override void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } EyeRaycastHit raycastHit; // Do the raycast forwards to see if we hit an interactive item if (GetInteractiveItem(out raycastHit)) { //VRInteractiveItem interactible = hit.collider.GetComponent<VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object VRInteractiveItem interactible = raycastHit.item; m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(raycastHit.point, raycastHit.distance, raycastHit.normal); } if (raycastHit.hasHit) { InvokeOnRaycastHitEvent(raycastHit.hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
/*void OnGUI() * { * GUI.Label(new Rect(10,10,500,20), "Screen: " + Screen.width + "x" + Screen.height); * GUI.Label(new Rect(10,30,500,20), "Mouse: " + Input.mousePosition.ToString("F3")); * }*/ private void MouseRaycast() { // Create a ray that points forwards from the camera. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
void ProcessRaycastHits(RaycastHit [] hits, Vector3 worldStartPoint, out Vector3 worldEndPoint) { VRInteractiveItem interactible = null; RaycastHit hit = hits[0]; float closestInteractive = Mathf.Infinity; for (int i = 0; i < hits.Length; i++) { if (hits[i].distance < closestInteractive) { closestInteractive = hits[i].distance; interactible = hits[i].collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object hit = hits[i]; } } #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { print(hit.transform.name); } #endif m_CurrentInteractible = interactible; worldEndPoint = hit.point; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } OnRaycasthit?.Invoke(hit); }
private IEnumerator FillCircle(VRInteractiveItem target, float loadingTime) { // When the circle starts to fill, reset the timer. float timer = 0f; circle.fillAmount = 0f; while (timer < loadingTime) { if (m_LastInteractible != null && target.name != m_LastInteractible.name) { yield break; } timer += Time.deltaTime; circle.fillAmount = timer / loadingTime; yield return(null); } circle.fillAmount = 1f; target.Over(); ResetGazer(); }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; Vector3 worldStartPoint = Vector3.zero; Vector3 worldEndPoint = Vector3.zero; if (m_LineRenderer != null) { m_LineRenderer.enabled = ControllerIsConnected && ShowLineRenderer; } if (ControllerIsConnected && m_TrackingSpace != null) { Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * 500.0f); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Create new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); } // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object if (interactible) { worldEndPoint = hit.point; } m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(ray.origin, ray.direction); } } if (ControllerIsConnected && m_LineRenderer != null) { m_LineRenderer.SetPosition(0, worldStartPoint); m_LineRenderer.SetPosition(1, worldEndPoint); } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Modified Scripts (Inserting laser into the controller) Vector3 worldStartPoint = Vector3.zero; Vector3 worldEndPoint = Vector3.zero; if (m_LineRenderer != null) { m_LineRenderer.enabled = ControllerIsConnected && ShowLineRenderer; } if (ControllerIsConnected && m_TrackingSpace != null) { // Matrix4x4 calculates the arbitrary linear in 3D transformations // Creating a variable localToWorld and assign it to m_TrackingSpace Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); //localStartPoint variable is assigned to the controllers position //To get localEndPoint, you add the localStartPoint to the orientation and multiple the orientation the to forward function and add the distant float Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * 50.0f); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Creates a new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); } //------------------------------------------------------------------------------------------------------------------------------// // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); // Attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } // Modified to get the end point and equate it to the hit.point if (interactible) { worldEndPoint = hit.point; } m_CurrentInteractible = interactible; } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(ray.origin, ray.direction); } } // If the controller is connected and the line renderer is not nulled then it would find the start position and end position if (ControllerIsConnected && m_LineRenderer != null) { m_LineRenderer.SetPosition(0, worldStartPoint); m_LineRenderer.SetPosition(1, worldEndPoint); } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; RaycastHit [] hits; VRInteractiveItem cInteractable = null; int hitIndex = -1; hits = Physics.RaycastAll(ray); foreach (RaycastHit hitDash in hits) { hitIndex++; VRInteractiveItem interactible = hitDash.collider.GetComponent <VRInteractiveItem>(); if (interactible != null) { cInteractable = interactible; if (cInteractable.tag.Contains("Button") || cInteractable.tag.Contains("Inner")) { break; } } } // Do the raycast forweards to see if we hit an interactive item if (cInteractable != null) { VRInteractiveItem interactible = cInteractable; m_CurrentInteractible = interactible; //Debug.Log ("GFX: VREyeRaycaster:" + interactible.transform.name); float timerDuation = 4.0f; float peakFactor = 0.25f; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { //Debug.Log ("VREyeRaycaster:" + interactible.transform.name); if (interactible != null && interactible.transform.tag.Contains("Button")) { m_LastInteractible = interactible; if (interactible.tag.Contains("ButtonWord")) { StartCoroutine(FillCircle(interactible, timerDuation * peakFactor)); } else { StartCoroutine(FillCircle(interactible, timerDuation)); } } else { ResetGazer(); interactible.Over(); } } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hits[hitIndex]); } if (OnRaycasthit != null) { OnRaycasthit(hits[hitIndex]); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; ResetGazer(); // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; if (hit.collider.gameObject.name == "Social") { hit_object = 1; Debug.Log("Social_Click"); } else if (hit.collider.gameObject.name == "Dongsan") { hit_object = 2; Debug.Log("Dongsan_Click"); } else if (hit.collider.gameObject.name == "play") { hit_object = 3; Debug.Log("play"); } else { hit_object = 0; } // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); m_VrInput.Input_lay = true; } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { //layTime += Time.deltaTime; m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; hit_object = 0; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, directionObject.position * m_DebugRayLength, Color.blue); } //Debug.Log(m_CurrentInteractible); // Create a ray that points forwards from the camera. // Ray ray = new Ray(m_Camera.position, m_Camera.forward); Ray ray = new Ray(m_Camera.position, directionObject.position * m_DebugRayLength); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object if (!m_DragingFlag) { m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.setAutoClickTime(autoClickTime); interactible.Over(); m_Reticle.fillInTime(autoClickTime); } } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. Vector3 moveVector = (Vector3.right * Input.GetAxis("Horizontal") + Vector3.up * Input.GetAxis("Vertical")); Vector3 rectPosition = m_Camera.forward * 5f; if (m_Reticle) { m_Reticle.SetPosition(directionObject.position); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { // Debug.Log (hit.collider.tag + "on:" + masterscript.GetComponent<MasterControls> ().on); VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (hit.collider.tag != "Finish" && hit.collider.tag != "Startcube") { masterscript.GetComponent <MasterControls> ().on = false; masterscript.GetComponent <MasterControls> ().onstartcube = false; //Debug.Log ("COLLIDER TAG IS NOT FINISH"); } if (hit.collider.tag == " startcube") { Debug.Log("startcube"); interactible.Over(); masterscript.GetComponent <MasterControls> ().onstartcube = true; } if (interactible && interactible != m_LastInteractible) { if (hit.collider.tag == "Finish") { //Debug.Log ("COLLIDER TAG IS FINISH " + "hit : " + hit.collider.name); masterscript.GetComponent <MasterControls> ().on = true; masterscript.GetComponent <MasterControls> ().currentroach = hit.collider.name; interactible.Over(); } else { } } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; masterscript.GetComponent <MasterControls> ().on = false; masterscript.GetComponent <MasterControls> ().onstartcube = false; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required //Debug.Log("EyeRaycast"); if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.red, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); // ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; /// // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { //Debug.Log("EyeRaycast Physics.Raycast we hit an interactive item"); VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { Debug.Log("interactible Over : " + interactible.name); interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { //Debug.Log("EyeRaycast PhysicsHandleDownRaycast Nothing was hit, deactive the last interactive item"); // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; //make the item interactable //create a point on the area in which there is an intersection between the ray and the object GameObject heat = Instantiate(heatTex[0], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; if (Input.GetKeyDown("s")) { GameObject[] heat2 = GameObject.FindGameObjectsWithTag("EYE"); for (int i = 0; i < 500000000; i++) { heat2[i].GetComponent <MeshRenderer>().material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 1.0f)); } } /* if (Input.GetKeyDown("t")) * { * GameObject[] heat2 = GameObject.FindGameObjectsWithTag("EYE"); * for (int i = 0; i < 500000000; i++) * heat2[i].GetComponent<MeshRenderer>().material.SetColor("_Color", new Color(1.0f, 0.0f, 0.0f, 0.0f)); * }*/ //If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } //Debug.Log("here"); } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }