using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Sci-Fi Ship Controller. Copyright (c) 2018-2023 SCSM Pty Ltd. All rights reserved.
namespace SciFiShipController
{
///
/// This sample script shows how you can use a custom player input action to change the camera view for a ship.
/// Setup:
/// 1. Add this script to your camera (it must have a Ship Camera Module attached)
/// 2. On your Player Input Module, add a new custom player input
/// 3. Configure the button to the button you want to press to cycle the camera views
/// 4. In the gameobject slot, select the object this script is attached to (the camera)
/// 5. Choose the "SampleChangeCameraView.CycleCameraView" option from the function dropdown (where it initially says "No Function")
/// 6. Configure the settings of the three camera views as required
///
[AddComponentMenu("Sci-Fi Ship Controller/Samples/Change Camera View")]
[HelpURL("http://scsmmedia.com/ssc-documentation")]
[RequireComponent(typeof(ShipCameraModule))]
public class SampleChangeCameraView : MonoBehaviour
{
#region Public Variables
#region Camera View 1 Variables
[Header("Camera View 1")]
///
/// The target offset coordinates of camera view 1.
///
public ShipCameraModule.TargetOffsetCoordinates targetOffsetCoords1 = ShipCameraModule.TargetOffsetCoordinates.TargetRotation;
///
/// The target offset of camera view 1.
///
public Vector3 targetOffset1 = new Vector3(0f, 0.75f, 4.25f);
///
/// Whether camera view 1 is locked to the target position.
///
public bool lockToTargetPos1 = true;
///
/// The move speed of camera view 1.
///
public float moveSpeed1 = 15f;
///
/// Whether camera view 1 is locked to the target rotation.
///
public bool lockToTargetRot1 = true;
///
/// The turn speed of camera view 1.
///
public float turnSpeed1 = 15f;
///
/// The camera rotation mode of camera view 1.
///
public ShipCameraModule.CameraRotationMode cameraRotationMode1 = ShipCameraModule.CameraRotationMode.FollowTargetRotation;
///
/// The follow velocity threshold of camera view 1.
///
public float followVelocityThreshold1 = 10f;
///
/// Whether camera view 1 is oriented upwards.
///
public bool orientUpwards1 = false;
#endregion
#region Camera View 2 Variables
[Header("Camera View 2")]
///
/// The target offset coordinates of camera view 2.
///
public ShipCameraModule.TargetOffsetCoordinates targetOffsetCoords2 = ShipCameraModule.TargetOffsetCoordinates.TargetRotation;
///
/// The target offset of camera view 2.
///
public Vector3 targetOffset2 = new Vector3(0f, 2f, -10f);
///
/// Whether camera view 2 is locked to the target position.
///
public bool lockToTargetPos2 = false;
///
/// The move speed of camera view 2.
///
public float moveSpeed2 = 15f;
///
/// Whether camera view 2 is locked to the target rotation.
///
public bool lockToTargetRot2 = false;
///
/// The turn speed of camera view 2.
///
public float turnSpeed2 = 15f;
///
/// The camera rotation mode of camera view 2.
///
public ShipCameraModule.CameraRotationMode cameraRotationMode2 = ShipCameraModule.CameraRotationMode.FollowVelocity;
///
/// The follow velocity threshold of camera view 2.
///
public float followVelocityThreshold2 = 10f;
///
/// Whether camera view 2 is oriented upwards.
///
public bool orientUpwards2 = false;
#endregion
#region Camera View 3 Variables
[Header("Camera View 3")]
///
/// The target offset coordinates of camera view 3.
///
public ShipCameraModule.TargetOffsetCoordinates targetOffsetCoords3 = ShipCameraModule.TargetOffsetCoordinates.TargetRotation;
///
/// The target offset of camera view 3.
///
public Vector3 targetOffset3 = new Vector3(0f, 3f, -20f);
///
/// Whether camera view 3 is locked to the target position.
///
public bool lockToTargetPos3 = false;
///
/// The move speed of camera view 3.
///
public float moveSpeed3 = 15f;
///
/// Whether camera view 3 is locked to the target rotation.
///
public bool lockToTargetRot3 = false;
///
/// The turn speed of camera view 3.
///
public float turnSpeed3 = 15f;
///
/// The camera rotation mode of camera view 3.
///
public ShipCameraModule.CameraRotationMode cameraRotationMode3 = ShipCameraModule.CameraRotationMode.FollowVelocity;
///
/// The follow velocity threshold of camera view 3.
///
public float followVelocityThreshold3 = 10f;
///
/// Whether camera view 3 is oriented upwards.
///
public bool orientUpwards3 = false;
#endregion
#endregion
#region Private Variables
private ShipCameraModule shipCameraModule;
private int currentCameraViewIndex = 0;
#endregion
#region Initialisation
// Awake is called before the first frame update
void Awake()
{
// Get a reference to the ship camera module
shipCameraModule = GetComponent();
}
#endregion
#region Public Methods
///
/// Cycles the camera view.
///
public void CycleCameraView (Vector3 inputValue, int customPlayerInputEventType)
{
// Cycle the current camera view index to the next view.
currentCameraViewIndex = (currentCameraViewIndex + 1) % 3;
SetCurrentView(currentCameraViewIndex);
}
///
/// Gets the current camera view index.
/// 0 - camera view 1.
/// 1 - camera view 2.
/// 2 - camera view 3.
///
///
public int GetCurrentCameraViewIndex ()
{
return currentCameraViewIndex;
}
///
/// Gets the current camera view index.
/// 0 - camera view 1.
/// 1 - camera view 2.
/// 2 - camera view 3.
///
///
public int GetNextCameraViewIndex ()
{
return (currentCameraViewIndex + 1) % 3;
}
///
/// Set the current view using the zero-based index
/// 0 - camera view 1.
/// 1 - camera view 2.
/// 2 - camera view 3.
///
///
public void SetCurrentView(int viewIndex)
{
if (viewIndex >= 0 && viewIndex < 3 && shipCameraModule != null)
{
currentCameraViewIndex = viewIndex;
if (currentCameraViewIndex == 0)
{
// Camera view 1
// Set the camera parameters to match camera view 1
shipCameraModule.targetOffsetCoordinates = targetOffsetCoords1;
shipCameraModule.targetOffset = targetOffset1;
shipCameraModule.lockToTargetPosition = lockToTargetPos1;
shipCameraModule.moveSpeed = moveSpeed1;
shipCameraModule.lockToTargetRotation = lockToTargetRot1;
shipCameraModule.turnSpeed = turnSpeed1;
shipCameraModule.cameraRotationMode = cameraRotationMode1;
shipCameraModule.followVelocityThreshold = followVelocityThreshold1;
shipCameraModule.orientUpwards = orientUpwards1;
}
else if (currentCameraViewIndex == 1)
{
// Camera view 2
// Set the camera parameters to match camera view 2
shipCameraModule.targetOffsetCoordinates = targetOffsetCoords2;
shipCameraModule.targetOffset = targetOffset2;
shipCameraModule.lockToTargetPosition = lockToTargetPos2;
shipCameraModule.moveSpeed = moveSpeed2;
shipCameraModule.lockToTargetRotation = lockToTargetRot2;
shipCameraModule.turnSpeed = turnSpeed2;
shipCameraModule.cameraRotationMode = cameraRotationMode2;
shipCameraModule.followVelocityThreshold = followVelocityThreshold2;
shipCameraModule.orientUpwards = orientUpwards2;
}
else
{
// Camera view 3
// Set the camera parameters to match camera view 3
shipCameraModule.targetOffsetCoordinates = targetOffsetCoords3;
shipCameraModule.targetOffset = targetOffset3;
shipCameraModule.lockToTargetPosition = lockToTargetPos3;
shipCameraModule.moveSpeed = moveSpeed3;
shipCameraModule.lockToTargetRotation = lockToTargetRot3;
shipCameraModule.turnSpeed = turnSpeed3;
shipCameraModule.cameraRotationMode = cameraRotationMode3;
shipCameraModule.followVelocityThreshold = followVelocityThreshold3;
shipCameraModule.orientUpwards = orientUpwards3;
}
}
}
#endregion
}
}