namespace Zinnia.Tracking.Modification
{
using UnityEngine;
using Zinnia.Data.Collection.List;
using Zinnia.Data.Type;
using Zinnia.Extension;
///
/// Provides the ability to modify the enabled state of a or component.
///
public class ComponentEnabledStateModifier : MonoBehaviour
{
[Tooltip("The Object types to manage the enabled state on.")]
[SerializeField]
private SerializableTypeComponentObservableList types;
///
/// The types to manage the enabled state on.
///
public SerializableTypeComponentObservableList Types
{
get
{
return types;
}
set
{
types = value;
}
}
[Tooltip("The target to modify the enabled states for the provided Types.")]
[SerializeField]
private GameObject target;
///
/// The target to modify the enabled states for the provided .
///
public GameObject Target
{
get
{
return target;
}
set
{
target = value;
}
}
///
/// Clears .
///
public virtual void ClearTarget()
{
if (!this.IsValidState())
{
return;
}
Target = default;
}
///
/// Sets the enabled state of all matching found on .
///
/// The enabled state to apply.
public virtual void SetEnabledState(bool state)
{
if (!this.IsValidState() || Types == null || Target == null)
{
return;
}
foreach (SerializableType serializableType in Types.NonSubscribableElements)
{
foreach (Component targetObject in Target.GetComponentsInChildren(serializableType, true))
{
Behaviour potentialBehaviour = targetObject as Behaviour;
if (potentialBehaviour != null)
{
potentialBehaviour.enabled = state;
continue;
}
Renderer potentialRenderer = targetObject as Renderer;
if (potentialRenderer != null)
{
potentialRenderer.enabled = state;
}
}
}
}
}
}