private Vodget DoRaycast() { Vodget hitVodget = null; // Do a Physics.Raycast starting at the hand_pos in the direction of hand.forward (this.transform.position and this.transform.forward) if (Physics.Raycast(this.transform.position, this.transform.forward, out targetHit, 0.06f) || Physics.Raycast(this.transform.position, this.transform.forward * -1, out targetHit, 0.0001f)) { hitVodget = targetHit.collider.gameObject.GetComponent <Vodget>(); if (hitVodget != null) { // cursor_ball_obj = targetHit.collider.gameObject.transform; cursor_ball_obj.position = targetHit.point; } else { cursor_ball_obj.localPosition = Vector3.zero; } } else { cursor_ball_obj.localPosition = Vector3.zero; } // If a collider is hit, set hitVodget to any vodget component found on the colliders gameObject. // Set hitVodget to null if no vodget is found. // Set the cursor_ball_obj either to the world hit point when hitVodget is found or Vector3.zero if hitVodget was not found. return(hitVodget); }
private Vodget DoRaycast() { Vodget hitVodget = null; // Do a Physics.Raycast starting at the hand_pos in the direction of hand.forward (this.transform.position and this.transform.forward) if (Physics.Raycast(this.transform.position, this.transform.forward, out targetHit, 10.0f)) { hitVodget = targetHit.collider.gameObject.GetComponent <Vodget>(); if (hitVodget != null) { // cursor_ball_obj = targetHit.collider.gameObject.transform; cursor_ball_obj.position = targetHit.point; } else { cursor_ball_obj.localPosition = Vector3.zero; } } else { cursor_ball_obj.localPosition = Vector3.zero; } return(hitVodget); }
private void OnTriggerExit(Collider collision) { if (collision.gameObject.GetComponent <Vodget>() == null) { return; } else { HitVodget = null; } if (focus_grabbed) { this.SendButtonEvent(Selector.ButtonType.Trigger, false); if (focusVodget != null) { focusVodget.Focus(this, false); focusVodget = null; HitVodget = null; } return; } // If exiting the focusVodget (if not null), notify the focusVodget that it has lost focus // Clear the focusVodget. }
// CommonUsage(primary2DAxisClick) private void OnTriggerEnter(Collider collision) { if (focus_grabbed) { return; } if (collision.gameObject.GetComponent <Vodget>() == null) { return; } else { HitVodget = collision.gameObject.GetComponent <Vodget>(); } // A collider was hit. Look for a vodget component on the collision.gameObject! // If no vodget component is found on the collision.gameObject... return. // If focus_grabbed (see Selector base class) is true... return. // Otherwise, focusVodget needs to change. // Let the previous focusVodget know that it has lost focus here (if not null) // Change focusVodget and let the new focusVodget know that it now has selector focus. // Note: When focus is grabbed the collider can still enter and exit other vodgets. // While not a requirement, an advanced implementation would keep track of the vodgets // that are currently entered and exited to potentially choose a new client when // focus grab is released. }
private Vodget DoRaycast() { Vodget hitVodget = null; LEye.transform.LookAt(this.transform.position); if (Physics.Raycast(LEye.transform.position, LEye.transform.forward, out targetHit)) { hitVodget = targetHit.collider.gameObject.GetComponent <Vodget>(); } return(hitVodget); }
//public override void GrabFocus(bool val) //{ // base.GrabFocus(val); // if (val == true) // { // // Note: Most vodgets will grab the selector focus when buttons go down (true) // // Vodgets typical grab focus to guarantee they get the button up (false) event. // // Focus has just been grabbed! // // The initial hit point was found by casting a vector from the hand along the hands forward direction. // // When focus is grabbed save the length of the ray in raylength. // // You can do this by transforming the cursor into the local frame and taking the z (forward) value. // // You could also just get the distance between the hit and current hand points. // } //} private void Update() { // Stop looking for vodgets in the scene when your selectors focus is grabbed. if (!focus_grabbed) { // Use a physics raycast to find vodgets in the scene. Vodget hitVodget = DoRaycast(); // If a vodgets is found, give it focus and begin forwarding any events while it still has focus. if (hitVodget != focusVodget) { // Set your Cursor to the hit point SetCursor(); // Should be good. // Let the previous focusVodgetCurr know that it has lost focus here. if (focusVodget != null) { focusVodget.Focus(this, false); } // Let the focusVodgetCurr know that it now has selector focus here. focusVodget = hitVodget; if (focusVodget != null) { focusVodget.Focus(this, true); } } } // A selector is responsible for giving any vodgets with "focus" a heartbeat by calling FocusUpdate. if (focusVodget != null) { // Set the cursor and call FocusUpdate on focusVodget. SetCursor(); focusVodget.FocusUpdate(this); } }