namespace VRTK.Prefabs.Interactions.InteractableSnapZone
{
using UnityEngine;
using UnityEngine.Events;
using System;
using Malimbe.MemberChangeMethod;
using Malimbe.MemberClearanceMethod;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Zinnia.Rule;
using Zinnia.Data.Type;
using Zinnia.Data.Attribute;
using VRTK.Prefabs.Interactions.Interactables;
public class SnapZoneFacade : MonoBehaviour
{
///
/// Defines the event with the .
///
[Serializable]
public class UnityEvent : UnityEvent { }
///
/// The state the SnapZone is in.
///
public enum SnapZoneState
{
///
/// No valid is colliding with the SnapZone and nothing has been snapped into the SnapZone.
///
ZoneIsEmpty,
///
/// At least one valid is colliding with the SnapZone but nothing has been snapped into the SnapZone.
///
ZoneIsActivated,
///
/// A valid has been snapped into the SnapZone.
///
ZoneIsSnapped
}
#region Snap Settings
///
/// The rules that determine which can be snapped to this snap zone.
///
[Serialized, Cleared]
[field: Header("Snap Settings"), DocumentedByXml]
public RuleContainer SnapValidity { get; set; }
///
/// The duration for the transition of the snapped to reach the snap zone destination.
///
[Serialized]
[field: DocumentedByXml]
public float TransitionDuration { get; set; }
#endregion
#region Reference Settings
///
/// The linked Configurator Setup.
///
[Serialized]
[field: Header("Reference Settings"), DocumentedByXml, Restricted]
public SnapZoneConfigurator Configuration { get; protected set; }
#endregion
#region Zone Events
///
/// Emitted when a valid enters the zone.
///
[Header("Zone Events"), DocumentedByXml]
public UnityEvent Entered = new UnityEvent();
///
/// Emitted when a valid exits the zone.
///
[DocumentedByXml]
public UnityEvent Exited = new UnityEvent();
///
/// Emitted when a valid activates the zone.
///
[DocumentedByXml]
public UnityEvent Activated = new UnityEvent();
///
/// Emitted when a valid deactivates the zone.
///
[DocumentedByXml]
public UnityEvent Deactivated = new UnityEvent();
///
/// Emitted when a valid is snapped to the zone.
///
[DocumentedByXml]
public UnityEvent Snapped = new UnityEvent();
///
/// Emitted when a valid is unsnapped from the zone.
///
[DocumentedByXml]
public UnityEvent Unsnapped = new UnityEvent();
#endregion
///
/// Returns the collection of s that are currently colliding with the snap zone and are valid to be snapped.
///
public HeapAllocationFreeReadOnlyList SnappableGameObjects => Configuration.SnappableInteractables;
///
/// Returns the currently snapped .
///
public GameObject SnappedGameObject => Configuration.SnappedInteractable;
///
/// The state of the SnapZone.
///
public SnapZoneState ZoneState
{
get
{
if (SnappedGameObject != null)
{
return SnapZoneState.ZoneIsSnapped;
}
else if (SnappableGameObjects.Count > 0)
{
return SnapZoneState.ZoneIsActivated;
}
return SnapZoneState.ZoneIsEmpty;
}
}
///
/// Attempts to snap a given to the snap zone.
///
/// The interactable to attempt to snap.
public virtual void Snap(InteractableFacade interactableToSnap)
{
Snap(interactableToSnap.gameObject);
}
///
/// Attempts to snap a given to the snap zone.
///
/// The object to attempt to snap.
public virtual void Snap(GameObject objectToSnap)
{
Configuration.Snap(objectToSnap);
}
///
/// Attempts to unsnap any existing that is currently snapped to the snap zone.
///
public virtual void Unsnap()
{
Configuration.Unsnap();
}
///
/// Called after has been changed.
///
[CalledAfterChangeOf(nameof(SnapValidity))]
protected virtual void OnAfterSnapValidityChange()
{
Configuration.ConfigureValidityRules();
}
///
/// Called after has been changed.
///
[CalledAfterChangeOf(nameof(TransitionDuration))]
protected virtual void OnAfterTransitionDurationChange()
{
Configuration.ConfigurePropertyApplier();
}
}
}