/// <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() { GameObjectsAssociation desiredAssociation = associations.EmptyIfNull().FirstOrDefault(association => association.ShouldBeActive()); if (desiredAssociation == null || CurrentAssociation == desiredAssociation) { return; } CurrentAssociation = desiredAssociation; IEnumerable <GameObjectsAssociation> 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); } }
/// <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; }