Esempio n. 1
0
        /// <summary>
        /// Activates the <see cref="GameObject"/>s that are part of the association if the association matches the currently expected state.
        /// </summary>
        public virtual void Activate()
        {
            BaseGameObjectsAssociation desiredAssociation = associations.EmptyIfNull().FirstOrDefault(association => association.ShouldBeActive());

            if (desiredAssociation == null || CurrentAssociation == desiredAssociation)
            {
                return;
            }

            CurrentAssociation = desiredAssociation;

            IEnumerable <BaseGameObjectsAssociation> otherAssociations = associations.EmptyIfNull()
                                                                         .Except(
                new[]
            {
                desiredAssociation
            });

            foreach (GameObject otherAssociationObject in otherAssociations.SelectMany(otherAssociation => otherAssociation.gameObjects.EmptyIfNull()))
            {
                otherAssociationObject.SetActive(false);
            }

            foreach (GameObject associationObject in desiredAssociation.gameObjects.EmptyIfNull())
            {
                associationObject.SetActive(true);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deactivates the association that is currently activated and all other known associations.
        /// </summary>
        public virtual void Deactivate()
        {
            foreach (GameObject associationObject in associations.EmptyIfNull()
                     .Append(CurrentAssociation)
                     .Where(association => association != null)
                     .SelectMany(association => association.gameObjects.EmptyIfNull()))
            {
                associationObject.SetActive(false);
            }

            CurrentAssociation = null;
        }