CameraState.cs
Description
This is the base class to be used by the different states of the camera's state machine.
Script
using Unity.Cinemachine;
namespace Cameras.FSM
{
public abstract class CameraState
{
protected CameraController CameraController;
protected CameraStateMachine StateMachine;
public bool IsChangingPerspective { get; set; }
protected CinemachineCamera StateCamera { get; set; }
protected CameraState(CameraStateMachine stateMachine, CameraController cameraController,
CinemachineCamera stateCamera)
{
StateMachine = stateMachine;
CameraController = cameraController;
StateCamera = stateCamera;
CameraController.playerInput.actions["Perspective"].performed += _ => PerspectiveChange();
}
public void Enter()
{
MainCamera.SetActiveCamera(StateCamera);
}
public void HandleInput()
{
}
public virtual void LogicUpdate()
{
}
public void PhysicsUpdate()
{
}
private void PerspectiveChange()
{
StateMachine.CurrentState.IsChangingPerspective = true;
}
public void Exit()
{
IsChangingPerspective = false;
}
}
}
Protected Methods
- CameraState()
Stores a reference to the required components, while also setting up a bind to change camera perspectives
Public Methods
- Enter()
Sets the active camera to be the state camera
- Exit()
Indicates that the camera is no longer changing perspective.
- HandleInput()
Does nothing, overridden by the states.
- LogicUpdate()
Does nothing, overridden by the states.
- PerspectiveChange()
Indicates that the camera is changing perspective.
- PhysicsUpdate()
Does nothing, overridden by the states.
Variables
- CameraController
The script that controls the camera.
- IsChangingPerspective
Is the player changing camera perspective.
- StateCamera
The camera to be used for each specific state.
- StateMachine
The script that controls the camera state machine.
Last modified: 30 April 2024