camera distance is configurable

This commit is contained in:
in0finite 2019-07-29 02:10:59 +02:00
parent d138ac9a66
commit fb302bf086
6 changed files with 39 additions and 7 deletions

View file

@ -39,12 +39,11 @@ namespace SanAndreasUnity.Behaviours
public CharacterController characterController { get; private set; }
[SerializeField] private float m_cameraDistance = 3f;
public float CameraDistance { get { return m_cameraDistance; } set { m_cameraDistance = value; } }
public float CameraDistance { get { return PedManager.Instance.cameraDistanceFromPed; } set { PedManager.Instance.cameraDistanceFromPed = value; } }
[SerializeField] private float m_cameraDistanceVehicle = 6f;
public float CameraDistanceVehicle { get { return m_cameraDistanceVehicle; } set { m_cameraDistanceVehicle = value; } }
public float CameraDistanceVehicle { get { return VehicleManager.Instance.cameraDistanceFromVehicle; } set { VehicleManager.Instance.cameraDistanceFromVehicle = value; } }
// used for clamping camera rotation
[SerializeField] private Vector2 m_cameraClampValue = new Vector2(60, 60);
public Vector2 CameraClampValue { get { return m_cameraClampValue; } set { m_cameraClampValue = value; } }

View file

@ -173,7 +173,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
public virtual void UpdateCameraZoom()
{
m_ped.CameraDistance = Mathf.Clamp(m_ped.CameraDistance - m_ped.MouseScrollInput.y, 2.0f, 32.0f);
m_ped.CameraDistance = Mathf.Clamp(m_ped.CameraDistance - m_ped.MouseScrollInput.y, PedManager.Instance.minCameraDistanceFromPed,
PedManager.Instance.maxCameraDistanceFromPed);
}
public virtual void CheckCameraCollision()

View file

@ -160,7 +160,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
public override void UpdateCameraZoom()
{
m_ped.CameraDistanceVehicle = Mathf.Clamp(m_ped.CameraDistanceVehicle - m_ped.MouseScrollInput.y, 2.0f, 32.0f);
m_ped.CameraDistanceVehicle = Mathf.Clamp(m_ped.CameraDistanceVehicle - m_ped.MouseScrollInput.y, PedManager.Instance.minCameraDistanceFromPed,
PedManager.Instance.maxCameraDistanceFromPed);
}
public override void CheckCameraCollision ()

View file

@ -13,6 +13,10 @@ namespace SanAndreasUnity.Behaviours
public float pedTurnSpeed = 10f;
public bool showPedSpeedometer = true;
public float cameraDistanceFromPed = 3f;
public float minCameraDistanceFromPed = 2f;
public float maxCameraDistanceFromPed = 30f;
[Header("Health bar")]
public bool displayHealthBarAbovePeds = false;

View file

@ -9,6 +9,8 @@ namespace SanAndreasUnity.Behaviours.Vehicles
public GameObject vehiclePrefab;
public float cameraDistanceFromVehicle = 6f;
public bool syncLinearVelocity = true;
public bool syncAngularVelocity = true;
public Utilities.WhenOnClient whenToDisableRigidBody = Utilities.WhenOnClient.OnlyOnOtherClients;

View file

@ -1,5 +1,7 @@
using UnityEngine;
using SanAndreasUnity.UI;
using SanAndreasUnity.Behaviours;
using SanAndreasUnity.Behaviours.Vehicles;
namespace SanAndreasUnity.Settings {
@ -24,15 +26,38 @@ namespace SanAndreasUnity.Settings {
setValue = (value) => { s_fieldOfView = value; if (Camera.main != null) Camera.main.fieldOfView = value; },
persistType = OptionsWindow.InputPersistType.OnStart,
};
OptionsWindow.FloatInput m_cameraDistanceFromPed = new OptionsWindow.FloatInput() {
description = "Camera distance from ped",
minValue = 0.1f,
maxValue = 100f,
getValue = () => PedManager.Instance.cameraDistanceFromPed,
setValue = (value) => { PedManager.Instance.cameraDistanceFromPed = value; },
persistType = OptionsWindow.InputPersistType.OnStart,
};
OptionsWindow.FloatInput m_cameraDistanceFromVehicle = new OptionsWindow.FloatInput() {
description = "Camera distance from vehicle",
minValue = 0.1f,
maxValue = 100f,
getValue = () => VehicleManager.Instance.cameraDistanceFromVehicle,
setValue = (value) => { VehicleManager.Instance.cameraDistanceFromVehicle = value; },
persistType = OptionsWindow.InputPersistType.OnStart,
};
void Awake ()
{
OptionsWindow.RegisterInputs ("CAMERA", m_farClipPlaneInput, m_fieldOfViewInput);
OptionsWindow.RegisterInputs ("CAMERA", m_farClipPlaneInput, m_fieldOfViewInput, m_cameraDistanceFromPed, m_cameraDistanceFromVehicle);
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (s1, s2) => OnActiveSceneChanged();
}
void Start ()
{
// assign min & max values for camera distance
m_cameraDistanceFromPed.minValue = m_cameraDistanceFromVehicle.minValue = PedManager.Instance.minCameraDistanceFromPed;
m_cameraDistanceFromPed.maxValue = m_cameraDistanceFromVehicle.maxValue = PedManager.Instance.maxCameraDistanceFromPed;
}
void OnActiveSceneChanged()
{
// apply settings