Exemplo n.º 1
0
        /// <summary>
        /// Find the near avalible grabbable to this controller
        /// </summary>
        /// <returns></returns>
        private VR_Interactable FindNearInteract()
        {
            if (interactList.Count == 0)
            {
                return(null);
            }

            VR_Interactable interact    = null;
            float           minDistance = float.MaxValue;

            for (int n = 0; n < interactList.Count; n++)
            {
                if (interactList[n].enabled && interactList[n].CanInteract && interactList[n].CanInteractUsingController(this))
                {
                    Transform highlightPoint = (ControllerType == VR_ControllerType.Right ? interactList[n].HighlightPointRightHand : interactList[n].HighlightPointLeftHand);

                    if (highlightPoint != null)
                    {
                        float d = (Position - highlightPoint.position).magnitude;

                        if (d < minDistance && d <= interactList[n].InteractDistance)
                        {
                            interact    = interactList[n];
                            minDistance = d;
                        }
                    }
                }
            }


            return(interact);
        }
Exemplo n.º 2
0
        public void InteractWithNearesObject()
        {
            //we have something grabbe we should no interact
            if (currentGrab != null)
            {
                return;
            }
            SetDefaultInteractAnimation();

            //get the near interact object to this controller
            VR_Interactable interact = FindNearInteract();


            if (interact == null && activeDistanceGrabbable != null && (activeDistanceGrabbable != otherController.activeDistanceGrabbable || !ThereIsNearbyControllerInteraction(activeDistanceGrabbable)))
            {
                interact = activeDistanceGrabbable as VR_Interactable;
            }

            if (interact != null && interact.enabled && interact.CanInteractUsingController(this))
            {
                VR_HandInteractSettings settings = interact.GetHandInteractionSettings(this);
                ProcessInteractSettings(settings);
                ProcessInteraction(interact);
            }
        }
Exemplo n.º 3
0
        private void ProcessInteraction(VR_Interactable interact)
        {
            interact.Interact(this);

            if (interact is VR_Grabbable)
            {
                currentGrab = interact as VR_Grabbable;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Remove a grabbable object
        /// </summary>
        /// <param name="grabbable"></param>
        public void RemoveInteract(VR_Interactable interact)
        {
            interactList.Remove(interact);

            //if this is a grabbable to remove it from grabbable list
            if (interact is VR_Grabbable)
            {
                grabbableList.Remove(interact as VR_Grabbable);
            }
        }
        protected virtual void Awake()
        {
            interact = GetComponent <VR_Interactable>();

            if (interact == null)
            {
                Debug.LogError("VR_Hightlight attached to " + gameObject.name + " needs a interactable script in order to work");
            }

            VR_Manager.instance.RegisterHighlight(this);
        }
Exemplo n.º 6
0
        private bool ThereIsNearbyControllerInteraction(VR_Interactable interactable)
        {
            if (!otherController.Input.GetButtonDown(interactable.InteractButton))
            {
                return(false);
            }

            float thisDistance  = CalculateDistanceToInteractable(this, interactable);
            float otherDistance = CalculateDistanceToInteractable(otherController, interactable);

            return(thisDistance > otherDistance);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Register a grabbable object
        /// </summary>
        /// <param name="grabbable"></param>
        public void RegisterInteract(VR_Interactable interact)
        {
            if (interactList.Contains(interact))
            {
                return;
            }

            interactList.Add(interact);

            //is this is a grabbable to lets have it on a diferent list
            if (interact is VR_Grabbable)
            {
                grabbableList.Add(interact as VR_Grabbable);
            }
        }
Exemplo n.º 8
0
 private float CalculateDistanceToInteractable(VR_Controller controller, VR_Interactable interactable)
 {
     return(Vector3.Distance(controller.OriginalParent.position, interactable.transform.position));
 }