using UnityEngine;
namespace Cinemachine
{
///
/// This is a CinemachineComponent in the Aim section of the component pipeline.
/// Its job is to aim the camera in response to the user's mouse or joystick input.
///
/// The composer does not change the camera's position. It will only pan and tilt the
/// camera where it is, in order to get the desired framing. To move the camera, you have
/// to use the virtual camera's Body section.
///
[DocumentationSorting(23, DocumentationSortingAttribute.Level.UserRef)]
[AddComponentMenu("")] // Don't display in add component menu
[RequireComponent(typeof(CinemachinePipeline))]
[SaveDuringPlay]
public class CinemachinePOV : CinemachineComponentBase
{
/// The Vertical axis. Value is -90..90. Controls the vertical orientation
[Tooltip("The Vertical axis. Value is -90..90. Controls the vertical orientation")]
public AxisState m_VerticalAxis = new AxisState(300f, 0.1f, 0.1f, 0f, "Mouse Y", true);
/// The Horizontal axis. Value is -180..180. Controls the horizontal orientation
[Tooltip("The Horizontal axis. Value is -180..180. Controls the horizontal orientation")]
public AxisState m_HorizontalAxis = new AxisState(300f, 0.1f, 0.1f, 0f, "Mouse X", false);
/// True if component is enabled and has a LookAt defined
public override bool IsValid { get { return enabled; } }
/// Get the Cinemachine Pipeline stage that this component implements.
/// Always returns the Aim stage
public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } }
private void OnValidate()
{
m_HorizontalAxis.Validate();
m_VerticalAxis.Validate();
}
private void OnEnable()
{
m_HorizontalAxis.SetThresholds(-180f, 180f, true);
m_VerticalAxis.SetThresholds(-90, 90, false);
}
/// Applies the axis values and orients the camera accordingly
/// The current camera state
/// Used for calculating damping. Not used.
public override void MutateCameraState(ref CameraState curState, float deltaTime)
{
if (!IsValid)
return;
//UnityEngine.Profiling.Profiler.BeginSample("CinemachinePOV.MutateCameraState");
// Only read joystick when game is playing
if (deltaTime >= 0 || CinemachineCore.Instance.IsLive(VirtualCamera))
{
m_HorizontalAxis.Update(deltaTime);
m_VerticalAxis.Update(deltaTime);
}
Quaternion rot = Quaternion.Euler(m_VerticalAxis.Value, m_HorizontalAxis.Value, 0);
rot = rot * Quaternion.FromToRotation(Vector3.up, curState.ReferenceUp);
curState.OrientationCorrection = curState.OrientationCorrection * rot;
//UnityEngine.Profiling.Profiler.EndSample();
}
}
}