예제 #1
0
    public void TryGrab()
    {
        if (grabbingObject != null)
        {
            Debug.Log("Somehow grabbed something while already grabbing something else. Calling ReleaseGrab on that object.");
            ReleaseGrab();
        }

        if (hoveringObject == null)
        {
            return;
        }

        IXRGrabbable newgrab = hoveringObject.GetTransform().GetComponent <IXRGrabbable>();

        if (newgrab == null)
        {
            return;
        }

        if (!Equals(hoveringObject, null))
        {
            hoveringObject.OnHoverEnd();
        }
        hoveringObject = null;

        newgrab.OnGrabStart(transform);
        grabbingObject = newgrab;

        PlaySoundIfValid(grabStartSound);
    }
예제 #2
0
    private void CheckHovers()
    {
        //If we're grabbing something, we shouldn't be hovering over anything.
        if (grabbingObject != null)
        {
            if (hoveringObject != null)
            {
                if (!Equals(hoveringObject, null))
                {
                    hoveringObject.OnHoverEnd();
                }
                hoveringObject = null;
            }
            return;
        }


        float        nearestdist = Mathf.Infinity;
        IXRHoverable newhover    = null;

        foreach (IXRHoverable hover in collidingHoverables)
        {
            float dist = Vector3.Distance(transform.position, hover.GetTransform().position);
            if (dist < nearestdist)
            {
                newhover = hover;
            }
        }

        if (hoveringObject != newhover)
        {
            if (hoveringObject != null && !hoveringObject.Equals(null))
            {
                hoveringObject.OnHoverEnd();
            }
            if (newhover != null)
            {
                PlaySoundIfValid(hoverStartSound);
                newhover.OnHoverStart();
            }

            hoveringObject = newhover;
        }
    }
예제 #3
0
    private void OnDisable()
    {
        if (hoveringObject != null)
        {
            if (!Equals(hoveringObject, null))
            {
                hoveringObject.OnHoverEnd();
            }
            hoveringObject = null;
        }

        if (grabbingObject != null)
        {
            grabbingObject.OnGrabEnd();
            grabbingObject = null;
        }

        collidingHoverables.Clear();
        collidingGrabbables.Clear();
        collidingClickables.Clear();
    }
예제 #4
0
    private void OnTriggerExit(Collider collision)
    {
        IXRHoverable newhoverable = collision.gameObject.GetComponent <IXRHoverable>();

        if (newhoverable != null && collidingHoverables.Contains(newhoverable))
        {
            collidingHoverables.Remove(newhoverable);
        }

        IXRClickable newclickable = collision.gameObject.GetComponent <IXRClickable>();

        if (newclickable != null && collidingClickables.Contains(newclickable))
        {
            collidingClickables.Remove(newclickable);
        }

        IXRGrabbable newgrabbable = collision.gameObject.GetComponent <IXRGrabbable>();

        if (newgrabbable != null && collidingGrabbables.Contains(newgrabbable))
        {
            collidingGrabbables.Remove(newgrabbable);
        }
    }