void Start() { m_CurrentInteractible = GetComponent <VRInteractiveItem>(); m_CurrentInteractible.OnOver += HandleOver; m_CurrentInteractible.OnOut += HandleOut; m_SelectionRadial.OnSelectionComplete += HandleSelectionComplete; }
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(); } } }
private void DeactiveLastInteractible() { if (m_LastInteractible == null) return; m_LastInteractible.Out(); m_LastInteractible = null; }
protected void HandleOver(VRInteractiveItem interactible) { interactible.Over(); if (m_LastInteractible == null) { OnOverSomething?.Invoke(interactible); } }
protected void HandleOut(VRInteractiveItem interactible) { interactible.Out(); if (m_CurrentInteractible == null) { OnOutOfEverything?.Invoke(interactible); } }
private bool m_IsEnding; // Whether the target is currently being removed by another source. private void Awake() { // Setup the references. m_CameraTransform = Camera.main.transform; m_Audio = GetComponent<AudioSource> (); m_InteractiveItem = GetComponent<VRInteractiveItem>(); m_Renderer = GetComponent<Renderer>(); m_Collider = GetComponent<Collider>(); }
protected void DeactiveLastInteractible() { if (m_LastInteractible == null) { return; } HandleOut(m_LastInteractible); m_LastInteractible = null; }
private void HandleUp() { if (m_CurrentInteractible != null) { m_CurrentInteractible.Up(); } m_DragingFlag = false; InitialDistanceUpdated = false; m_CurrentSelectedForDrag = null; }
protected void DeactiveLastInteractible() { if (m_LastInteractible == null) { return; } m_LastInteractible.Out(); m_LastInteractible = null; }
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(); } } }
private void DeactiveLastInteractible() { if (m_LastInteractible == null) { return; } m_Reticle.stopFilling(); m_LastInteractible.Out(); m_LastInteractible = null; }
private void DeactiveLastInteractible() { if (m_LastInteractible == null) { return; } m_VrInput.Input_lay = false; m_LastInteractible.Out(); m_LastInteractible = null; }
/*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 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.SphereCast(ray, rayWidth, 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(); } }
private bool m_GazeOver; // Whether the user is looking at the VRInteractiveItem currently. private void OnEnable() { attachedToggle = GetComponent <Toggle>(); if (this.GetComponent <VRInteractiveItem>() != null) { m_InteractiveItem = this.GetComponent <VRInteractiveItem>(); } else { this.gameObject.AddComponent(typeof(VRInteractiveItem)); Debug.Log("Attaching VR Interactive Script to this GameObject, it's required"); m_InteractiveItem = this.GetComponent <VRInteractiveItem>(); } if (this.GetComponent <BoxCollider>() == null) { this.gameObject.AddComponent(typeof(BoxCollider)); GetComponent <BoxCollider>().size = new Vector3(this.GetComponent <RectTransform>().rect.width, this.GetComponent <RectTransform>().rect.height, 1); Debug.Log("Attaching Box collider to this GameObject, it's required"); } if (Camera.main.gameObject.GetComponent <SelectionRadial>() != null) { m_SelectionRadial = Camera.main.gameObject.GetComponent <SelectionRadial>(); } else { Debug.Log("No SelectionRadial Script attached to the VR Interactive Camera, it's required"); } if (gazeTimeForSelection == 0) { gazeTimeForSelection = 1; } m_InteractiveItem.OnOver += HandleOver; m_InteractiveItem.OnOut += HandleOut; m_SelectionRadial.OnSelectionComplete += HandleSelectionComplete; }
private void HandleDrag() { m_DragingFlag = true; if (m_CurrentInteractible != null) { m_CurrentSelectedForDrag = m_CurrentInteractible; } if (m_CurrentSelectedForDrag != null) { if (!InitialDistanceUpdated) { ObjectInitialDistance = Vector3.Distance(m_Camera.position, m_CurrentSelectedForDrag.gameObject.transform.position); } InitialDistanceUpdated = true; Debug.Log(Input.GetAxis("ScaleAxis")); ObjectInitialDistance += Input.GetAxis("MoveFront&Back"); m_CurrentSelectedForDrag.gameObject.transform.localScale = Vector3.Lerp(m_CurrentSelectedForDrag.gameObject.transform.localScale, m_CurrentSelectedForDrag.gameObject.transform.localScale + (Vector3.one * Input.GetAxis("ScaleAxis")), Time.deltaTime / 2f); m_CurrentSelectedForDrag.gameObject.transform.rotation = Quaternion.LookRotation(m_CurrentSelectedForDrag.gameObject.transform.position - Camera.main.transform.position); m_CurrentSelectedForDrag.gameObject.transform.position = Vector3.Lerp(m_CurrentSelectedForDrag.gameObject.transform.position, m_Camera.position + (directionObject.position.normalized * ObjectInitialDistance), Time.deltaTime * 10.0f); } }
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(); }
//This function checks if an object is being interacted with and if the position/transform has changed //significantly enough to warrant packet transmission and sync. 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)) { //set flashlight reference object transform GameObject flashlightObj = transform.Find("Camera Player/pFlashLight").gameObject; flashlightObj.transform.position = hit.point; VRInteractiveItem interactible = hit.collider.GetComponent<VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; //If the object hit by the raycast has a VRInteractiveItem Script, tell that object to get the inventory script from the raycasting player if (interactible != null) { if (currentInteractibleName == "") { lastPosition = interactible.gameObject.transform.position; lastRot = interactible.gameObject.transform.rotation; } currentInteractibleName = interactible.gameObject.name; //For Ryan //This will most likely need a Cmd written for it. Let me test it first -R hit.transform.SendMessage("RetrieveInventoryScript", gameObject); //If there is a manipulate script attached to the object you're looking at, send it the player's inspect point transform if (hit.transform.gameObject.GetComponent<VRStandardAssets.Examples.spt_interactiveItemManipulate>() != null) hit.transform.SendMessage("RetrieveLookPoint", gameObject); } else resetCurrentInter(); // 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); racyCastTouch = true; } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; racyCastTouch = false; // Position the reticle at default distance. if (m_Reticle) m_Reticle.SetPosition(); } }
public void ResetInteractable() { m_CurrentInteractible = null; }
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; Vector3 worldStartPoint; Vector3 worldEndPoint; switch (PlatformManager.Instance.currentVRPlatform) { case VRPlataform.PC: default: worldStartPoint = m_Camera.position; worldEndPoint = worldStartPoint + (worldStartPoint * m_RayLength); ray = new Ray(m_Camera.position, m_Camera.forward); break; case VRPlataform.Oculus: Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * m_RayLength); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Create new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); break; } //first look for UI elements hits = Physics.RaycastAll(ray, m_RayLength, m_UILayers); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { foreach (var item in hits) { print(item.transform.name + "_" + item.distance); } print("_______________________"); } #endif // Do the raycast forwards to see if we hit an interactive item if (hits.Length > 0) { ProcessRaycastHits(hits, worldStartPoint, out worldEndPoint); RenderLine(worldStartPoint, worldEndPoint); return; } //if there is no hit, then look for other colliders hits = Physics.RaycastAll(ray, m_RayLength, ~m_ExclusionLayers); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { foreach (var item in hits) { print(item.transform.name); } print("_______________________"); } #endif // Do the raycast forwards to see if we hit an interactive item if (hits.Length > 0) { ProcessRaycastHits(hits, worldStartPoint, out worldEndPoint); } 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); } } RenderLine(worldStartPoint, worldEndPoint); }
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); } } }
protected void NoHits() { m_CurrentInteractible = null; // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); }
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(); } } }
// Use this for initialization void Start() { if (gazeTimeForSelection == 0) { gazeTimeForSelection = 1; //defaults to 1 } if (this.GetComponent <VRInteractiveItem> () != null) { m_InteractiveItem = this.GetComponent <VRInteractiveItem> (); } else { Debug.Log("Attaching VR Interactive Script to this GameObject, it's required"); this.gameObject.AddComponent(typeof(VRInteractiveItem)); m_InteractiveItem = this.GetComponent <VRInteractiveItem> (); } if (this.GetComponent <BoxCollider>() == null) { this.gameObject.AddComponent(typeof(BoxCollider)); GetComponent <BoxCollider> ().size = new Vector3(this.GetComponent <RectTransform> ().rect.width, this.GetComponent <RectTransform> ().rect.height, 1); Debug.Log("Attaching Box collider to this GameObject, it's required"); } if (this.GetComponent <Scrollbar> () != null) { vScale = this.GetComponent <Scrollbar> (); } else { Debug.Log("No Scrollbar component attached to this GameObject, it's required"); } if (this.GetComponent <Scrollbar>().handleRect.gameObject != null) { sliderHandle = this.GetComponent <Scrollbar>().handleRect.gameObject; } else { Debug.Log("No child Handle (GameObject) attached to this GameObject, it's required"); } if (Camera.main.gameObject.GetComponent <SelectionRadial>() != null) { m_SelectionRadial = Camera.main.gameObject.GetComponent <SelectionRadial>(); } else { Debug.Log("No SelectionRadial Script attached to the VR Interactive Camera, it's required"); } if (Camera.main.gameObject.GetComponent <SelectionRadial>() != null) { reticlePosition = Camera.main.gameObject.GetComponent <Reticle>().ReticleTransform; } else { Debug.Log("No Reticle Script attached to the VR Interactive Camera, it's required with it's references"); } //sliderHandle.SetActive(false); }
private EyeRaycastHit GetGraphicInteractiveItem() { EyeRaycastHit result = new EyeRaycastHit(); result.distance = -1.0f; //EventSystem eventSystem = EventSystem.current; PointerEventData eventData = new PointerEventData(m_EventSystem); //Vector2 position = new Vector2(Screen.width / 2.0f, Screen.height / 2.0f); Vector2 position = m_CameraObject.WorldToScreenPoint(m_Camera.position + m_Camera.forward); //Debug.Log("Raycast Startpoint: " + position + " vs. " + cposition + " vs. " + wposition); eventData.position = position; List <RaycastResult> results = new List <RaycastResult>(); m_EventSystem.RaycastAll(eventData, results); // Check to see if we have an interactive item. if (results.Count > 0) { // Make sure we don't have any duplicates. List <GameObject> resultsObjects = new List <GameObject>(); results.RemoveAll(potentialDuplicate => { bool alreadyContains = resultsObjects.Contains(potentialDuplicate.gameObject); if (!alreadyContains) { resultsObjects.Add(potentialDuplicate.gameObject); } return(alreadyContains); }); /* If so, grab the first one (since it will be the closest item) and remove everything else (since we don't care * about regular UI items if we have an interactive item). This may look super strange, but there's no sense in doubling * back through all of the objects and call GetComponent again (which is expensive) if there is a VRInteractiveItem on * one of them, so I just cache the first one that comes by. */ GameObject firstInteractiveObject = null; bool interactiveItemExists = results.Exists(raycastResult => { VRInteractiveItem item = raycastResult.gameObject.GetComponent <VRInteractiveItem>(); if (item != null && firstInteractiveObject == null) { firstInteractiveObject = raycastResult.gameObject; } return(item != null); }); if (interactiveItemExists) { results.RemoveAll(currentResult => { return(currentResult.gameObject != firstInteractiveObject); }); } } // If we have any results at this point, just grab the first one, and let's go! if (results.Count > 0) { GameObject resultObject = results[0].gameObject; result.item = resultObject.GetComponent <VRInteractiveItem>(); Vector3 worldPosition = m_CameraObject.ScreenToWorldPoint(new Vector3(results[0].screenPosition.x, results[0].screenPosition.y, results[0].distance)); result.point = worldPosition; result.normal = -resultObject.transform.forward; result.distance = results[0].distance; result.gameObject = results[0].gameObject; } return(result); }
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 Awake() { //initialize variables m_InteractiveItem = GetComponent <VRInteractiveItem> (); }
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 Awake() { m_InteractiveItem = GetComponent <VRInteractiveItem>(); m_Selection = (ReferenceManager.Instance).SelectionRadialSlider; }