added: camera settings change now functional, unfinished

This commit is contained in:
Chris
2025-07-10 18:59:00 -04:00
parent ab79cd92ea
commit 1ffb90e425
4 changed files with 252 additions and 14 deletions

View File

@@ -0,0 +1,246 @@
using NodeCanvas.Framework;
using NodeCanvas.Tasks.Actions;
using ParadoxNotion.Design;
using Sirenix.OdinInspector;
using Unity.Cinemachine;
using UnityEditor;
using UnityEngine;
// TODO: Move this outta here but I don't know where to. Future organization task? There's also a shitty method down below in OnInit that calls this for every single instance of Change Camera Settings.
public static class OriginalCameraSettings{
public static float orbitFollowTopHeight;
public static float orbitFollowTopRadius;
public static float orbitFollowCenterHeight;
public static float orbitFollowCenterRadius;
public static float orbitFollowBottomHeight;
public static float orbitFollowBottomRadius;
public static Vector2 rotCompScreenPosition;
public static bool valuesSaved;
[InitializeOnEnterPlayMode]
public static void OnEnterPlaymodeInEditor(){
// Unity Play Mode contingency
valuesSaved = false;
}
public static void StashCameraOriginalSettings(GameObject cinemachine){
if (valuesSaved == false) {
CinemachineOrbitalFollow orbit = cinemachine.GetComponent<CinemachineOrbitalFollow>();
orbitFollowTopHeight = orbit.Orbits.Top.Height;
orbitFollowTopRadius = orbit.Orbits.Top.Radius;
orbitFollowCenterHeight = orbit.Orbits.Center.Height;
orbitFollowCenterRadius = orbit.Orbits.Center.Radius;
orbitFollowBottomHeight = orbit.Orbits.Bottom.Height;
orbitFollowBottomRadius = orbit.Orbits.Bottom.Radius;
CinemachineRotationComposer rotComp = cinemachine.GetComponent<CinemachineRotationComposer>();
rotCompScreenPosition = rotComp.Composition.ScreenPosition;
valuesSaved = true;
}
}
}
// Individual bool setting for each ring. Three of these will be used.
public struct OrbitalFollowValueGroup{
public string label;
public CameraSettingsToggle changeHeight;
public float height;
public CameraSettingsToggle changeRadius;
public float radius;
public OrbitalFollowValueGroup(string newLabel){
label = newLabel;
changeHeight = CameraSettingsToggle.NoChange;
height = 0f;
changeRadius = CameraSettingsToggle.NoChange;
radius = 0f;
}
}
// Enum options for individual camera settings
public enum CameraSettingsToggle{
NoChange,
NewValue,
ResetValue
}
// Custom editor for each orbital follow ring setting
public class OrbitalFollowValueGroupDrawer : ObjectDrawer<OrbitalFollowValueGroup>{
public override OrbitalFollowValueGroup OnGUI(GUIContent content, OrbitalFollowValueGroup instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 1;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(300.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(60.0f),
};
// Start a Horiztonal Section
GUILayout.BeginHorizontal();
// Add the left side label
GUILayout.Label(instance.label, labelOptions);
// Create the height settings enum
instance.changeHeight = (CameraSettingsToggle)EditorGUILayout.EnumPopup("", instance.changeHeight);
// Create the value/disabled information field
if (instance.changeHeight == CameraSettingsToggle.NewValue){
instance.height = EditorGUILayout.FloatField(instance.height, floatOptions);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(instance.changeHeight == CameraSettingsToggle.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the radius settings enum
instance.changeRadius = (CameraSettingsToggle)EditorGUILayout.EnumPopup("", instance.changeRadius);
// Create the value/disabled information field
if (instance.changeRadius == CameraSettingsToggle.NewValue){
instance.radius = EditorGUILayout.FloatField(instance.radius, floatOptions);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(instance.changeRadius == CameraSettingsToggle.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return instance;
}
}
namespace NodeCanvas.Tasks.Actions {
[Category("Reset")]
[Description("Change Cinemachine camera settings for the player")]
public class ChangeCameraSettings : ActionTask{
public BBParameter<GameObject> cinemachine;
[Space(5)]
[ParadoxNotion.Design.Header("Orbit Follow Ring Settings")]
public OrbitalFollowValueGroup orbitFollowTop = new OrbitalFollowValueGroup(newLabel: "Top");
public OrbitalFollowValueGroup orbitFollowCenter = new OrbitalFollowValueGroup(newLabel: "Center");
public OrbitalFollowValueGroup orbitFollowBottom = new OrbitalFollowValueGroup(newLabel: "Bottom");
[ParadoxNotion.Design.Header("Rotation Composer Settings")]
public bool changeScreenPosition;
[HideLabel]
public Vector2 screenPosition;
private CinemachineOrbitalFollow orbitalFollow;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
// Check if cinemachine is referenced
try {
orbitalFollow = cinemachine.value.GetComponent<CinemachineOrbitalFollow>();
} catch {
Debug.LogError("Couldn't grab all references from the camera?");
EndAction(false);
}
// Save em.
OriginalCameraSettings.StashCameraOriginalSettings(cinemachine.value);
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute(){
// Switch case farm for checking if values should be changed and what to
switch (orbitFollowTop.changeHeight) {
case CameraSettingsToggle.NewValue:
orbitalFollow.Orbits.Top.Height = orbitFollowTop.height;
break;
case CameraSettingsToggle.ResetValue:
orbitalFollow.Orbits.Top.Height = OriginalCameraSettings.orbitFollowTopHeight;
break;
}
switch (orbitFollowTop.changeRadius) {
case CameraSettingsToggle.NewValue:
orbitalFollow.Orbits.Top.Radius = orbitFollowTop.radius;
break;
case CameraSettingsToggle.ResetValue:
orbitalFollow.Orbits.Top.Radius = OriginalCameraSettings.orbitFollowTopRadius;
break;
}
switch (orbitFollowCenter.changeHeight) {
case CameraSettingsToggle.NewValue:
orbitalFollow.Orbits.Center.Height = orbitFollowCenter.height;
break;
case CameraSettingsToggle.ResetValue:
orbitalFollow.Orbits.Center.Height = OriginalCameraSettings.orbitFollowCenterHeight;
break;
}
switch (orbitFollowCenter.changeRadius) {
case CameraSettingsToggle.NewValue:
orbitalFollow.Orbits.Center.Radius = orbitFollowCenter.radius;
break;
case CameraSettingsToggle.ResetValue:
orbitalFollow.Orbits.Center.Radius = OriginalCameraSettings.orbitFollowCenterRadius;
break;
}
switch (orbitFollowBottom.changeHeight) {
case CameraSettingsToggle.NewValue:
orbitalFollow.Orbits.Bottom.Height = orbitFollowBottom.height;
break;
case CameraSettingsToggle.ResetValue:
orbitalFollow.Orbits.Bottom.Height = OriginalCameraSettings.orbitFollowBottomHeight;
break;
}
switch (orbitFollowBottom.changeRadius) {
case CameraSettingsToggle.NewValue:
orbitalFollow.Orbits.Bottom.Radius = orbitFollowBottom.radius;
break;
case CameraSettingsToggle.ResetValue:
orbitalFollow.Orbits.Bottom.Radius = OriginalCameraSettings.orbitFollowBottomRadius;
break;
}
EndAction(true);
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 87f3505b4ac62814ba2f782df47b0dbe