/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Demo.UI
{
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.StateSystem;
using UnityEngine;
///
/// Manages the mouse smoothing zone. Allows switching betweening mouse input types.
///
public class MouseSmoothingZone : UIZone
{
private enum SmoothingType { Raw, Smoothing, LowSensitivity, LowSensitivityAcceleration }
private SmoothingType m_SmoothingType = SmoothingType.Smoothing;
///
/// Change the smoothing type to the specified type.
///
/// The type to change the value to.
public void ChangeSmoothingType(int type)
{
ChangeInputType((SmoothingType)type);
}
///
/// Change the smoothing type to the specified type.
///
/// The type to change the value to.
private void ChangeInputType(SmoothingType type)
{
// Revert the old.
SetButtonColor((int)m_SmoothingType, m_NormalColor);
StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SmoothingType), m_SmoothingType), false);
// Set the new smoothing type.
m_SmoothingType = type;
SetButtonColor((int)m_SmoothingType, m_PressedColor);
StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SmoothingType), type), true);
EnableInput();
}
///
/// The character has entered from the zone.
///
/// The character that entered the zone.
protected override void CharacterEnter(UltimateCharacterLocomotion characterLocomotion)
{
// The smoothing type is the standard type.
ChangeInputType(SmoothingType.Smoothing);
}
///
/// The character has exited from the zone.
///
/// The character that exited the zone.
protected override void CharacterExit(UltimateCharacterLocomotion characterLocomotion)
{
// The smoothing type should activate when leaving the zone.
ChangeInputType(SmoothingType.Smoothing);
}
}
}