示例#1
0
        public static void Deregister(NVRInteractable interactable)
        {
            NVRPlayer.DeregisterInteractable(interactable);

            ColliderMapping = ColliderMapping.Where(mapping => mapping.Value != interactable).ToDictionary(mapping => mapping.Key, mapping => mapping.Value);
            NVRInteractableMapping.Remove(interactable);
        }
示例#2
0
 public static void DeregisterInteractable(NVRInteractable interactable)
 {
     for (int index = 0; index < Instance.Hands.Length; index++)
     {
         Instance.Hands[index].DeregisterInteractable(interactable);
     }
 }
示例#3
0
        public static void Register(NVRInteractable interactable, Collider[] colliders)
        {
            NVRInteractableMapping.Add(interactable, colliders);

            for (int index = 0; index < colliders.Length; index++)
            {
                ColliderMapping.Add(colliders[index], interactable);
            }
        }
示例#4
0
        protected bool PickupClosest()
        {
            NVRInteractable closest         = null;
            float           closestDistance = float.MaxValue;

            foreach (var collider in GhostColliders)
            {
                foreach (var hovering in CurrentlyHoveringOver)
                {
                    if (hovering.Key == null)
                    {
                        continue;
                    }

                    if (!hovering.Key.gameObject.activeInHierarchy)
                    {
                        continue;
                    }

                    var itemColliders = hovering.Value;

                    itemColliders.Where(item => !item.Key.gameObject.activeInHierarchy).ToList().ForEach(item => itemColliders.Remove(item.Key));


                    float distance = Vector3.Distance(collider.transform.position, hovering.Key.transform.position);
                    if (distance < closestDistance)
                    {
                        closestDistance = distance;
                        closest         = hovering.Key;
                    }
                }
            }

            if (closest != null)
            {
                BeginInteraction(closest);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        protected virtual void OnTriggerStay(Collider collider)
        {
            NVRInteractable interactable = NVRInteractables.GetInteractable(collider);

            if (interactable == null || interactable.enabled == false)
            {
                return;
            }

            if (CurrentlyHoveringOver.ContainsKey(interactable) == false)
            {
                CurrentlyHoveringOver[interactable] = new Dictionary <Collider, float>();
            }

            if (CurrentlyHoveringOver[interactable].ContainsKey(collider) == false)
            {
                CurrentlyHoveringOver[interactable][collider] = Time.time;
            }
        }
示例#6
0
        public static void Register(NVRInteractable interactable, Collider[] colliders)
        {
            if (Initialized == false)
            {
                Debug.LogError("[NewtonVR] Error: NVRInteractables.Register called before initialization.");
            }

            NVRInteractableMapping[interactable] = colliders;

            for (int index = 0; index < colliders.Length; index++)
            {
                ColliderMapping[colliders[index]] = interactable;
            }

            if (NVRInteractableList.Contains(interactable) == false)
            {
                NVRInteractableList.Add(interactable);
            }
        }
示例#7
0
        public virtual void BeginInteraction(NVRInteractable interactable)
        {
            if (interactable.CanAttach == true)
            {
                // Implemented hand controller should subscribe to this event and implement appropriate functionality
                OnBeginInteractionCustomHands.Invoke(interactable);

                CurrentlyInteracting = interactable;
                CurrentlyInteracting.BeginInteraction(this);

                if (PhysicalController)
                {
                    PhysicalController.On();        // enable animation with Phyiscal Hand component during interaction
                }

                if (OnBeginInteraction != null)
                {
                    OnBeginInteraction.Invoke(interactable);
                }
            }
        }
示例#8
0
        private void OnTriggerExit(Collider collider)
        {
            NVRInteractable interactable = NVRInteractables.GetInteractable(collider);

            if (interactable == null)
            {
                return;
            }

            if (CurrentlyHoveringOver.ContainsKey(interactable) == true)
            {
                if (CurrentlyHoveringOver[interactable].ContainsKey(collider) == true)
                {
                    CurrentlyHoveringOver[interactable].Remove(collider);
                    if (CurrentlyHoveringOver[interactable].Count == 0)
                    {
                        CurrentlyHoveringOver.Remove(interactable);
                    }
                }
            }
        }
示例#9
0
        protected virtual void OnTriggerExit(Collider collider)
        {
            NVRInteractable interactable = NVRInteractables.GetInteractable(collider);

            if (interactable == null || collider.tag.Equals("Ungrabbable"))
            {
                return;
            }

            if (CurrentlyHoveringOver.ContainsKey(interactable))
            {
                if (CurrentlyHoveringOver[interactable].ContainsKey(collider))
                {
                    CurrentlyHoveringOver[interactable].Remove(collider);
                    if (CurrentlyHoveringOver[interactable].Count == 0)
                    {
                        CurrentlyHoveringOver.Remove(interactable);
                    }
                }
            }
        }
示例#10
0
        public virtual void BeginInteraction(NVRInteractable interactable)
        {
            if (interactable.CanAttach == true)
            {
                if (interactable.AttachedHand != null)
                {
                    if (interactable.AllowTwoHanded == false)
                    {
                        interactable.AttachedHand.EndInteraction(null);
                    }
                }

                CurrentlyInteracting = interactable;
                CurrentlyInteracting.BeginInteraction(this);

                if (OnBeginInteraction != null)
                {
                    OnBeginInteraction.Invoke(interactable);
                }
            }
        }
示例#11
0
        public virtual void EndInteraction(NVRInteractable item)
        {
            if (item != null && CurrentlyHoveringOver.ContainsKey(item) == true)
            {
                CurrentlyHoveringOver.Remove(item);
            }

            if (CurrentlyInteracting != null)
            {
                CurrentlyInteracting.EndInteraction();
                CurrentlyInteracting = null;
            }

            if (CurrentInteractionStyle == InterationStyle.Toggle)
            {
                if (CurrentHandState != HandState.Idle)
                {
                    CurrentHandState = HandState.Idle;
                }
            }
        }
示例#12
0
        public virtual void EndInteraction(NVRInteractable item)
        {
            if (item != null && CurrentlyHoveringOver.ContainsKey(item) == true)
            {
                CurrentlyHoveringOver.Remove(item);
            }

            if (CurrentlyInteracting != null)
            {
                // TODO: A more general event may be better
                ScenarioLogManager.Instance.LogEvent(this.gameObject, "OnRelease", CurrentlyInteracting.gameObject.name);

                CurrentlyInteracting.EndInteraction();
                CurrentlyInteracting = null;
            }

            if (CurrentInteractionStyle == InteractionStyle.GripToggleToInteract)
            {
                if (CurrentHandState != HandState.Idle)
                {
                    CurrentHandState = HandState.Idle;
                }
            }
        }
示例#13
0
        public virtual void EndInteraction(NVRInteractable item)
        {
            if (item != null && CurrentlyHoveringOver.ContainsKey(item) == true)
                CurrentlyHoveringOver.Remove(item);

            if (CurrentlyInteracting != null)
            {
                CurrentlyInteracting.EndInteraction();
                CurrentlyInteracting = null;
            }

            if (CurrentInteractionStyle == InterationStyle.GripToggleToInteract)
            {
                if (CurrentHandState != HandState.Idle)
                {
                    CurrentHandState = HandState.Idle;
                }
            }
        }
示例#14
0
 void SendBeginInteraction(NVRInteractable item)
 {
     NetworkObjectManager.Instance.SendBeginInterraction(item, this);
 }
示例#15
0
        public void DeregisterInteractable(NVRInteractable interactable)
        {
            if (CurrentlyInteracting == interactable)
                CurrentlyInteracting = null;

            CurrentlyHoveringOver.Remove(interactable);
        }
示例#16
0
        public void EndInteraction(NVRInteractable item)
        {
            if (item != null && CurrentlyHoveringOver.ContainsKey(item) == true)
                CurrentlyHoveringOver.Remove(item);

            if (CurrentlyInteracting != null)
            {
                CurrentlyInteracting.EndInteraction();
                CurrentlyInteracting = null;
            }
        }
示例#17
0
        private void BeginInteraction(NVRInteractable interactable)
        {
            if (interactable.CanAttach == true)
            {
                if (interactable.AttachedHand != null)
                {
                    interactable.AttachedHand.EndInteraction(null);
                }

                CurrentlyInteracting = interactable;
                CurrentlyInteracting.BeginInteraction(this);
            }
        }
示例#18
0
 void SendEndInteraction(NVRInteractable item)
 {
     NetworkObjectManager.Instance.SendEndInterraction(item);
 }