예제 #1
0
    /// <summary>
    /// Get closest object for interaction
    /// </summary>
    private void GetInteractingObject()
    {
        float minDistance = float.MaxValue;

        float distance;

        foreach (h_InteractableObject obj in this._ObjectsHoveringOver)
        {
            if (obj == null)
            {
                continue;
            }

            distance = (obj.transform.position - transform.position).sqrMagnitude;

            if (distance < minDistance)
            {
                this._ClosestObject = obj;
                minDistance         = distance;
            }
        }

        this._InteractingObject = this._ClosestObject;
        this._ClosestObject     = null;

        if (this._InteractingObject != null)
        {
            if (this._InteractingObject.IsInteracting)
            {
                this._InteractingObject.EndInteration(this);
            }

            this._InteractingObject.StartInteraction(this);
        }
    }
예제 #2
0
    public void OnTriggerExit(Collider collider)
    {
        h_InteractableObject collidedObject = collider.GetComponent <h_InteractableObject>();

        if (collidedObject)
        {
            this._ObjectsHoveringOver.Remove(collidedObject);
        }
    }
예제 #3
0
    /// <summary>
    /// Update
    /// </summary>
    void Update()
    {
        // Make sure there's controller
        if (this._ControllerIndex == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        if (this._ControllerIndex.GetPressDown(EVRButtonId.k_EButton_Grip))
        {
            this.GetInteractingObject();
            //Debug.Log(string.Format("IsInteracting with {0}", this._InteractingObject.name));
        }

        if (this._ControllerIndex.GetPressUp(EVRButtonId.k_EButton_Grip) && this._InteractingObject != null)
        {
            this._InteractingObject.EndInteration(this);
            this._InteractingObject = null;
        }
    }