Exemple #1
0
        void checkGrabbableEvents()
        {
            // Bail if nothing in our trigger area
            if (grabsInTrigger == null)
            {
                return;
            }

            // If last closest was this one let event know and remove validator
            if (previousClosest != grabsInTrigger.ClosestGrabbable)
            {
                if (previousClosest != null)
                {
                    // Fire Off Events
                    GrabbableEvents[] ge = previousClosest.GetComponents <GrabbableEvents>();
                    if (ge != null)
                    {
                        for (int x = 0; x < ge.Length; x++)
                        {
                            ge[x].OnNoLongerClosestGrabbable(HandSide);
                        }
                    }
                    previousClosest.RemoveValidGrabber(this);
                }

                // Update closest Grabbable
                if (grabsInTrigger.ClosestGrabbable != null && !HoldingItem)
                {
                    // Fire Off Events
                    GrabbableEvents[] ge = grabsInTrigger.ClosestGrabbable.GetComponents <GrabbableEvents>();
                    if (ge != null)
                    {
                        for (int x = 0; x < ge.Length; x++)
                        {
                            ge[x].OnBecomesClosestGrabbable(HandSide);
                        }
                    }
                    grabsInTrigger.ClosestGrabbable.AddValidGrabber(this);
                }
            }

            if (grabsInTrigger.ClosestGrabbable != null && !HoldingItem)
            {
                grabsInTrigger.ClosestGrabbable.AddValidGrabber(this);
            }

            // Remote Grabbable Events
            // If last closest was this one, unhighlight object
            if (previousClosestRemote != grabsInTrigger.ClosestRemoteGrabbable)
            {
                if (previousClosestRemote != null)
                {
                    // Fire Off Events
                    GrabbableEvents[] ge = previousClosestRemote.GetComponents <GrabbableEvents>();
                    if (ge != null)
                    {
                        for (int x = 0; x < ge.Length; x++)
                        {
                            ge[x].OnNoLongerClosestRemoteGrabbable(HandSide);
                        }
                    }
                    previousClosestRemote.RemoveValidGrabber(this);
                }

                // Update closest remote Grabbable
                if (grabsInTrigger.ClosestRemoteGrabbable != null && !HoldingItem)
                {
                    // Fire Off Events
                    GrabbableEvents[] ge = grabsInTrigger.ClosestRemoteGrabbable.GetComponents <GrabbableEvents>();
                    if (ge != null)
                    {
                        for (int x = 0; x < ge.Length; x++)
                        {
                            ge[x].OnBecomesClosestRemoteGrabbable(HandSide);
                        }
                    }

                    grabsInTrigger.ClosestRemoteGrabbable.AddValidGrabber(this);
                }
            }

            // Set this as previous closest
            previousClosest       = grabsInTrigger.ClosestGrabbable;
            previousClosestRemote = grabsInTrigger.ClosestRemoteGrabbable;
        }