namespace VRTK.Prefabs.Interactions.InteractorVisibilityModifier
{
using UnityEngine;
using UnityEngine.Events;
using System;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Malimbe.BehaviourStateRequirementMethod;
using Zinnia.Data.Attribute;
using VRTK.Prefabs.Interactions.Interactors;
///
/// Provides a mechanism for showing and hiding Interactors.
///
public class InteractorVisibilityModifierFacade : MonoBehaviour
{
///
/// Defines the event with the .
///
[Serializable]
public class UnityEvent : UnityEvent
{
}
#region Visibility Events
///
/// Emitted when the Interactor becomes shown.
///
[Header("Visibility Events"), DocumentedByXml]
public UnityEvent Shown = new UnityEvent();
///
/// Emitted when the Interactor becomes hidden.
///
[DocumentedByXml]
public UnityEvent Hidden = new UnityEvent();
#endregion
#region Reference Settings
///
/// The emitter that deals with hiding the interactor.
///
[Serialized]
[field: Header("Reference Settings"), DocumentedByXml, Restricted]
public InteractorFacadeEventProxyEmitter HideEmitter { get; protected set; }
///
/// The emitter that deals with showing the interactor.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public InteractorFacadeEventProxyEmitter ShowEmitter { get; protected set; }
#endregion
///
/// Attempts to hide the given .
///
/// The interactor to hide.
public virtual void Hide(InteractorFacade interactorFacade)
{
if (Emit(HideEmitter, interactorFacade))
{
Hidden?.Invoke(interactorFacade);
}
}
///
/// Attempts to show the given .
///
/// The interactor to show.
public virtual void Show(InteractorFacade interactorFacade)
{
if (Emit(ShowEmitter, interactorFacade))
{
Shown?.Invoke(interactorFacade);
}
}
///
/// Attempts to emit the appropriate emitter for the given .
///
/// The event proxy to emit to.
/// The interactor to emit with.
/// Whether the event is emitted.
[RequiresBehaviourState]
protected virtual bool Emit(InteractorFacadeEventProxyEmitter emitter, InteractorFacade interactorFacade)
{
if (emitter == null)
{
return false;
}
emitter.Receive(interactorFacade);
return true;
}
}
}