namespace VRTK.Prefabs.Locomotion.Teleporters
{
using UnityEngine;
using System.Collections.Generic;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Zinnia.Visual;
using Zinnia.Data.Enum;
using Zinnia.Data.Type;
using Zinnia.Data.Attribute;
using Zinnia.Tracking;
using Zinnia.Tracking.Modification;
///
/// Sets up the Teleport Prefab based on the provided user settings.
///
public class TeleporterConfigurator : MonoBehaviour
{
#region Facade Settings
///
/// The public interface facade.
///
[Serialized]
[field: Header("Facade Settings"), DocumentedByXml, Restricted]
public TeleporterFacade Facade { get; protected set; }
#endregion
#region Teleporter Settings
///
/// The to use for the teleporting event.
///
[Serialized]
[field: Header("Teleporter Settings"), DocumentedByXml, Restricted]
public SurfaceLocator SurfaceTeleporter { get; protected set; }
///
/// The to use for the teleporting event.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public TransformPropertyApplier ModifyTeleporter { get; protected set; }
#endregion
#region Alias Settings
///
/// The to set aliases on.
///
[Serialized]
[field: Header("Alias Settings"), DocumentedByXml, Restricted]
public List SurfaceLocatorAliases { get; protected set; } = new List();
///
/// The to set rules on.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public List SurfaceLocatorRules { get; protected set; } = new List();
///
/// The collection to set aliases on.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public List TransformPropertyApplierAliases { get; protected set; } = new List();
///
/// The collection to ignore offsets on.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public List TransformPropertyApplierIgnoreOffsetAliases { get; protected set; } = new List();
///
/// The scene s to set the s to affect.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public List CameraColorOverlays { get; protected set; } = new List();
#endregion
///
/// Attempts to teleport the .
///
/// The location to attempt to teleport to.
public virtual void Teleport(TransformData destination)
{
if (SurfaceTeleporter != null)
{
SurfaceTeleporter.Locate(destination);
}
if (ModifyTeleporter != null)
{
ModifyTeleporter.Source = destination;
ModifyTeleporter.Apply();
}
}
///
/// Notifies that the teleporter is about to initiate.
///
/// The location data.
public virtual void NotifyTeleporting(TransformPropertyApplier.EventData data)
{
Facade.Teleporting?.Invoke(data);
}
///
/// Notifies that the teleporter has completed.
///
/// The location data.
public virtual void NotifyTeleported(TransformPropertyApplier.EventData data)
{
Facade.Teleported?.Invoke(data);
}
///
/// Configures the surface locator aliases with the offset provided in the facade.
///
public virtual void ConfigureSurfaceLocatorAliases()
{
foreach (SurfaceLocator currentLocator in SurfaceLocatorAliases)
{
currentLocator.SearchOrigin = Facade.Offset;
}
}
///
/// Configures the surface locator rules with the valid targets provided in the facade.
///
public virtual void ConfigureSurfaceLocatorRules()
{
foreach (SurfaceLocator currentLocator in SurfaceLocatorRules)
{
currentLocator.TargetValidity = Facade.TargetValidity;
}
}
///
/// Configures the transform properties applies with the settings applied in the facade.
///
public virtual void ConfigureTransformPropertyAppliers()
{
foreach (TransformPropertyApplier currentApplier in TransformPropertyApplierAliases)
{
currentApplier.Target = Facade.Target;
currentApplier.Offset = null;
if (!TransformPropertyApplierIgnoreOffsetAliases.Contains(currentApplier))
{
currentApplier.Offset = Facade.Offset;
continue;
}
currentApplier.Offset = Facade.OffsetUsage == TeleporterFacade.OffsetType.OffsetAlwaysWithDestinationRotation || Facade.OffsetUsage == TeleporterFacade.OffsetType.OffsetAlwaysIgnoreDestinationRotation ? Facade.Offset : null;
currentApplier.ApplyRotationOffsetOnAxis = Facade.OffsetUsage == TeleporterFacade.OffsetType.OffsetAlwaysWithDestinationRotation ? currentApplier.ApplyRotationOffsetOnAxis : Vector3State.False;
}
}
///
/// Configures the camera color overlays with the scene cameras provided in the facade.
///
public virtual void ConfigureCameraColorOverlays()
{
foreach (CameraColorOverlay currentOverlay in CameraColorOverlays)
{
currentOverlay.CameraValidity = Facade.CameraValidity;
}
}
///
/// Configures whether the teleporter will apply the destination rotation to the target.
///
public virtual void ConfigureRotationAbility(bool shouldRotate)
{
if (shouldRotate)
{
EnableRotations();
}
else
{
DisableRotations();
}
}
protected virtual void OnEnable()
{
ConfigureSurfaceLocatorAliases();
ConfigureSurfaceLocatorRules();
ConfigureTransformPropertyAppliers();
ConfigureCameraColorOverlays();
ConfigureRotationAbility(Facade.ApplyDestinationRotation);
}
///
/// Disables the ability to rotate the target.
///
protected virtual void DisableRotations()
{
foreach (TransformPropertyApplier alias in TransformPropertyApplierIgnoreOffsetAliases)
{
alias.ApplyTransformations &= ~TransformProperties.Rotation;
}
}
///
/// Enables the ability to rotate the target.
///
protected virtual void EnableRotations()
{
foreach (TransformPropertyApplier alias in TransformPropertyApplierIgnoreOffsetAliases)
{
alias.ApplyTransformations |= TransformProperties.Rotation;
}
}
}
}