namespace Zinnia.Action.Collection { using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using Zinnia.Data.Collection.List; using Zinnia.Extension; /// /// Allows observing changes to a of s. /// public class ActionRegistrarSourceObservableList : DefaultObservableList { /// /// Defines the event with the . /// [Serializable] public class UnityEvent : UnityEvent { } /// /// Enables the that has a container matching the given source. /// /// The source to match the container against. public virtual void EnableSource(GameObject source) { if (!this.IsValidState()) { return; } SetSourceEnabledState(source, true, false); } /// /// Disables the that has a container matching the given source. /// /// The source to match the container against. public virtual void DisableSource(GameObject source) { if (!this.IsValidState()) { return; } SetSourceEnabledState(source, false, false); } /// /// Enables all elements. /// public virtual void EnableAllSources() { if (!this.IsValidState()) { return; } SetSourceEnabledState(null, true, true); } /// /// Disables all elements. /// public virtual void DisableAllSources() { if (!this.IsValidState()) { return; } SetSourceEnabledState(null, false, true); } /// /// Sets the enabled state of an . /// /// The source to match the container to set the state of. /// The state to set enabled to. /// Whether to ignore the source and just set all sources to the given state. protected virtual void SetSourceEnabledState(GameObject source, bool state, bool setAll) { for (int index = 0; index < NonSubscribableElements.Count; index++) { ActionRegistrar.ActionSource actionSource = NonSubscribableElements[index]; if (actionSource.Container != source && !setAll) { continue; } actionSource.Enabled = state; RemoveAt(index); InsertAt(actionSource, index); } } } }