namespace Zinnia.Pointer
{
using UnityEngine;
using UnityEngine.Events;
using Zinnia.Extension;
///
/// Describes an element of the rendered .
///
public class PointerElement : MonoBehaviour
{
///
/// The visibility of a .
///
public enum Visibility
{
///
/// The will only be visible when the is activated.
///
OnWhenPointerActivated,
///
/// The will always be visible regardless of the state.
///
AlwaysOn,
///
/// The will never be visible regardless of the state.
///
AlwaysOff
}
#region Valid Container Settings
[Header("Valid Container Settings")]
[Tooltip("The containing GameObject that represents the element when a valid collision is occuring.")]
[SerializeField]
private GameObject validElementContainer;
///
/// The containing that represents the element when a valid collision is occuring.
///
public GameObject ValidElementContainer
{
get
{
return validElementContainer;
}
set
{
validElementContainer = value;
}
}
[Tooltip("The GameObject containing the visible mesh for the PointerElement when a valid collision is occuring.")]
[SerializeField]
private GameObject validMeshContainer;
///
/// The containing the visible mesh for the when a valid collision is occuring.
///
public GameObject ValidMeshContainer
{
get
{
return validMeshContainer;
}
set
{
validMeshContainer = value;
}
}
#endregion
#region Invalid Container Settings
[Header("Invalid Container Settings")]
[Tooltip("The containing GameObject that represents the element when an invalid collision or no collision is occuring.")]
[SerializeField]
private GameObject invalidElementContainer;
///
/// The containing that represents the element when an invalid collision or no collision is occuring.
///
public GameObject InvalidElementContainer
{
get
{
return invalidElementContainer;
}
set
{
invalidElementContainer = value;
}
}
[Tooltip("The GameObject containing the visible mesh for the PointerElement when an invalid collision or no collision is occuring.")]
[SerializeField]
private GameObject invalidMeshContainer;
///
/// The containing the visible mesh for the when an invalid collision or no collision is occuring.
///
public GameObject InvalidMeshContainer
{
get
{
return invalidMeshContainer;
}
set
{
invalidMeshContainer = value;
}
}
#endregion
#region Visibility Settings
[Header("Visibility Settings")]
[Tooltip("Determines when the PointerElement is visible.")]
[SerializeField]
private Visibility elementVisibility = Visibility.OnWhenPointerActivated;
///
/// Determines when the is visible.
///
public Visibility ElementVisibility
{
get
{
return elementVisibility;
}
set
{
elementVisibility = value;
if (this.IsMemberChangeAllowed())
{
OnAfterElementVisibilityChange();
}
}
}
#endregion
#region Element Events
///
/// Emitted when the visibility of the element changes.
///
[Header("Element Events")]
public UnityEvent VisibilityChanged = new UnityEvent();
#endregion
///
/// Whether the element is currently visible.
///
public bool IsVisible { get; set; }
///
/// Clears .
///
public virtual void ClearValidElementContainer()
{
if (!this.IsValidState())
{
return;
}
ValidElementContainer = default;
}
///
/// Clears .
///
public virtual void ClearValidMeshContainer()
{
if (!this.IsValidState())
{
return;
}
ValidMeshContainer = default;
}
///
/// Clears .
///
public virtual void ClearInvalidElementContainer()
{
if (!this.IsValidState())
{
return;
}
InvalidElementContainer = default;
}
///
/// Clears .
///
public virtual void ClearInvalidMeshContainer()
{
if (!this.IsValidState())
{
return;
}
InvalidMeshContainer = default;
}
///
/// Sets the .
///
/// The index of the .
public virtual void SetElementVisibilityt(int index)
{
ElementVisibility = EnumExtensions.GetByIndex(index);
}
///
/// Called after has been changed.
///
protected virtual void OnAfterElementVisibilityChange()
{
VisibilityChanged?.Invoke();
}
}
}