126 lines
5.0 KiB
C#
126 lines
5.0 KiB
C#
using Reset.Core;
|
|
using Sirenix.OdinInspector;
|
|
using Unity.Cinemachine;
|
|
using UnityEngine;
|
|
|
|
public class CameraSettingsProcessor : MonoBehaviour{
|
|
public static CameraSettingsProcessor Instance{ get; private set; }
|
|
|
|
[HideInInspector] public static CameraSettingData data;
|
|
[HideInInspector] public static CameraSettingData original;
|
|
[ShowInInspector] public static CameraSettingData smoothing;
|
|
[ShowInInspector] public static CameraSettingData easing;
|
|
|
|
|
|
[HideInInspector] public static CameraSettingData currentSmoothing;
|
|
[HideInInspector] public static CameraSettingData currentValue;
|
|
|
|
public static GameObject mainCamera;
|
|
|
|
private CinemachineCamera main;
|
|
private CinemachineOrbitalFollow orbit;
|
|
private CinemachineRotationComposer rotComp;
|
|
private CinemachineCameraOffset offset;
|
|
private CinemachineInputAxisController axisCont;
|
|
|
|
public void Awake(){
|
|
// Singleton management
|
|
if (Instance != null && Instance != this) {
|
|
Destroy(this);
|
|
} else {
|
|
Instance = this;
|
|
}
|
|
|
|
// Set references for camera object and cinemachine components
|
|
mainCamera = gameObject;
|
|
main = mainCamera.GetComponent<CinemachineCamera>();
|
|
orbit = mainCamera.GetComponent<CinemachineOrbitalFollow>();
|
|
rotComp = mainCamera.GetComponent<CinemachineRotationComposer>();
|
|
offset = mainCamera.GetComponent<CinemachineCameraOffset>();
|
|
axisCont = mainCamera.GetComponent<CinemachineInputAxisController>();
|
|
|
|
// Initialize camera settings values from current values
|
|
data.mainFieldOfView.targetValue = main.Lens.FieldOfView;
|
|
|
|
data.orbitPositionDamping.targetValue = orbit.TrackerSettings.PositionDamping;
|
|
data.orbitTargetOffset.targetValue = orbit.TargetOffset;
|
|
|
|
data.axisLookEnabledX.targetValue = axisCont.Controllers[0].Enabled;
|
|
data.axisLookEnabledY.targetValue = axisCont.Controllers[1].Enabled;
|
|
|
|
data.axisLookGainX.targetValue = axisCont.Controllers[0].Input.Gain;
|
|
data.axisLookGainY.targetValue = axisCont.Controllers[1].Input.Gain;
|
|
|
|
data.orbitFollowTopHeight.targetValue = orbit.Orbits.Top.Height;
|
|
data.orbitFollowTopRadius.targetValue = orbit.Orbits.Top.Radius;
|
|
data.orbitFollowCenterHeight.targetValue = orbit.Orbits.Center.Height;
|
|
data.orbitFollowCenterRadius.targetValue = orbit.Orbits.Center.Radius;
|
|
data.orbitFollowBottomHeight.targetValue = orbit.Orbits.Bottom.Height;
|
|
data.orbitFollowBottomRadius.targetValue = orbit.Orbits.Bottom.Radius;
|
|
|
|
data.rotationComposerScreenPos.targetValue = rotComp.Composition.ScreenPosition;
|
|
data.cameraOffsetOffset.targetValue = offset.Offset;
|
|
|
|
// And copy to the original
|
|
original = (CameraSettingData)data.Clone();
|
|
}
|
|
|
|
void Update(){
|
|
// EaseToNewSmoothingValues();
|
|
// ProcessCameraValues();
|
|
}
|
|
|
|
void EaseToNewSmoothingValues(){
|
|
data.mainFieldOfView.SmoothAndEase();
|
|
|
|
data.orbitPositionDamping.SmoothAndEase();
|
|
data.orbitTargetOffset.SmoothAndEase();
|
|
|
|
data.axisLookGainX.SmoothAndEase();
|
|
data.axisLookGainY.SmoothAndEase();
|
|
|
|
data.orbitFollowTopHeight.SmoothAndEase();
|
|
data.orbitFollowTopRadius.SmoothAndEase();
|
|
data.orbitFollowCenterHeight.SmoothAndEase();
|
|
data.orbitFollowCenterRadius.SmoothAndEase();
|
|
data.orbitFollowBottomHeight.SmoothAndEase();
|
|
data.orbitFollowBottomRadius.SmoothAndEase();
|
|
|
|
data.rotationComposerScreenPos.SmoothAndEase();
|
|
data.cameraOffsetOffset.SmoothAndEase();
|
|
}
|
|
|
|
void ProcessCameraValues(){
|
|
main.Lens.FieldOfView = data.mainFieldOfView.Value;
|
|
|
|
axisCont.Controllers[0].Enabled = data.axisLookEnabledX.Value;
|
|
axisCont.Controllers[1].Enabled = data.axisLookEnabledY.Value;
|
|
|
|
axisCont.Controllers[0].Input.Gain = data.axisLookGainX.Value;
|
|
axisCont.Controllers[1].Input.Gain = data.axisLookGainY.Value;
|
|
|
|
orbit.TrackerSettings.PositionDamping = data.orbitPositionDamping.Value;
|
|
orbit.TargetOffset = data.orbitTargetOffset.Value;
|
|
|
|
orbit.Orbits.Top.Height = data.orbitFollowTopHeight.Value;
|
|
orbit.Orbits.Top.Radius = data.orbitFollowTopRadius.Value;
|
|
orbit.Orbits.Center.Height = data.orbitFollowCenterHeight.Value;
|
|
orbit.Orbits.Center.Radius = data.orbitFollowCenterRadius.Value;
|
|
orbit.Orbits.Bottom.Height = data.orbitFollowBottomHeight.Value;
|
|
orbit.Orbits.Bottom.Radius = data.orbitFollowBottomRadius.Value;
|
|
|
|
rotComp.Composition.ScreenPosition = data.rotationComposerScreenPos.Value;
|
|
|
|
offset.Offset = data.cameraOffsetOffset.Value;
|
|
}
|
|
|
|
[Button]
|
|
void InitializeAllSettings(){
|
|
var allSettings = data.GetAllSettings();
|
|
for (int i = 0; i < allSettings.Count; i++) {
|
|
allSettings[i].Initialize();
|
|
allSettings[i].Verify();
|
|
}
|
|
}
|
|
}
|