using System; using Reset.Core; using Sirenix.OdinInspector; using Unity.Cinemachine; using UnityEngine; public struct CameraSettingData : ICloneable{ public SettingValue mainFieldOfView; public SettingValue orbitPositionDamping; public SettingValue orbitTargetOffset; public SettingValue axisLookEnabledX; public SettingValue axisLookEnabledY; public SettingValue axisLookGainX; public SettingValue axisLookGainY; public SettingValue orbitFollowTopHeight; public SettingValue orbitFollowTopRadius; public SettingValue orbitFollowCenterHeight; public SettingValue orbitFollowCenterRadius; public SettingValue orbitFollowBottomHeight; public SettingValue orbitFollowBottomRadius; public SettingValue rotationComposerScreenPos; public SettingValue cameraOffsetOffset; public object Clone(){ return MemberwiseClone(); } } 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(); orbit = mainCamera.GetComponent(); rotComp = mainCamera.GetComponent(); offset = mainCamera.GetComponent(); axisCont = mainCamera.GetComponent(); // 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; } }