Exemplo n.º 1
0
 private void tooManyBalls()
 {
     if (spawnedBallsList.Count > 4)
     {
         if (spawnedBallsList[0])
         {
             InteractableFacade interactable = spawnedBallsList[0].GetComponent <InteractableFacade>();
             if (!interactable.IsGrabbed)
             {
                 Destroy(spawnedBallsList[0]);
                 spawnedBallsList.RemoveAt(0);
             }
             else
             {
                 if (spawnedBallsList[1])
                 {
                     interactable = spawnedBallsList[1].GetComponent <InteractableFacade>();
                     if (!interactable.IsGrabbed)
                     {
                         Destroy(spawnedBallsList[1]);
                     }
                 }
                 spawnedBallsList.RemoveAt(1);
             }
         }
         else
         {
             spawnedBallsList.RemoveAt(0);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to snap a given <see cref="GameObject"/> to the snap zone.
        /// </summary>
        /// <param name="objectToSnap">The object to attempt to snap.</param>
        public virtual void Snap(GameObject objectToSnap)
        {
            if (!AllValidRules.Accepts(objectToSnap))
            {
                return;
            }

            InteractableFacade snappableInteractable = objectToSnap.TryGetComponent <InteractableFacade>(true, true);

            if (snappableInteractable == null || SnappedInteractable != null)
            {
                return;
            }

            foreach (GameObject collidingWith in snappableInteractable.Configuration.ActiveCollisions.SubscribableElements)
            {
                SnapZoneActivator activatingZone = collidingWith.GetComponent <SnapZoneActivator>();

                if (activatingZone == null)
                {
                    continue;
                }

                activatingZone.Facade.Unsnap();
                break;
            }

            if (objectToSnap.transform.position.ApproxEquals(DestinationLocation.transform.position))
            {
                objectToSnap.transform.position += Vector3.forward * InitialOffset;
            }

            SnapDroppedInteractableProcess.Receive(objectToSnap);
        }
    public void OnEnable()
    {
        facade        = transform.GetComponent <InteractableFacade>();
        meshContainer = transform.GetChild(0).gameObject;

        isThis = true;
    }
Exemplo n.º 4
0
        /// <summary>
        /// Attempts to process any other valid snappable objects against any other potential SnapZones if their primary activating zone is snapped by another object.
        /// </summary>
        public virtual void ProcessOtherSnappablesOnSnap()
        {
            foreach (GameObject snappable in SnappableInteractables)
            {
                if (snappable == null || snappable == SnappedInteractable)
                {
                    continue;
                }

                InteractableFacade snappableInteractable = snappable.TryGetComponent <InteractableFacade>(true, true);

                if (snappableInteractable == null)
                {
                    continue;
                }

                foreach (GameObject collidingWith in snappableInteractable.Configuration.ActiveCollisions.SubscribableElements)
                {
                    SnapZoneActivator activatingZone = collidingWith.GetComponent <SnapZoneActivator>();

                    if (activatingZone == null || activatingZone == ActivationArea || activatingZone.Facade.ZoneState == SnapZoneFacade.SnapZoneState.ZoneIsActivated)
                    {
                        continue;
                    }

                    activatingZone.Facade.Configuration.GrabStateEmitter.DoIsGrabbed(snappableInteractable);
                    break;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Attempts to nock the arrow.
        /// </summary>
        /// <param name="data">The collision data which should contain an arrow.</param>
        public virtual void AttemptArrowNock(CollisionNotifier.EventData data)
        {
            if (ArrowSnapZone.SnappedGameObject != null || !data.ColliderData.name.Equals("ArrowNockPoint"))
            {
                return;
            }

            InteractableFacade arrow = data.ColliderData.GetAttachedRigidbody().GetComponent <InteractableFacade>();

            if (arrow == null || arrow.GrabbingInteractors.Count == 0)
            {
                return;
            }

            arrowInteractor = arrow.GrabbingInteractors.Count > 0 ? arrow.GrabbingInteractors[0] : null;

            if (arrowInteractor == null)
            {
                return;
            }

            arrowInteractor.Ungrab();
            arrowInteractor.SimulateUntouch(arrow);
            arrowInteractor.Grab(BowInteractable);
            ArrowSnapZone.Snap(arrow);

            nockedArrow = arrow.GetComponentInParent <ArrowController>();
            ToggleColliders(BowColliders, nockedArrow.ArrowColliders, true);
            nockedArrow.ToggleColliderTrigger(true);
        }
        protected virtual void CreateClimbable(GameObject objectToWrap)
        {
            int        siblingIndex = objectToWrap.transform.GetSiblingIndex();
            GameObject newClimbable = (GameObject)PrefabUtility.InstantiatePrefab(climbablePrefab);

            newClimbable.name += "_" + objectToWrap.name;
            ClimbableFacade    climbableFacade = newClimbable.GetComponent <ClimbableFacade>();
            InteractableFacade facade          = newClimbable.GetComponentInChildren <InteractableFacade>();

            newClimbable.transform.SetParent(objectToWrap.transform.parent);
            newClimbable.transform.localPosition = objectToWrap.transform.localPosition;
            newClimbable.transform.localRotation = objectToWrap.transform.localRotation;
            newClimbable.transform.localScale    = objectToWrap.transform.localScale;

            foreach (MeshRenderer defaultMeshes in facade.Configuration.MeshContainer.GetComponentsInChildren <MeshRenderer>())
            {
                defaultMeshes.gameObject.SetActive(false);
            }

            objectToWrap.transform.SetParent(facade.Configuration.MeshContainer.transform);
            objectToWrap.transform.localPosition = Vector3.zero;
            objectToWrap.transform.localRotation = Quaternion.identity;
            objectToWrap.transform.localScale    = Vector3.one;

            newClimbable.transform.SetSiblingIndex(siblingIndex);
            climbableFacade.ClimbingFacade = climbingFacade;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Clears the grab state at the end of the frame.
        /// </summary>
        /// <param name="interactable"></param>
        /// <returns>An Enumerator to manage the running of the Coroutine.</returns>
        protected virtual IEnumerator ClearGrabStateAtEndOfFrame(InteractableFacade interactable)
        {
            yield return(delayInstruction);

            ClearGrabState(interactable);
            ClearGrabStateRoutine = null;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Clears the grab state for the given <see cref="InteractableFacade"/>.
 /// </summary>
 /// <param name="interactable">The Interactable to clear grab state on.</param>
 protected virtual void ClearGrabState(InteractableFacade interactable)
 {
     GrabConfiguration.IsGrabbingAction.Receive(false);
     GrabConfiguration.GrabbedObjectsCollection.Remove(interactable.TryGetGameObject());
     GrabConfiguration.GrabbedObjectsCollection.Remove(interactable.Configuration.ConsumerContainer);
     GrabConfiguration.StopGrabbingPublisher.ClearActiveCollisions();
     GrabConfiguration.StartGrabbingPublisher.RegisteredConsumerContainer.UnregisterConsumersOnContainer(interactable.Configuration.ConsumerContainer);
 }
Exemplo n.º 9
0
        private void LinkGrabEvent(LinearDriveFacade linerJointFacade, Transform interactable)
        {
            // Connects the linerJointFacade with the interactableFacade so the position of the normaliser object is correct
            InteractableFacade interactableFacade = interactable.GetComponent <InteractableFacade>();
            UnityAction        action             = (_) => linerJointFacade.SetTargetValueByStepValue();

            interactableFacade.LastUngrabbed.AddListener(action);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Clears any invalid SnapZone collision that still may be stored on the activating Interactable.
 /// </summary>
 /// <param name="interactable">The activating interactable.</param>
 /// <param name="invalidCollisions">The collection of invalid SnapZone collisions.</param>
 protected virtual void ClearInvalidSnapZoneCollisions(InteractableFacade interactable, ref List <GameObject> invalidCollisions)
 {
     foreach (GameObject invalidCollision in invalidCollisions)
     {
         interactable.Configuration.ActiveCollisions.Remove(invalidCollision);
     }
     invalidCollisions.Clear();
 }
 /// <summary>
 /// Ignores the interactable grabbed by the interactor.
 /// </summary>
 /// <param name="interactable">The interactable to ignore.</param>
 protected virtual void IgnoreInteractorGrabbedCollision(InteractableFacade interactable)
 {
     Collider[] interactableColliders = interactable.GetComponentsInChildren <Collider>(true);
     foreach (Collider toRestore in interactableColliders.Except(ignoredColliders))
     {
         RestoreColliders.Add(toRestore);
     }
     IgnoreCollisionsWith(interactable.gameObject);
 }
        /// <summary>
        /// Simulates an untouch on the given Interactable.
        /// </summary>
        /// <param name="interactable">The Interactable to simulate the untouch on.</param>
        public virtual void SimulateUntouch(InteractableFacade interactable)
        {
            if (interactable == null)
            {
                return;
            }

            interactable.Configuration.TouchConfiguration.NotifyUntouch(SimulatedInteractor.gameObject);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Emits the <see cref="Facade.AfterGrabbed"/> event.
        /// </summary>
        /// <param name="interactable">The payload to emit with.</param>
        public virtual void NotifyAfterGrabbed(InteractableFacade interactable)
        {
            if (interactable == null)
            {
                return;
            }

            Facade.AfterGrabbed?.Invoke(interactable);
        }
        public virtual void SetSource(GameObject source)
        {
            if (source == null)
            {
                return;
            }

            Source = source.GetComponent <InteractableFacade>();
        }
 /// <summary>
 /// Resumes the interactable ungrabbed by the interactor.
 /// </summary>
 /// <param name="interactable">The interactable to resume.</param>
 protected virtual void ResumeInteractorUngrabbedCollision(InteractableFacade interactable)
 {
     Collider[] interactableColliders = interactable.GetComponentsInChildren <Collider>(true);
     foreach (Collider resumeCollider in interactableColliders.Intersect(RestoreColliders))
     {
         ResumeCollisionsWith(resumeCollider);
         RestoreColliders.Remove(resumeCollider);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Unregisters a listener from the given <see cref="InteractableFacade"/> Grabbed event.
        /// </summary>
        /// <param name="grabbable">The interactable to unregister the grab event from.</param>
        public virtual void UnregisterGrabbed(InteractableFacade grabbable)
        {
            if (grabbable == null || !unsubscribeGrabActions.TryGetValue(grabbable, out System.Action unsubscribeAction))
            {
                return;
            }

            unsubscribeAction();
            unsubscribeGrabActions.Remove(grabbable);
        }
        /// <summary>
        /// Emits the <see cref="Facade.AfterGrabbed"/> event.
        /// </summary>
        /// <param name="interactable">The payload to emit with.</param>
        public virtual void NotifyAfterGrabbed(InteractableFacade interactable)
        {
            if (interactable == null)
            {
                return;
            }

            RestoreInteractorPrecognitionValue();
            Facade.AfterGrabbed?.Invoke(interactable);
        }
        /// <summary>
        /// Handles the <see cref="Facade.Interactor"/> touching state.
        /// </summary>
        /// <param name="interactable">The Interactable being touched.</param>
        protected virtual void HasTouched(InteractableFacade interactable)
        {
            if (!DisablePointerOnInteractorTouch)
            {
                return;
            }

            PointerContainer.SetActive(false);
            EnablePointerContainer.SetActive(false);
        }
        /// <summary>
        /// Handles the <see cref="Facade.Interactor"/> untouching state.
        /// </summary>
        /// <param name="interactable">The Interactable being touched.</param>
        protected virtual void HasUntouched(InteractableFacade interactable)
        {
            EnablePointerContainer.SetActive(true);
            if (!DisablePointerOnInteractorTouch || ShouldIgnoreEnablePointer)
            {
                return;
            }

            PointerContainer.SetActive(true);
        }
 /// <summary>
 /// Resumes the Interactable ungrabbed by the Interactor.
 /// </summary>
 /// <param name="interactable">The Interactable to resume.</param>
 protected virtual void ResumeInteractorUngrabbedCollision(InteractableFacade interactable)
 {
     if (!Facade.IgnoredGameObjects.Contains(interactable.gameObject) &&
         (
             interactable.GrabbingInteractors.Count == 0 ||
             !Facade.IgnoredGameObjects.NonSubscribableElements.Intersect(GetGameObjectListFromInteractorFacadeList(interactable.GrabbingInteractors)).Any())
         )
     {
         CollisionsToIgnore.RunWhenActiveAndEnabled(() => CollisionsToIgnore.Targets.Remove(interactable.gameObject));
     }
 }
Exemplo n.º 21
0
 /// <summary>
 /// Notifies the Interactor that it is grabbing an Interactable.
 /// </summary>
 /// <param name="interactable">The Interactable being grabbed.</param>
 public virtual void NotifyOfGrab(InteractableFacade interactable)
 {
     GrabConfiguration.GrabbedObjectsCollection.AddUnique(interactable.gameObject);
     if (ClearGrabStateRoutine != null)
     {
         StopCoroutine(ClearGrabStateRoutine);
         ClearGrabStateRoutine = null;
     }
     GrabConfiguration.IsGrabbingAction.Receive(true);
     Grabbed?.Invoke(interactable);
 }
        /// <summary>
        /// Attempts to unsnap the given Interactable if it is snapped into a snap zone.
        /// </summary>
        /// <param name="interactable">The Interactable to attempt to unsnap.</param>
        public virtual void UnsnapInteractable(InteractableFacade interactable)
        {
            if (!IsInSnapZone(interactable, out SnapZoneFacade foundSnapZone))
            {
                return;
            }

            if (foundSnapZone != null)
            {
                foundSnapZone.Unsnap();
            }
        }
Exemplo n.º 23
0
        public virtual void RegisterGrabbed(InteractableFacade grabbable)
        {
            if (grabbable == null || unsubscribeGrabActions.ContainsKey(grabbable))
            {
                return;
            }

            void OnGrabbed(InteractorFacade _) => InteractableGrabbed(grabbable);

            grabbable.FirstGrabbed.AddListener(OnGrabbed);
            unsubscribeGrabActions[grabbable] = () => grabbable.FirstGrabbed.RemoveListener(OnGrabbed);
        }
        /// <summary>
        /// Unregisters the appropriate events on the given <see cref="InteractableFacade"/>.
        /// </summary>
        /// <param name="interactable">The source of the interaction events.</param>
        protected virtual void UnregisterInteractableEvents(InteractableFacade interactable)
        {
            if (interactable == null)
            {
                return;
            }

            interactable.FirstTouched.RemoveListener(HandleFirstTouched);
            interactable.LastUntouched.RemoveListener(HandleLastUntouched);
            interactable.FirstGrabbed.RemoveListener(HandleFirstGrabbed);
            interactable.LastUngrabbed.RemoveListener(LastUngrabbed);
        }
Exemplo n.º 25
0
        public virtual void RegisterUngrabbed(InteractableFacade ungrabbable)
        {
            if (ungrabbable == null || unsubscribeUngrabActions.ContainsKey(ungrabbable))
            {
                return;
            }

            void OnUngrabbed(InteractorFacade _) => InteractableUngrabbed(ungrabbable);

            ungrabbable.LastUngrabbed.AddListener(OnUngrabbed);
            unsubscribeUngrabActions[ungrabbable] = () => ungrabbable.LastUngrabbed.RemoveListener(OnUngrabbed);
        }
Exemplo n.º 26
0
        /// <inheritdoc />
        protected override GameObject ExtractValue()
        {
            if (Source.GetType() != typeof(InteractableFacade))
            {
                return(null);
            }

            InteractableFacade interactableSource = (InteractableFacade)Source;

            return(interactableSource != null && interactableSource.Configuration != null && interactableSource.Configuration.ConsumerRigidbody != null
                ? interactableSource.Configuration.ConsumerRigidbody.gameObject
                : null);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Attempts to set the cache for the <see cref="InteractableFacade"/> associated with the given valid snappable <see cref="GameObject"/>.
        /// </summary>
        /// <param name="container">The colliding interactable.</param>
        protected virtual void TrySetInteractableFacade(GameObject container)
        {
            if ((container != null && container != currentActivatingGameObject) || currentActivatingInteractable == null)
            {
                currentActivatingGameObject   = container;
                currentActivatingInteractable = TryGetInteractable(currentActivatingGameObject);
            }

            if (currentActivatingInteractable == null)
            {
                throw new NullReferenceException("The given container must contain an InteractableFacade.");
            }
        }
Exemplo n.º 28
0
    public void Awake()
    {
        climbRef = FindObjectOfType <BetterClimb>();

        if (!climbRef)
        {
            Debug.LogError("No Player BetterClimb Component");
        }

        thisInteractible = GetComponent <InteractableFacade>();
        GetComponent <InteractableFacade>().Grabbed.AddListener(Grabbed);
        GetComponent <InteractableFacade>().Ungrabbed.AddListener(UnGrabbed);
    }
Exemplo n.º 29
0
        /// <summary>
        /// Snaps the orientation of the grabbed Interactable at the given index to this Interactor.
        /// </summary>
        /// <param name="index">The index of the grabbed Interactable.</param>
        public virtual void SnapGrabbedInteractableOrientation(int index)
        {
            if (index < 0 || index >= GrabbedObjects.Count)
            {
                return;
            }

            InteractableFacade interactable = GrabbedObjects[index].TryGetComponent <InteractableFacade>(true, true);

            if (interactable != null)
            {
                interactable.SnapFollowOrientation();
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Attempt to ungrab currently grabbed Interactables to the current Interactor.
        /// </summary>
        public virtual void Ungrab()
        {
            if (GrabbedObjects.Count == 0)
            {
                return;
            }

            InteractableFacade interactable = GrabbedObjects[0].TryGetComponent <InteractableFacade>(true, true);

            if (interactable.IsGrabTypeToggle)
            {
                ProcessGrabAction(StartGrabbingPublisher, true);
            }
            ProcessGrabAction(StopGrabbingPublisher, false);
        }