namespace VRTK.Prefabs.CameraRig.SimulatedCameraRig
{
using UnityEngine;
using System.Collections.Generic;
using Malimbe.MemberChangeMethod;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Zinnia.Extension;
using Zinnia.Data.Type.Transformation.Aggregation;
using VRTK.Prefabs.CameraRig.SimulatedCameraRig.Input;
///
/// Sets up the active controllable objects.
///
public class ActiveObjectController : MonoBehaviour
{
///
/// The speed to move the free mouse cursor.
///
[Serialized]
[field: DocumentedByXml]
public float FreeCursorRotationSpeed { get; set; } = 0.2f;
///
/// The speed to move the locked mouse cursor.
///
///
[Serialized]
[field: DocumentedByXml]
public float LockedCursorRotationSpeed { get; set; } = 3f;
///
/// The speed to move the object at.
///
[Serialized]
[field: DocumentedByXml]
public float MovementSpeed { get; set; } = 0.025f;
///
/// The mouse input action to update.
///
[Serialized]
[field: DocumentedByXml]
public MouseVector2DAction MouseInput { get; set; }
///
/// A collection of multipliers that deal with positive floats.
///
[Tooltip("A collection of multipliers that deal with positive floats.")]
public List positiveMultipliers = new List();
///
/// A collection of multipliers that deal with negative floats.
///
[Tooltip("A collection of multipliers that deal with negative floats.")]
public List negativeMultipliers = new List();
///
/// Refreshes the positive multiplier collection.
///
public virtual void RefreshPositiveMultipliers()
{
foreach (FloatMultiplier positiveMultiplier in positiveMultipliers)
{
positiveMultiplier.Collection.RunWhenActiveAndEnabled(() => positiveMultiplier.Collection.SetAt(MovementSpeed, 1));
positiveMultiplier.Collection.RunWhenActiveAndEnabled(() => positiveMultiplier.Collection.CurrentIndex = 0);
}
}
///
/// Refreshes the negative multiplier collection.
///
public virtual void RefreshNegativeMultipliers()
{
foreach (FloatMultiplier negativeMultiplier in negativeMultipliers)
{
negativeMultiplier.Collection.RunWhenActiveAndEnabled(() => negativeMultiplier.Collection.SetAt(-MovementSpeed, 1));
negativeMultiplier.Collection.RunWhenActiveAndEnabled(() => negativeMultiplier.Collection.CurrentIndex = 0);
}
}
protected virtual void OnEnable()
{
ConfigureMouseInput();
RefreshPositiveMultipliers();
RefreshNegativeMultipliers();
}
///
/// Configures the mouse input settings.
///
protected virtual void ConfigureMouseInput()
{
if (MouseInput != null)
{
MouseInput.CursorMultiplier = FreeCursorRotationSpeed;
MouseInput.LockedCursorMultiplier = LockedCursorRotationSpeed;
}
}
///
/// Called after has been changed.
///
[CalledAfterChangeOf(nameof(FreeCursorRotationSpeed))]
protected virtual void OnAfterFreeCursorRotationSpeedChange()
{
ConfigureMouseInput();
}
///
/// Called after has been changed.
///
[CalledAfterChangeOf(nameof(LockedCursorRotationSpeed))]
protected virtual void OnAfterLockedCursorRotationSpeedChange()
{
ConfigureMouseInput();
}
///
/// Called after has been changed.
///
[CalledAfterChangeOf(nameof(MovementSpeed))]
protected virtual void OnAfterMovementSpeedChange()
{
RefreshPositiveMultipliers();
RefreshNegativeMultipliers();
}
///
/// Called after has been changed.
///
[CalledAfterChangeOf(nameof(MouseInput))]
protected virtual void OnAfterMouseInputChange()
{
ConfigureMouseInput();
}
}
}