7 Commits

48 changed files with 2632 additions and 1753 deletions

View File

@@ -344,6 +344,142 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c032a18b0b0c1da4092bfc365c6e4aad, type: 3} m_Script: {fileID: 11500000, guid: c032a18b0b0c1da4092bfc365c6e4aad, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
data:
mainFieldOfView:
targetValue: 0
currentValue: 0
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitPositionDamping:
targetValue: {x: 0, y: 0, z: 0}
currentValue: {x: 0, y: 0, z: 0}
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: {x: 0, y: 0, z: 0}
defaultSmoothing: 1
defaultEasing: 2
orbitTargetOffset:
targetValue: {x: 0, y: 0, z: 0}
currentValue: {x: 0, y: 0, z: 0}
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: {x: 0, y: 0, z: 0}
defaultSmoothing: 1
defaultEasing: 2
axisLookEnabledX:
targetValue: 1
currentValue: 1
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 1
defaultSmoothing: 1
defaultEasing: 2
axisLookEnabledY:
targetValue: 1
currentValue: 1
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 1
defaultSmoothing: 1
defaultEasing: 2
axisLookGainX:
targetValue: 0
currentValue: 0
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
axisLookGainY:
targetValue: 0
currentValue: 0
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitFollowTopHeight:
targetValue: 0
currentValue: 0
targetSmoothing: 20
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitFollowTopRadius:
targetValue: 0
currentValue: 0
targetSmoothing: 20
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitFollowCenterHeight:
targetValue: 0
currentValue: 0
targetSmoothing: 20
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitFollowCenterRadius:
targetValue: 0
currentValue: 0
targetSmoothing: 20
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitFollowBottomHeight:
targetValue: 0
currentValue: 0
targetSmoothing: 20
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
orbitFollowBottomRadius:
targetValue: 0
currentValue: 0
targetSmoothing: 20
targetEasing: 2
currentSmoothing: 1
defaultValue: 0
defaultSmoothing: 1
defaultEasing: 2
rotationComposerScreenPos:
targetValue: {x: 0, y: 0}
currentValue: {x: 0, y: 0}
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: {x: 0, y: 0}
defaultSmoothing: 1
defaultEasing: 2
cameraOffsetOffset:
targetValue: {x: 0, y: 0, z: 0}
currentValue: {x: 0, y: 0, z: 0}
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: {x: 0, y: 0, z: 0}
defaultSmoothing: 1
defaultEasing: 2
--- !u!114 &4383369033389970653 --- !u!114 &4383369033389970653
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

File diff suppressed because one or more lines are too long

View File

@@ -208,50 +208,133 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b3b4e13d59527d1429a62dde97c6a001, type: 3} m_Script: {fileID: 11500000, guid: b3b4e13d59527d1429a62dde97c6a001, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
outputMoveDirection: {x: 0, y: 0, z: 0}
additionalMoveDirection: {x: 0, y: 0, z: 0}
gravitySmooth: 0
data: data:
accelerationSmoothing: 5 directionChangingSoftness:
deaccelerationSmoothing: 5 targetValue: 1
airDirectionDecay: 0 currentValue: 1
moveSpeed: 15 targetSmoothing: 1
moveSpeedSoothing: 10 targetEasing: 2
jumpPower: 0 currentSmoothing: 1
jumpPowerDecay: 3 defaultValue: 1
gravityPower: 0 defaultSmoothing: 1
gravityMax: 8 defaultEasing: 2
gravityAcceleration: 1 directionSpinningHardness:
gravityScale: 1 targetValue: 30
settingsChangeSmoothing: 6 currentValue: 30
rotateFacing: targetSmoothing: 1
rid: -2 targetEasing: 2
rotationSpeed: 5 currentSmoothing: 1
rotationSmoothing: 1 defaultValue: 3
rotationInputBlending: 0.3 defaultSmoothing: 1
defaultData: defaultEasing: 2
accelerationSmoothing: 5 directionSpinningSpeed:
deaccelerationSmoothing: 5 targetValue: 5
airDirectionDecay: 0 currentValue: 5
moveSpeed: 15 targetSmoothing: 1
moveSpeedSoothing: 10 targetEasing: 2
jumpPower: 0 currentSmoothing: 1
jumpPowerDecay: 3 defaultValue: 3
gravityPower: 0 defaultSmoothing: 1
gravityMax: 8 defaultEasing: 2
gravityAcceleration: 1 airDirectionDecay:
gravityScale: 1 targetValue: 1
settingsChangeSmoothing: 6 currentValue: 1
rotateFacing: targetSmoothing: 1
rid: -2 targetEasing: 2
rotationSpeed: 5 currentSmoothing: 1
rotationSmoothing: 1 defaultValue: 1
rotationInputBlending: 0.3 defaultSmoothing: 1
references: defaultEasing: 2
version: 2 acceleration:
RefIds: targetValue: 28
- rid: -2 currentValue: 28
type: {class: , ns: , asm: } targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 5
defaultSmoothing: 1
defaultEasing: 2
deacceleration:
targetValue: 20
currentValue: 20
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 5
defaultSmoothing: 1
defaultEasing: 2
moveSpeed:
targetValue: 15
currentValue: 15
targetSmoothing: 10
targetEasing: 2
currentSmoothing: 10
defaultValue: 15
defaultSmoothing: 10
defaultEasing: 2
gravityPower:
targetValue: 1
currentValue: 1
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 1
defaultSmoothing: 1
defaultEasing: 2
gravityMax:
targetValue: 4
currentValue: 4
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 8
defaultSmoothing: 1
defaultEasing: 2
gravityAcceleration:
targetValue: 15
currentValue: 15
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 1
defaultSmoothing: 1
defaultEasing: 2
gravityScale:
targetValue: 1
currentValue: 1
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 1
defaultSmoothing: 1
defaultEasing: 2
facingDirection:
targetValue: 4
currentValue: 4
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 4
defaultSmoothing: 1
defaultEasing: 2
rotationSpeed:
targetValue: 5
currentValue: 5
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 5
defaultSmoothing: 1
defaultEasing: 2
rotationInputBlending:
targetValue: 0.3
currentValue: 0.3
targetSmoothing: 1
targetEasing: 2
currentSmoothing: 1
defaultValue: 0.3
defaultSmoothing: 1
defaultEasing: 2
--- !u!114 &679199079481597207 --- !u!114 &679199079481597207
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -438,7 +521,7 @@ MonoBehaviour:
offset: {x: 0, y: 0.8, z: 0} offset: {x: 0, y: 0.8, z: 0}
ignoreLayers: ignoreLayers:
serializedVersion: 2 serializedVersion: 2
m_Bits: 64 m_Bits: 0
width: 0 width: 0
size: {x: 2.1, y: 2.9, z: 0.4} size: {x: 2.1, y: 2.9, z: 0.4}
rotation: {x: 9, y: 0, z: 0} rotation: {x: 9, y: 0, z: 0}
@@ -562,6 +645,7 @@ MonoBehaviour:
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"currentSpeed":{"_name":"currentSpeed","_id":"f585caab-68c5-4ead-85c4-cbc16c18655e","$type":"NodeCanvas.Framework.Variable`1[[System.Single, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"currentSpeed":{"_name":"currentSpeed","_id":"f585caab-68c5-4ead-85c4-cbc16c18655e","$type":"NodeCanvas.Framework.Variable`1[[System.Single,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"movementData":{"_propertyPath":"Reset.Units.UnitMovementHandler.data","_name":"movementData","_id":"357123c2-2d10-4425-a3c9-7341e810fc88","$type":"NodeCanvas.Framework.Variable`1[[Reset.Units.UnitMovementData, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"movementData":{"_propertyPath":"Reset.Units.UnitMovementHandler.data","_name":"movementData","_id":"357123c2-2d10-4425-a3c9-7341e810fc88","$type":"NodeCanvas.Framework.Variable`1[[Reset.Units.UnitMovementData,
Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"outputMoveDirection":{"_propertyPath":"Reset.Units.UnitMovementHandler.outputMoveDirection","_name":"outputMoveDirection","_id":"3b9833f5-870a-4182-9824-e31a9896eec2","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3, Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"outputMoveDirection":{"_propertyPath":"Reset.Units.UnitMovementHandler.outputMoveDirection","_name":"outputMoveDirection","_id":"3b9833f5-870a-4182-9824-e31a9896eec2","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"myVector3":{"_name":"myVector3","_id":"9367e2ee-ac93-43f7-9cd7-6a7cf167e07a","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}' UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}'
_objectReferences: [] _objectReferences: []
_serializedVariables: _serializedVariables:
@@ -586,6 +670,9 @@ MonoBehaviour:
- _json: '{"_propertyPath":"Reset.Units.UnitMovementHandler.outputMoveDirection","_name":"outputMoveDirection","_id":"3b9833f5-870a-4182-9824-e31a9896eec2","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3, - _json: '{"_propertyPath":"Reset.Units.UnitMovementHandler.outputMoveDirection","_name":"outputMoveDirection","_id":"3b9833f5-870a-4182-9824-e31a9896eec2","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}' UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
_references: [] _references: []
- _json: '{"_name":"myVector3","_id":"9367e2ee-ac93-43f7-9cd7-6a7cf167e07a","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Vector3,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
_references: []
--- !u!114 &43868462096200776 --- !u!114 &43868462096200776
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -2971,19 +2971,19 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.9996973 value: 0.99973595
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.024602825 value: -0.022979952
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.000000011836157 value: 3.1949018e-10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 2.9129085e-10 value: 7.3437315e-12
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 1478733240008970968, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x
@@ -3001,6 +3001,10 @@ PrefabInstance:
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 5 value: 5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3229831872226355039, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: Composition.ScreenPosition.y
value: 0.14794445
objectReference: {fileID: 0}
- target: {fileID: 3716971538123186913, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 3716971538123186913, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: CameraGroup value: CameraGroup
@@ -3019,24 +3023,48 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.9996973 value: 0.99973595
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.024602825 value: -0.022979954
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.000000011836157 value: 3.1949024e-10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 2.9129105e-10 value: 7.34381e-12
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} - target: {fileID: 5136833180492354989, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x
value: -89 value: -89
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7070283194321853303, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: data.orbitFollowTopHeight.targetSmoothing
value: 20
objectReference: {fileID: 0}
- target: {fileID: 7070283194321853303, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: data.orbitFollowTopRadius.targetSmoothing
value: 20
objectReference: {fileID: 0}
- target: {fileID: 7070283194321853303, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: data.orbitFollowBottomHeight.targetSmoothing
value: 20
objectReference: {fileID: 0}
- target: {fileID: 7070283194321853303, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: data.orbitFollowBottomRadius.targetSmoothing
value: 20
objectReference: {fileID: 0}
- target: {fileID: 7070283194321853303, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: data.orbitFollowCenterHeight.targetSmoothing
value: 20
objectReference: {fileID: 0}
- target: {fileID: 7070283194321853303, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3}
propertyPath: data.orbitFollowCenterRadius.targetSmoothing
value: 20
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []

View File

@@ -9,32 +9,36 @@ namespace NodeCanvas.Tasks.Actions {
[Category("Reset")] [Category("Reset")]
[Description("Change Cinemachine camera settings for the player")] [Description("Change Cinemachine camera settings for the player")]
public class ChangeCameraSettings : ActionTask{ public class ChangeCameraSettings : ActionTask{
[ParadoxNotion.Design.Header("Main Settings")] [ParadoxNotion.Design.Header("Main Settings"), Space(8)]
public FloatValueGroup fieldOfView = new (newLabel: "FOV"); public FloatValueGroup fieldOfView = new (newLabel: "FOV");
[ParadoxNotion.Design.Header("Orbit Follow Ring Settings"), Space (5)]
public Vector3ValueGroup orbitTargetOffset = new(newLabel: "Target Offset"); public Vector3ValueGroup orbitTargetOffset = new(newLabel: "Target Offset");
[Space(5)]public Vector3ValueGroup orbitPositionDamping = new(newLabel: "Position Damping"); [Space(5)]public Vector3ValueGroup orbitPositionDamping = new(newLabel: "Position Damping");
public OrbitalFollowValueGroup orbitFollowTop = new (newLabel: "Top"); [ParadoxNotion.Design.Header("Orbit Follow Ring Settings"), Space (5)]
public OrbitalFollowValueGroup orbitFollowCenter = new (newLabel: "Center"); public OrbitalFollowValueGroup orbitFollowTop = new (newLabel: "Top Ring");
public OrbitalFollowValueGroup orbitFollowBottom = new (newLabel: "Bottom"); public OrbitalFollowValueGroup orbitFollowCenter = new (newLabel: "Top Ring");
[Space(8)]
public OrbitalFollowValueGroup orbitFollowBottom = new (newLabel: "Top Ring");
public BoolValueGroup enableXAxis = new (newLabel: "Input Axis X Enabled"); public BoolValueGroup enableXAxis = new (newLabel: "Input Axis X Enabled");
public BoolValueGroup enableYAxis = new (newLabel: "Input Axis Y Enabled"); public BoolValueGroup enableYAxis = new (newLabel: "Input Axis Y Enabled");
public FloatValueGroup axisLookXGain = new (newLabel: "Look Orbit X Gain"); public FloatValueGroup axisLookXGain = new (newLabel: "Look Orbit X Gain");
public FloatValueGroup axisLookYGain = new (newLabel: "Look Orbit Y Gain"); public FloatValueGroup axisLookYGain = new (newLabel: "Look Orbit Y Gain");
[ParadoxNotion.Design.Header("Rotation Composer Settings")] [ParadoxNotion.Design.Header("Rotation Composer Settings"), Space(8)]
public Vector2ValueGroup screenPosition = new (newLabel: "Screen Position"); public Vector2ValueGroup screenPosition = new (newLabel: "Screen Position");
[ParadoxNotion.Design.Header("Camera Offset Settings")] [ParadoxNotion.Design.Header("Camera Offset Settings"), Space(8)]
public Vector3ValueGroup cameraOffset = new (newLabel: "Offset"); public Vector3ValueGroup cameraOffset = new (newLabel: "Offset");
private CameraSettingsProcessor processor;
//Use for initialization. This is called only once in the lifetime of the task. //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 //Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){ protected override string OnInit(){
processor = CameraSettingsProcessor.Instance;
return null; return null;
} }
@@ -42,119 +46,28 @@ namespace NodeCanvas.Tasks.Actions {
//Call EndAction() to mark the action as finished, either in success or failure. //Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere. //EndAction can be called from anywhere.
protected override void OnExecute(){ protected override void OnExecute(){
UpdateOrbitFollowValue(orbitFollowTop, ref CameraSettingsProcessor.values.orbitFollowTopHeight, ref CameraSettingsProcessor.values.orbitFollowTopRadius); OrbitalFollowValueGroup.UpdateValue(orbitFollowTop, processor.data.orbitFollowTopHeight, processor.data.orbitFollowTopRadius);
UpdateOrbitFollowValue(orbitFollowCenter, ref CameraSettingsProcessor.values.orbitFollowCenterHeight, ref CameraSettingsProcessor.values.orbitFollowCenterRadius); OrbitalFollowValueGroup.UpdateValue(orbitFollowCenter, processor.data.orbitFollowCenterHeight, processor.data.orbitFollowCenterRadius);
UpdateOrbitFollowValue(orbitFollowBottom, ref CameraSettingsProcessor.values.orbitFollowBottomHeight, ref CameraSettingsProcessor.values.orbitFollowBottomRadius); OrbitalFollowValueGroup.UpdateValue(orbitFollowBottom, processor.data.orbitFollowBottomHeight, processor.data.orbitFollowBottomRadius);
UpdateVector3Value(cameraOffset, ref CameraSettingsProcessor.values.cameraOffsetOffset); Vector3ValueGroup.UpdateValue(cameraOffset, processor.data.cameraOffsetOffset);
UpdateVector3Value(orbitPositionDamping, ref CameraSettingsProcessor.values.orbitPositionDamping); Vector3ValueGroup.UpdateValue(orbitPositionDamping, processor.data.orbitPositionDamping);
UpdateVector3Value(orbitTargetOffset, ref CameraSettingsProcessor.values.orbitTargetOffset); Vector3ValueGroup.UpdateValue(orbitTargetOffset, processor.data.orbitTargetOffset);
UpdateVector2Value(screenPosition, ref CameraSettingsProcessor.values.rotationComposerScreenPos); Vector2ValueGroup.UpdateValue(screenPosition, processor.data.rotationComposerScreenPos);
UpdateFloatValue(fieldOfView, ref CameraSettingsProcessor.values.mainFieldOfView);
UpdateFloatValue(axisLookXGain, ref CameraSettingsProcessor.values.axisLookGainX); FloatValueGroup.UpdateValue(fieldOfView, processor.data.mainFieldOfView);
UpdateFloatValue(axisLookYGain, ref CameraSettingsProcessor.values.axisLookGainY);
UpdateBoolValue(enableXAxis, ref CameraSettingsProcessor.values.axisLookEnabledX); FloatValueGroup.UpdateValue(axisLookXGain, processor.data.axisLookGainX);
UpdateBoolValue(enableYAxis, ref CameraSettingsProcessor.values.axisLookEnabledY); FloatValueGroup.UpdateValue(axisLookYGain, processor.data.axisLookGainY);
BoolValueGroup.UpdateValue(enableXAxis, processor.data.axisLookEnabledX);
BoolValueGroup.UpdateValue(enableYAxis, processor.data.axisLookEnabledY);
EndAction(true); EndAction(true);
} }
public void UpdateVector3Value(Vector3ValueGroup valueGroup, ref CameraSettingSingleValue<Vector3> targetProperty){
switch (valueGroup.changeX) {
case ValueChangeAction.NewValue:
targetProperty.targetValue.x = valueGroup.newValue.x;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue.x = targetProperty.originalValue.x;
break;
}
switch (valueGroup.changeY) {
case ValueChangeAction.NewValue:
targetProperty.targetValue.y = valueGroup.newValue.y;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue.y = targetProperty.originalValue.y;
break;
}
switch (valueGroup.changeZ) {
case ValueChangeAction.NewValue:
targetProperty.targetValue.z = valueGroup.newValue.z;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue.z = targetProperty.originalValue.z;
break;
}
}
public void UpdateVector2Value(Vector2ValueGroup valueGroup, ref CameraSettingSingleValue<Vector2> targetProperty){
switch (valueGroup.changeX) {
case ValueChangeAction.NewValue:
targetProperty.targetValue.x = valueGroup.newValue.x;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue.x = targetProperty.originalValue.x;
break;
}
switch (valueGroup.changeY) {
case ValueChangeAction.NewValue:
targetProperty.targetValue.y = valueGroup.newValue.y;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue.y = targetProperty.originalValue.y;
break;
}
}
public void UpdateOrbitFollowValue(OrbitalFollowValueGroup valueGroup, ref CameraSettingSingleValue<float> targetHeight, ref CameraSettingSingleValue<float> targetRadius){
switch (valueGroup.changeHeight) {
case ValueChangeAction.NewValue:
targetHeight.targetValue = valueGroup.height;
break;
case ValueChangeAction.ResetValue:
targetHeight.targetValue = targetHeight.originalValue;
break;
}
switch (valueGroup.changeRadius) {
case ValueChangeAction.NewValue:
targetRadius.targetValue = valueGroup.radius;
break;
case ValueChangeAction.ResetValue:
targetRadius.targetValue = targetRadius.originalValue;
break;
}
}
public void UpdateBoolValue(BoolValueGroup valueGroup, ref CameraSettingSingleValue<bool> targetProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty.targetValue = valueGroup.value;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue = targetProperty.originalValue;
break;
}
}
public void UpdateFloatValue(FloatValueGroup valueGroup, ref CameraSettingSingleValue<float> targetProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty.targetValue = valueGroup.value.value;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue = targetProperty.originalValue;
break;
}
}
//Called once per frame while the action is active. //Called once per frame while the action is active.
protected override void OnUpdate() { protected override void OnUpdate() {

View File

@@ -1,235 +0,0 @@
using System;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using Reset.Units;
using UnityEngine;
namespace Reset.Core {
[Category("Reset")]
[Description("Commits movement unit changes to the handler.")]
public class ChangeMovementSettings : ActionTask<UnitMovementHandler> {
// Move Speed
[ParadoxNotion.Design.Header("Speed")]
public FloatValueGroup moveSpeed = new (newLabel: "Move Speed");
public FloatValueGroup moveSpeedSoothing = new (newLabel: "Move Speed Smoothing");
[ParadoxNotion.Design.Header("Direction")]
public FloatValueGroup airDirectionDecay = new FloatValueGroup("Air Direction Decay");
public FloatValueGroup accelerationSmoothing = new (newLabel: "Acceleration Smoothing");
public FloatValueGroup deaccelerationSmoothing = new (newLabel: "Deacceleration Smoothing");
// public CurveValueGroup deaccelerationCurve = new (newLabel: "Deacceleration Curve"); // Currently unused, may return
// Direction
[Space(5)]
public Vector3ValueGroup feedNewDirection = new Vector3ValueGroup("Feed New Direction");
public float newDirectionStrength;
[Space(5)]
public Vector2 addDirectionFromInput;
public float addInputStrength;
[SliderField(0,1)]
public float addInputPriorty;
// Jumping
[ParadoxNotion.Design.Header("Jumping")]
public FloatValueGroup jumpPower = new (newLabel: "Jump Power");
public FloatValueGroup jumpPowerDecay = new (newLabel: "Jump Decay Speed");
// Gravity
[ParadoxNotion.Design.Header("Gravity")]
public FloatValueGroup gravityPower = new (newLabel: "Gravity Power");
public FloatValueGroup gravityMax = new (newLabel: "Gravity Max");
public FloatValueGroup gravityAcceleration = new (newLabel: "Gravity Acceleration Speed");
public FloatValueGroup gravityScale = new (newLabel: "Gravity Scale");
public FloatValueGroup settingsChangeSmoothing = new(newLabel: "Settings Change Smoothing");
// Rotation
[ParadoxNotion.Design.Header("Rotation")]
public EnumValueGroup rotateFacing = new EnumValueGroup("Facing Direction", PlayerFacingDirection.TowardsTarget);
public FloatValueGroup rotationSpeed = new (newLabel: "Rotation Speed");
public FloatValueGroup rotationSmoothing = new (newLabel: "Rotation Smoothing");
public FloatValueGroup rotationInputBlending = new("Rotation Input Blending");
[Space(5)]
public BBParameter<Vector3> feedNewRotation;
public BBParameter<Vector3> feedRelativeTo;
public Space rotationRelativeSpace;
private Vector3 feedDir;
protected override string OnInit() {
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() {
// Direction
UpdateFloatValue(airDirectionDecay, ref agent.data.airDirectionDecay, ref agent.data.airDirectionDecay);
UpdateFloatValue(accelerationSmoothing, ref agent.data.accelerationSmoothing, ref agent.defaultData.accelerationSmoothing);
UpdateFloatValue(deaccelerationSmoothing, ref agent.data.deaccelerationSmoothing, ref agent.defaultData.deaccelerationSmoothing);
// UpdateCurveProperty(deaccelerationCurve, ref agent.data.deaccelerationCurve, ref agent.defaultData.deaccelerationCurve); // Currently unused, may return
// Direction from value
// Check that feedDir is not changed
UpdateVector3Value(feedNewDirection, ref feedDir, ref feedDir);
// If there's a direciton add it to the player for a frame
if (feedDir != Vector3.zero) {
agent.AddToCurrentDirection(agent.transform.rotation * feedDir.normalized, newDirectionStrength);
// Reset the fed direction after it's added so future runs don't have
feedDir = Vector3.zero;
}
// Direction from controller input
if (addDirectionFromInput != Vector2.zero){
agent.OverwriteDirectionFromInput(new Vector3(addDirectionFromInput.x, addDirectionFromInput.y), addInputPriorty, addInputStrength);
}
// Move Speed
UpdateFloatValue(moveSpeed, ref agent.data.moveSpeed, ref agent.defaultData.moveSpeed);
UpdateFloatValue(moveSpeedSoothing, ref agent.data.moveSpeedSoothing, ref agent.defaultData.moveSpeedSoothing);
// Jump
UpdateFloatValue(jumpPower, ref agent.data.jumpPower, ref agent.defaultData.jumpPower);
UpdateFloatValue(jumpPowerDecay, ref agent.data.jumpPowerDecay, ref agent.defaultData.jumpPowerDecay);
// Gravity
UpdateFloatValue(gravityPower, ref agent.data.gravityPower, ref agent.defaultData.gravityPower);
UpdateFloatValue(gravityMax, ref agent.data.gravityMax, ref agent.defaultData.gravityMax);
UpdateFloatValue(gravityAcceleration, ref agent.data.gravityAcceleration, ref agent.defaultData.gravityAcceleration);
UpdateFloatValue(gravityScale, ref agent.data.gravityScale, ref agent.defaultData.gravityScale);
UpdateFloatValue(settingsChangeSmoothing, ref agent.data.settingsChangeSmoothing, ref agent.defaultData.settingsChangeSmoothing);
// Rotation
UpdateEnumValue(rotateFacing, ref agent.data.rotateFacing, ref agent.defaultData.rotateFacing);
UpdateFloatValue(rotationSpeed, ref agent.data.rotationSpeed, ref agent.defaultData.rotationSpeed);
UpdateFloatValue(rotationSmoothing, ref agent.data.rotationSmoothing, ref agent.defaultData.rotationSmoothing);
UpdateFloatValue(rotationInputBlending, ref agent.data.rotationInputBlending, ref agent.defaultData.rotationInputBlending);
// Rotation from value
if (feedNewRotation.value != Vector3.zero) {
if (rotationRelativeSpace == Space.World) {
Debug.Log(Quaternion.LookRotation(feedRelativeTo.value));
agent.SetSpecifiedRotation(Quaternion.Euler(feedNewRotation.value) * Quaternion.LookRotation(feedRelativeTo.value));
} else {
agent.SetSpecifiedRotation(agent.transform.rotation * Quaternion.Euler(feedNewRotation.value) * Quaternion.LookRotation(feedRelativeTo.value));
}
}
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() {
}
public void UpdateCurveProperty(CurveValueGroup valueGroup, ref AnimationCurve targetProperty, ref AnimationCurve defaultProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NoChange:
break;
case ValueChangeAction.NewValue:
targetProperty = valueGroup.newValue;
break;
case ValueChangeAction.ResetValue:
targetProperty = defaultProperty;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public void UpdateVector3Value(Vector3ValueGroup valueGroup, ref Vector3 targetProperty, ref Vector3 defaultProperty){
switch (valueGroup.changeX) {
case ValueChangeAction.NewValue:
targetProperty.x = valueGroup.newValue.x;
break;
case ValueChangeAction.ResetValue:
targetProperty.x = defaultProperty.x;
break;
}
switch (valueGroup.changeY) {
case ValueChangeAction.NewValue:
targetProperty.y = valueGroup.newValue.y;
break;
case ValueChangeAction.ResetValue:
targetProperty.y = defaultProperty.y;
break;
}
switch (valueGroup.changeZ) {
case ValueChangeAction.NewValue:
targetProperty.z = valueGroup.newValue.z;
break;
case ValueChangeAction.ResetValue:
targetProperty.z = defaultProperty.z;
break;
}
}
public void UpdateVector2Value(Vector2ValueGroup valueGroup, ref Vector2 targetProperty, ref Vector2 defaultProperty){
switch (valueGroup.changeX) {
case ValueChangeAction.NewValue:
targetProperty.x = valueGroup.newValue.x;
break;
case ValueChangeAction.ResetValue:
targetProperty.x = defaultProperty.x;
break;
}
switch (valueGroup.changeY) {
case ValueChangeAction.NewValue:
targetProperty.y = valueGroup.newValue.y;
break;
case ValueChangeAction.ResetValue:
targetProperty.y = defaultProperty.y;
break;
}
}
public void UpdateBoolValue(BoolValueGroup valueGroup, ref bool targetProperty, ref bool defaultProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty = valueGroup.value;
break;
case ValueChangeAction.ResetValue:
targetProperty = defaultProperty;
break;
}
}
public void UpdateEnumValue(EnumValueGroup valueGroup, ref Enum targetProperty, ref Enum defaultProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty = valueGroup.newValue;
break;
case ValueChangeAction.ResetValue:
targetProperty = defaultProperty;
break;
}
}
public void UpdateFloatValue(FloatValueGroup valueGroup, ref float targetProperty, ref float defaultProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty = valueGroup.value.value;
break;
case ValueChangeAction.ResetValue:
targetProperty = defaultProperty;
break;
}
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 5132a76af4f722e49bc7fbbc75edcaf1

View File

@@ -69,7 +69,7 @@ namespace NodeCanvas.Tasks.Actions {
directionOnStart = agent.transform.position.DirectionTo(grapplePoint.value); directionOnStart = agent.transform.position.DirectionTo(grapplePoint.value);
// Get the current move direction // Get the current move direction
velocityOnStart = agent.outputMoveDirection; // velocityOnStart = agent.outputMoveDirection; // NOTE: Deprecated by new movement values
// For setting finalDirection's initial value, first compose the swing variables one-time // For setting finalDirection's initial value, first compose the swing variables one-time
Vector3 velocityWhenMoving = CalculateSwingDirections(Vector3.Distance(agent.transform.position, grapplePoint.value), directionOnStart); Vector3 velocityWhenMoving = CalculateSwingDirections(Vector3.Distance(agent.transform.position, grapplePoint.value), directionOnStart);
@@ -86,7 +86,7 @@ namespace NodeCanvas.Tasks.Actions {
//Called once per frame while the action is active. //Called once per frame while the action is active.
protected override void OnUpdate(){ protected override void OnUpdate(){
agent.outputMoveDirection = Vector3.MoveTowards(agent.outputMoveDirection, Vector3.zero, .5f); // agent.outputMoveDirection = Vector3.MoveTowards(agent.outputMoveDirection, Vector3.zero, .5f); // NOTE: Deprecated by new movement values
// Basic variables, direction to point and current distnace // Basic variables, direction to point and current distnace
Vector3 directionToPoint = agent.transform.position.DirectionTo(grapplePoint.value); Vector3 directionToPoint = agent.transform.position.DirectionTo(grapplePoint.value);
@@ -178,7 +178,7 @@ namespace NodeCanvas.Tasks.Actions {
gizmoFinalDirection = finalDirection; gizmoFinalDirection = finalDirection;
// Finalize the movement to the controller // Finalize the movement to the controller
agent.SetNewDirection(Vector3.Lerp(agent.additionalMoveDirection, finalDirection.Flatten(null, 0), 1f * Time.deltaTime)); // agent.SetNewDirection(Vector3.Lerp(agent.additionalMoveDirection, finalDirection.Flatten(null, 0), 1f * Time.deltaTime)); // NOTE: Deprecated by new movement values
agent.SetNewGravity(finalDirection.y); agent.SetNewGravity(finalDirection.y);
agent.SmoothToSpeed(speed, 25f * Time.deltaTime); agent.SmoothToSpeed(speed, 25f * Time.deltaTime);

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7879b20d5bcdf974c823d1919491e026
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using Reset.Core;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
public class ChangeDirectionSettings : ActionTask<UnitMovementHandler> {
// Direction
[Space(5)]
public FloatValueGroup directionChangingSoftness = new FloatValueGroup("Direction Changing Softness");
public FloatValueGroup directionSpinningHardness = new FloatValueGroup("Direction Spinning Hardness");
public FloatValueGroup directionSpinningSpeed = new FloatValueGroup("Direction Spinning Speed");
//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() {
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() {
FloatValueGroup.UpdateValue(directionChangingSoftness, agent.data.directionChangingSoftness);
FloatValueGroup.UpdateValue(directionSpinningHardness, agent.data.directionSpinningHardness);
FloatValueGroup.UpdateValue(directionSpinningSpeed, agent.data.directionSpinningSpeed);
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: e97f34b81238a9548b0bf4f5b68c8f17

View File

@@ -0,0 +1,48 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using Reset.Core;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
public class ChangeGravitySettings : ActionTask<UnitMovementHandler>{
[SliderField(0f, 1f), SerializeField] public FloatValueGroup airDirectionDecay = new FloatValueGroup("Air Direction Decay");
[SerializeField] public FloatValueGroup gravityMax = new FloatValueGroup("Gravity Max");
[SerializeField] public FloatValueGroup gravityAcceleration = new FloatValueGroup("Gravity Acceleration");
[SerializeField] public FloatValueGroup gravityScale = new FloatValueGroup("Gravity Scale");
//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() {
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() {
FloatValueGroup.UpdateValue(airDirectionDecay, agent.data.airDirectionDecay);
FloatValueGroup.UpdateValue(gravityMax, agent.data.gravityMax);
FloatValueGroup.UpdateValue(gravityAcceleration, agent.data.gravityAcceleration);
FloatValueGroup.UpdateValue(gravityScale, agent.data.gravityScale);
}
//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: 67c9324e429e09f4da157ab85dadacff

View File

@@ -0,0 +1,46 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using Reset.Core;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
public class ChangeMoveSpeedSettings : ActionTask<UnitMovementHandler> {
[SerializeField] public FloatValueGroup moveSpeed = new (newLabel: "Move Speed");
[SerializeField] public FloatValueGroup acceleration = new (newLabel: "Acceleration");
[SerializeField] public FloatValueGroup deacceleration = new (newLabel: "Deacceleration");
//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() {
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() {
FloatValueGroup.UpdateValue(moveSpeed, agent.data.moveSpeed);
FloatValueGroup.UpdateValue(acceleration, agent.data.acceleration);
FloatValueGroup.UpdateValue(deacceleration, agent.data.deacceleration);
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: c1f858e8bdedb4f46ac3e10c0dccde29

View File

@@ -1,27 +1,19 @@
using System;
using NodeCanvas.Framework; using NodeCanvas.Framework;
using ParadoxNotion.Design; using ParadoxNotion.Design;
using Reset.Core;
using UnityEngine; using UnityEngine;
namespace Reset.Movement { namespace Reset.Units {
[Category("Reset/Movement")] [Category("Reset/Movement")]
[Description("Updates the movespeed for this agent")] public class ChangeRotationSettings : ActionTask<UnitMovementHandler> {
public class UpdateMovementSpeed : ActionTask{ [SerializeField] public EnumValueGroup facingDirection = new EnumValueGroup("Facing Direction", PlayerFacingDirection.TowardsTarget);
public BBParameter<float> target; [SerializeField] public FloatValueGroup rotationSpeed = new (newLabel: "Rotation Speed");
public BBParameter<float> speed;
public BBParameter<float> smoothing = 10f;
private float currentSpeed;
//Use for initialization. This is called only once in the lifetime of the task. //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 //Return null if init was successfull. Return an error string otherwise
protected override string OnInit() { protected override string OnInit() {
if (!speed.useBlackboard) {
Debug.LogError("This <b>Update Movement Speed</b> does not have it's current value attached to a Blackboard variable. Nothing will happen.", agent.gameObject);
}
return null; return null;
} }
@@ -29,22 +21,15 @@ namespace Reset.Movement {
//Call EndAction() to mark the action as finished, either in success or failure. //Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere. //EndAction can be called from anywhere.
protected override void OnExecute(){ protected override void OnExecute(){
// currentSpeed = speed.value; EnumValueGroup.UpdateValue(facingDirection, agent.data.facingDirection);
FloatValueGroup.UpdateValue(rotationSpeed, agent.data.rotationSpeed);
EndAction(true);
} }
//Called once per frame while the action is active. //Called once per frame while the action is active.
protected override void OnUpdate(){ protected override void OnUpdate() {
currentSpeed = Mathf.Lerp(currentSpeed, target.value, smoothing.value * Time.deltaTime);
speed.value = currentSpeed;
if (Mathf.Abs(currentSpeed - speed.value) < .01f) {
}
Debug.Log("Speed Done");
EndAction(true);
} }
//Called when the task is disabled. //Called when the task is disabled.

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2af547219746e194f97217fe24cfb8cd

View File

@@ -0,0 +1,57 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
[Description("Set a new direction value for this agent, either additively, absolutely, or relatively.")]
public class SetNewDirection : ActionTask<UnitMovementHandler> {
public BBParameter<Vector2> newDirection;
[Tooltip("Setting absolute to true will cause the resolved movement direction to snap to the new gravity value. Keeping it false will make it apply additively to the resolved movement direction. Both options use relativty for linear interpolation.")]
public BBParameter<bool> absolute;
[Tooltip("Higher relativity means more of the new value is used. Value of 1 will set it to the value directly, while .5 will blend halfway between.")]
[SliderField(0, 1)]
public BBParameter<float> relativity;
[Tooltip("Setting raw direciton will affect things that read the raw direction like rotation")]
public BBParameter<bool> setRawAsWell;
[Tooltip("This is set as a Vector3 but will be translated into a Vector2 on execute")]
public BBParameter<Vector3> relativeTo;
//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() {
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() {
agent.SetNewDirection(newDirection.value, relativity.value, absolute.value, relativeTo.value.ToVector2());
if (setRawAsWell.value) {
agent.SetNewRawDirection(newDirection.value, relativity.value, absolute.value, relativeTo.value.ToVector2());
}
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: fd070de4d2cacf64b8c520e98c8e4138

View File

@@ -0,0 +1,45 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
[Description("Sets a new value for gravity. Additively, or absolutely.")]
public class SetNewGravity : ActionTask<UnitMovementHandler>{
public BBParameter<float> newGravity;
[Tooltip("Setting absolute to true will cause the resolved movement gravity to snap to the new gravity value. Keeping it false will make it apply additively to the resolved movement gravity. Both options use relativty for linear interpolation.")]
public BBParameter<bool> absolute;
[Tooltip("Higher relativity means more of the new value is used. Value of 1 will set it to the value directly, while .5 will blend halfway between.")]
[SliderField(0, 1)]
public BBParameter<float> relativity;
//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() {
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() {
agent.SetNewGravity(newGravity.value, relativity.value, absolute.value);
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: ebaf22f2865425e4c8f10f444ae83c21

View File

@@ -0,0 +1,49 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
[Description("Set a new rotation value for this agent, either additively, absolutely, or relatively.")]
public class SetNewRotation : ActionTask<UnitMovementHandler> {
public BBParameter<Quaternion> newRotation;
[Tooltip("Setting absolute to true will cause the resolved movement rotation to snap to the new gravity value. Keeping it false will make it apply additively to the resolved movement rotation. Both options use relativty for linear interpolation.")]
public BBParameter<bool> absolute;
[Tooltip("Higher relativity means more of the new value is used. Value of 1 will set it to the value directly, while .5 will blend halfway between.")]
[SliderField(0, 1)]
public BBParameter<float> relativity;
public BBParameter<Quaternion> relativeTo;
//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() {
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() {
agent.SetNewRotation(newRotation.value, relativity.value, absolute.value, relativeTo.value);
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: 66d712031a5b8834c96bbf7bb79048fb

View File

@@ -0,0 +1,47 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace Reset.Units {
[Category("Reset/Movement")]
[Description("Set a new speed value for this agent, either additively, absolutely, or relatively.")]
public class SetNewSpeed : ActionTask<UnitMovementHandler> {
public BBParameter<float> newSpeed;
[Tooltip("Setting absolute to true will cause the resolved movement speed to snap to the new speed value. Keeping it false will make it apply additively to the resolved movement speed. Both options use relativty for linear interpolation.")]
public BBParameter<bool> absolute;
[Tooltip("Higher relativity means more of the new value is used. Value of 1 will set it to the value directly, while .5 will blend halfway between.")]
[SliderField(0, 1)]
public BBParameter<float> relativity;
//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() {
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() {
agent.SetNewGravity(newSpeed.value, relativity.value, absolute.value);
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: 605f812405d9b7d4c87c80ce8e41a056

View File

@@ -1,71 +0,0 @@
using System;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using Reset.Movement;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Movement")]
[Description("Launch the agent towards a specific point with respect to distance.")]
public class StartLaunchJump : ActionTask<CharacterController>{
public BBParameter<Vector3> airDirection;
public BBParameter<float> jumpPower;
public BBParameter<Vector3> targetLocation;
public BBParameter<Vector3> offset;
public BBParameter<Vector3> relativeRotation;
public BBParameter<PlayerFacingDirection> launchRelativeTo;
public BBParameter<bool> useRelativeForce;
[ShowIf("useRelativeForce", 1)] public BBParameter<float> minimumForce;
[ShowIf("useRelativeForce", 1)] public BBParameter<float> maximumForce;
[ShowIf("useRelativeForce", 1)] public BBParameter<float> forceRelativeToDistance;
public BBParameter<float> force;
//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() {
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(){
Vector3 launchDir = agent.transform.position.DirectionTo(targetLocation.value).normalized;
launchDir = Quaternion.Euler(relativeRotation.value) * launchDir;
Debug.Log(launchDir);
float distanceToTarget = Vector3.Distance(agent.transform.position, targetLocation.value);
float outputForce = (useRelativeForce.value ? distanceToTarget * forceRelativeToDistance.value : force.value);
outputForce = Mathf.Clamp(outputForce, minimumForce.value, maximumForce.value);
jumpPower.value = outputForce;
airDirection.value = (launchDir * outputForce);
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

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 8f32fe451feb2ca4e8159d4aa8919cd2

View File

@@ -1,73 +0,0 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Services;
using UnityEngine;
namespace Reset.Movement {
[Category("Reset/Movement")]
[Description("Process Y-axis movement for the agent")]
// TODO: Rename to UpdateGravitytDirection
public class UpdateGravityDirection : ActionTask<CharacterController>{
public BBParameter<Vector3> moveDirection;
public BBParameter<float> jumpPower;
public BBParameter<float> jumpPowerDecay;
[Space(5)]
public BBParameter<float> gravityAcceleration = 1f;
public BBParameter<float> gravityMax = 8f;
public BBParameter<float> gravityPower;
//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() {
MonoManager.current.onLateUpdate += LateUpdate;
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() {
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
// Accelerate gravity
gravityPower.value += gravityAcceleration.value * Time.deltaTime;
gravityPower.value = Mathf.Min(gravityPower.value, gravityMax.value);
// Apply a constant gravity if the player is grounded
if (agent.isGrounded) {
gravityPower.value = .1f;
}
// Create the gravity direction
float gravityMoveDirection = jumpPower.value + Physics.gravity.y * gravityPower.value;
// Commit gravity to move direction, ignoring XZ since those are done in UpdateMovementDirection
moveDirection.value = new Vector3(moveDirection.value.x, gravityMoveDirection, moveDirection.value.z);
Debug.Log("Gravity Done");
EndAction(true);
}
public void LateUpdate(){
// Decay jump power
jumpPower.value = Mathf.Lerp(jumpPower.value, 0f, jumpPowerDecay.value * Time.deltaTime);
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 5531fbd949d33204690c98dd89a5e97f

View File

@@ -1,118 +0,0 @@
using System;
using System.Collections;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Services;
using Unity.Cinemachine;
using Unity.Mathematics;
using UnityEngine;
using Reset.Movement;
using Reset.Units;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Movement")]
[Description("Finalizes movement and sends the final move commands to the controller")]
// TODO: Rename to UpdateMovementDirection
public class UpdateMovementDirection : ActionTask<CharacterController>{
[ParadoxNotion.Design.Header("References")]
public BBParameter<Vector3> moveDirection;
// TODO: Remove this reference and let each copy of this use their own settings.
public BBParameter<PlayerFacingDirection> playerFacingDirection;
[ParadoxNotion.Design.Header("Settings")]
public BBParameter<float> accelerationSmoothing = 5f;
public BBParameter<float> deaccelerationSmoothing = 5f;
public BBParameter<AnimationCurve> deaccelerationCurve;
public BBParameter<float> directionChangeMinimumMagnitude; // Unused. Use to only make input change if it's over a certain input threshold. Maybe smoothing can affect this?
private float lastLookMagnitude;
private Vector3 currentMoveDir;
// References
private PlayerControls controls;
//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() {
// Reference to controls
controls = agent.GetComponent<PlayerControls>();
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(){
// Initialize the smoothed direction with the value as is on input
// currentMoveDir = new Vector3(moveDirection.value.x, moveDirection.value.y, moveDirection.value.z);
}
//Called once per frame while the action is active.
protected override void OnUpdate(){
// Construct move direction
Vector3 targetDirection = moveDirection.value;
// Get input value
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
if (inputMovement.magnitude < .1f) {
inputMovement = Vector3.zero;
}
// Change how movement is managed based on facing state
switch (playerFacingDirection.value) {
case PlayerFacingDirection.TowardsTarget:
break;
case PlayerFacingDirection.MatchForward: // TODO: Recomment
// targetDirection = agent.transform.forward * inputMovement.magnitude;
targetDirection = inputMovement;
break;
case PlayerFacingDirection.MatchCamera:
targetDirection = Quaternion.Euler(Camera.main.transform.forward.DirectionTo(agent.transform.forward)) * inputMovement; // NOTE: This used to be t: currentRotSpeed * Time.deltaTime.
// See how it feels with a hard set value and go fro there.
break;
case PlayerFacingDirection.Static:
break;
default:
throw new ArgumentOutOfRangeException();
}
// Remove Y from variables
Vector3 targetNoY = new Vector3(targetDirection.x, 0f, targetDirection.z);
Vector3 currentNoY = new Vector3(currentMoveDir.x, 0f, currentMoveDir.z);
// Smooth movement
if (targetNoY.magnitude > currentNoY.magnitude) {
currentMoveDir = Vector3.Lerp(currentMoveDir, targetNoY,accelerationSmoothing.value * Time.deltaTime);
} else {
float deaccelValue = deaccelerationCurve.value.Evaluate(inputMovement.magnitude);
currentMoveDir = Vector3.Lerp(currentMoveDir, targetNoY, deaccelerationSmoothing.value * Time.deltaTime);
}
currentMoveDir.y = moveDirection.value.y;
// Commit move direction
moveDirection.value = currentMoveDir;
// Debug.Log(moveDirection.value);
EndAction(true);
}
// Gravity is processed in LateUpdate (added to MonoManager's onLateUpdate in OnInit())
//Called when the task is disabled.
protected override void OnStop() {
EndAction(true);
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 69daf571854fd8046a60a7baab64cc18

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 6a4c5896d783ad845861edd0c9eea14b

View File

@@ -13,7 +13,49 @@ public static class MathExtensions{
return (to - origin).normalized; return (to - origin).normalized;
} }
public static Vector3 ToVector3(this Vector2 vector2){
return new Vector3(vector2.x, 0f, vector2.y);
}
public static Vector2 ToVector2(this Vector3 vector3){
return new Vector2(vector3.x, vector3.z);
}
public static Color Alpha(this Color input, float newAlpha){ public static Color Alpha(this Color input, float newAlpha){
return new Color(input.r, input.g, input.b, newAlpha); return new Color(input.r, input.g, input.b, newAlpha);
} }
public static Quaternion SmoothDamp(Quaternion rot, Quaternion target, ref Quaternion deriv, float time) {
if (Time.deltaTime < Mathf.Epsilon) return rot;
// account for double-cover
var Dot = Quaternion.Dot(rot, target);
var Multi = Dot > 0f ? 1f : -1f;
target.x *= Multi;
target.y *= Multi;
target.z *= Multi;
target.w *= Multi;
// smooth damp (nlerp approx)
var Result = new Vector4(
Mathf.SmoothDamp(rot.x, target.x, ref deriv.x, time),
Mathf.SmoothDamp(rot.y, target.y, ref deriv.y, time),
Mathf.SmoothDamp(rot.z, target.z, ref deriv.z, time),
Mathf.SmoothDamp(rot.w, target.w, ref deriv.w, time)
).normalized;
// ensure deriv is tangent
var derivError = Vector4.Project(new Vector4(deriv.x, deriv.y, deriv.z, deriv.w), Result);
deriv.x -= derivError.x;
deriv.y -= derivError.y;
deriv.z -= derivError.z;
deriv.w -= derivError.w;
return new Quaternion(Result.x, Result.y, Result.z, Result.w);
}
public static Vector2 Rotate(this Vector2 v, float delta) {
return new Vector2(
v.x * Mathf.Cos(delta) - v.y * Mathf.Sin(delta),
v.x * Mathf.Sin(delta) + v.y * Mathf.Cos(delta)
);
}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,482 @@
using NodeCanvas.Editor;
using ParadoxNotion.Design;
using Reset.Core;
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
public class BoolValueGroupDrawer : ObjectDrawer<BoolValueGroup> {
public override BoolValueGroup OnGUI(GUIContent _content, BoolValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(80.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeValue = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue){
_instance.value = EditorGUILayout.Toggle(_instance.value.value, floatOptions);
} else if (_instance.changeValue.value == ValueChangeAction.RelativeValue){
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField("Not Available", floatOptions);
EditorGUI.EndDisabledGroup();
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class CurveValueGroupDrawer : ObjectDrawer<CurveValueGroup> {
public override CurveValueGroup OnGUI(GUIContent _content, CurveValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(80.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeValue.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue){
BBParameterEditor.ParameterField("", _instance.value);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class EnumValueGroupDrawer : ObjectDrawer<EnumValueGroup>{
public override EnumValueGroup OnGUI(GUIContent _content, EnumValueGroup _instance){
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(200.0f),
GUILayout.MinWidth(100.0f),
GUILayout.ExpandWidth(true),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeValue.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue){
_instance.value.value = EditorGUILayout.EnumPopup("", instance.value.value, floatOptions);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField((ValueChangeAction)_instance.value.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class FloatValueGroupDrawer : ObjectDrawer<FloatValueGroup> {
public override FloatValueGroup OnGUI(GUIContent _content, FloatValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Start the label
GUILayout.BeginHorizontal();
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(80.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
// End the label
GUILayout.EndHorizontal();
// Start the variables
GUILayout.BeginHorizontal();
// Create the x settings enum
// _instance.changeValue.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
BBParameterEditor.ParameterField("", _instance.changeValue);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue || _instance.changeValue.value == ValueChangeAction.RelativeValue){
BBParameterEditor.ParameterField("", _instance.value);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up with the variables
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class Vector3ValueGroupDrawer : ObjectDrawer<Vector3ValueGroup> {
public override Vector3ValueGroup OnGUI(GUIContent _content, Vector3ValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 20;
// 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),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeX.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeX.value);
// Create the value/disabled information field
if (_instance.changeX.value== ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.x = EditorGUILayout.FloatField(_instance.value.value.x, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeX.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the y settings enum
_instance.changeY.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeY.value);
// Create the value/disabled information field
if (_instance.changeY.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.y = EditorGUILayout.FloatField(_instance.value.value.y, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeY.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the y settings enum
_instance.changeZ.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeZ.value);
// Create the value/disabled information field
if (_instance.changeZ.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.z = EditorGUILayout.FloatField(_instance.value.value.z, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeZ.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class Vector2ValueGroupDrawer : ObjectDrawer<Vector2ValueGroup> {
public override Vector2ValueGroup OnGUI(GUIContent _content, Vector2ValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// 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),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeX.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeX.value);
// Create the value/disabled information field
if (_instance.changeX.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.x = EditorGUILayout.FloatField(_instance.value.value.x, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeX.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the y settings enum
_instance.changeY.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeY.value);
// Create the value/disabled information field
if (_instance.changeY.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.y = EditorGUILayout.FloatField(_instance.value.value.y, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeY.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
// 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),
};
// Add the label
GUILayout.Label(_instance.label, ValueGroupEditorUtilities.titleText);
// Start the smoothing and easing section
GUILayout.BeginHorizontal();
GUIStyle smallText= new GUIStyle{
fontSize = 10,
padding = new RectOffset(8, 0, 0,0),
normal ={
textColor = Color.gray + Color.gray / 2f
}
};
// Start the left side for height
GUILayout.BeginVertical();
// Draw the label
GUILayout.BeginHorizontal();
GUILayout.Label("Height", smallText);
GUILayout.EndHorizontal();
// Height
BBParameterEditor.ParameterField("", _instance.changeHeight);
if (_instance.changeHeight.value == ValueChangeAction.NewValue || _instance.changeHeight.value == ValueChangeAction.RelativeValue){
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.height);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeHeight.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close height
GUILayout.EndVertical();
// Start the right for radius
GUILayout.BeginVertical();
// Draw the label
GUILayout.BeginHorizontal();
GUILayout.Label("Radius", smallText);
GUILayout.EndHorizontal();
// Radius
BBParameterEditor.ParameterField("", _instance.changeRadius);
if (_instance.changeRadius.value == ValueChangeAction.NewValue || _instance.changeRadius.value == ValueChangeAction.RelativeValue){
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.radius);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeRadius.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close easing
GUILayout.EndVertical();
GUILayout.Space(8);
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public static class ValueGroupEditorUtilities{
public static void DrawEasingAndSmoothingSection(ValueGroup.ISmoothable _instance){
// Start the smoothing and easing section
GUILayout.BeginHorizontal();
GUIStyle smallText= new GUIStyle{
fontSize = 10,
padding = new RectOffset(8, 0, 0,0),
normal ={
textColor = Color.gray
}
};
// Start the left side for easing
GUILayout.BeginVertical();
// Draw the label
GUILayout.BeginHorizontal();
GUILayout.Label("Easing", smallText);
GUILayout.EndHorizontal();
// Easing
// _instance.changeEasing.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeEasing.value);
BBParameterEditor.ParameterField("", _instance.changeEasing);
if (_instance.changeEasing.value == ValueChangeAction.NewValue){
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.Easing);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeEasing.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close easing
GUILayout.EndVertical();
// Start the right for smoothing
GUILayout.BeginVertical();
// Draw the label
GUILayout.BeginHorizontal();
GUILayout.Label("Smoothing", smallText);
GUILayout.EndHorizontal();
// Smoothing
BBParameterEditor.ParameterField("", _instance.changeSmoothing);
if (_instance.changeSmoothing.value == ValueChangeAction.NewValue){
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.Smoothing);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeSmoothing.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close easing
GUILayout.EndVertical();
GUILayout.Space(8);
GUILayout.EndHorizontal();
}
static GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(300.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
public static GUIStyle titleText = new GUIStyle{
fontSize = 12,
fontStyle = FontStyle.Bold,
padding = new RectOffset(8, 0, 3,0),
normal ={
textColor = Color.white
}
};
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e327ef0e278a437486396775f36450dd
timeCreated: 1758039991

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
[Serializable]
public class CameraSettingData{
[Title("Field of View"), HideLabel, InlineProperty] public SettingValue<float> mainFieldOfView = new SettingValue<float>(0f);
[Title("Orbit Position Damping"), HideLabel, InlineProperty] public SettingValue<Vector3> orbitPositionDamping = new SettingValue<Vector3>(Vector3.zero);
[Title("Orbit Target Offset"), HideLabel, InlineProperty] public SettingValue<Vector3> orbitTargetOffset= new SettingValue<Vector3>(Vector3.zero);
[Title("X Axis Look Enabled"), HideLabel, InlineProperty] public SettingValue<bool> axisLookEnabledX = new SettingValue<bool>(true);
[Title("Y Axis Look Enabled"), HideLabel, InlineProperty] public SettingValue<bool> axisLookEnabledY = new SettingValue<bool>(true);
[Title("X Axis Look Gain"), HideLabel, InlineProperty] public SettingValue<float> axisLookGainX = new SettingValue<float>(0f);
[Title("Y Axis Look Gain"), HideLabel, InlineProperty] public SettingValue<float> axisLookGainY = new SettingValue<float>(0f);
[Title("Orbit Follow Top Height"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowTopHeight = new SettingValue<float>(0f);
[Title("Orbit Follow Top Radius"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowTopRadius = new SettingValue<float>(0f);
[Title("Orbit Follow Center Height"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowCenterHeight = new SettingValue<float>(0f);
[Title("Orbit Follow Center Radius"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowCenterRadius = new SettingValue<float>(0f);
[Title("Orbit Follow Bottom Height"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowBottomHeight = new SettingValue<float>(0f);
[Title("Orbit Follow Bottom Radius"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowBottomRadius = new SettingValue<float>(0f);
public SettingValue<Vector2> rotationComposerScreenPos= new SettingValue<Vector2>(Vector2.zero);
public SettingValue<Vector3> cameraOffsetOffset= new SettingValue<Vector3>(Vector3.zero);
public List<IResettableSettingValue> GetAllSettings(){
var outputList = new List<IResettableSettingValue>();
IResettableSettingValue[] settings = {
mainFieldOfView,
orbitPositionDamping,
orbitTargetOffset,
axisLookEnabledX,
axisLookEnabledY,
axisLookGainX,
axisLookGainY,
orbitFollowTopHeight,
orbitFollowTopRadius,
orbitFollowCenterHeight,
orbitFollowCenterRadius,
orbitFollowBottomHeight,
orbitFollowBottomRadius,
rotationComposerScreenPos,
cameraOffsetOffset,
};
outputList.AddRange(settings);
return outputList;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 14393bffe6324344b5f972412e37a339
timeCreated: 1758568723

View File

@@ -1,82 +1,14 @@
using System;
using Reset.Core;
using Sirenix.OdinInspector;
using Unity.Cinemachine; using Unity.Cinemachine;
using UnityEngine; using UnityEngine;
public struct CameraSettingSingleValue<T>{
// NOTE: Could add a locked variable here if needed??
public T originalValue;
public T targetValue;
public float smoothing;
public float velocityRef;
public Vector2 velocityRefV2;
public Vector3 velocityRefV3;
public CameraSettingSingleValue(float defaultSmoothing = .2f, T original = default(T)){
originalValue = original;
targetValue = original;
smoothing = defaultSmoothing;
velocityRef = 0;
velocityRefV2 = default;
velocityRefV3 = default;
}
public void Reset(){
targetValue = originalValue;
}
}
public struct CameraSettingValues{
public CameraSettingSingleValue<float> mainFieldOfView;
public CameraSettingSingleValue<Vector3> orbitPositionDamping;
public CameraSettingSingleValue<Vector3> orbitTargetOffset;
public CameraSettingSingleValue<bool> axisLookEnabledX;
public CameraSettingSingleValue<bool> axisLookEnabledY;
public CameraSettingSingleValue<float> axisLookGainX;
public CameraSettingSingleValue<float> axisLookGainY;
public CameraSettingSingleValue<float> orbitFollowTopHeight;
public CameraSettingSingleValue<float> orbitFollowTopRadius;
public CameraSettingSingleValue<float> orbitFollowCenterHeight;
public CameraSettingSingleValue<float> orbitFollowCenterRadius;
public CameraSettingSingleValue<float> orbitFollowBottomHeight;
public CameraSettingSingleValue<float> orbitFollowBottomRadius;
public CameraSettingSingleValue<Vector2> rotationComposerScreenPos;
public CameraSettingSingleValue<Vector3> cameraOffsetOffset;
public CameraSettingValues(float defaultSmoothing){
mainFieldOfView = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitPositionDamping = new CameraSettingSingleValue<Vector3>(defaultSmoothing);
orbitTargetOffset = new CameraSettingSingleValue<Vector3>(defaultSmoothing);
axisLookEnabledX = new CameraSettingSingleValue<bool>();
axisLookEnabledY = new CameraSettingSingleValue<bool>();
axisLookGainX = new CameraSettingSingleValue<float>(defaultSmoothing);
axisLookGainY = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowTopHeight = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowTopRadius = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowCenterHeight = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowCenterRadius = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowBottomHeight = new CameraSettingSingleValue<float>(defaultSmoothing);
orbitFollowBottomRadius = new CameraSettingSingleValue<float>(defaultSmoothing);
rotationComposerScreenPos = new CameraSettingSingleValue<Vector2>(defaultSmoothing);
cameraOffsetOffset = new CameraSettingSingleValue<Vector3>(defaultSmoothing);
}
}
public class CameraSettingsProcessor : MonoBehaviour{ public class CameraSettingsProcessor : MonoBehaviour{
public static CameraSettingsProcessor Instance{ get; private set; } public static CameraSettingsProcessor Instance{ get; private set; }
public static CameraSettingValues values = new(defaultSmoothing: .2f); [ShowInInspector, FoldoutGroup("Camera Data", expanded: true), InlineProperty, HideLabel]
public CameraSettingData data;
public static GameObject mainCamera; public static GameObject mainCamera;
@@ -101,88 +33,82 @@ public class CameraSettingsProcessor : MonoBehaviour{
rotComp = mainCamera.GetComponent<CinemachineRotationComposer>(); rotComp = mainCamera.GetComponent<CinemachineRotationComposer>();
offset = mainCamera.GetComponent<CinemachineCameraOffset>(); offset = mainCamera.GetComponent<CinemachineCameraOffset>();
axisCont = mainCamera.GetComponent<CinemachineInputAxisController>(); axisCont = mainCamera.GetComponent<CinemachineInputAxisController>();
// Initialize camera settings values // Quick check for a camera settings
values = new CameraSettingValues{ if (data == null) {
cameraOffsetOffset = new CameraSettingSingleValue<Vector3>(defaultSmoothing: .2f, offset.Offset), Debug.LogWarning("No Camera Settings Data was found on processing. One will be created. Is this intentional? This will have strong effects on camera movement");
mainFieldOfView = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, main.Lens.FieldOfView), data = new CameraSettingData();
axisLookEnabledX = new CameraSettingSingleValue<bool>(0, axisCont.Controllers[0].Enabled), }
axisLookEnabledY = new CameraSettingSingleValue<bool>(0, axisCont.Controllers[1].Enabled),
axisLookGainX = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, axisCont.Controllers[0].Input.Gain), // Initialize camera settings values from current values
axisLookGainY = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, axisCont.Controllers[1].Input.Gain), InitializeAllSettings();
orbitPositionDamping = new CameraSettingSingleValue<Vector3>(defaultSmoothing: .2f, orbit.TrackerSettings.PositionDamping),
orbitTargetOffset = new CameraSettingSingleValue<Vector3>(defaultSmoothing: .1f, orbit.TargetOffset),
orbitFollowTopHeight = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Top.Height),
orbitFollowTopRadius = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Top.Radius),
orbitFollowCenterHeight = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Center.Height),
orbitFollowCenterRadius = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Center.Radius),
orbitFollowBottomHeight = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Bottom.Height),
orbitFollowBottomRadius = new CameraSettingSingleValue<float>(defaultSmoothing: .2f, orbit.Orbits.Bottom.Radius),
rotationComposerScreenPos = new CameraSettingSingleValue<Vector2>(defaultSmoothing: .2f, rotComp.Composition.ScreenPosition),
};
} }
void ProcessCameraValues(){
main.Lens.FieldOfView = Mathf.SmoothDamp(main.Lens.FieldOfView,
values.mainFieldOfView.targetValue, ref values.mainFieldOfView.velocityRef,
values.mainFieldOfView.smoothing);
axisCont.Controllers[0].Enabled = values.axisLookEnabledX.targetValue;
axisCont.Controllers[1].Enabled = values.axisLookEnabledY.targetValue;
axisCont.Controllers[0].Input.Gain = Mathf.SmoothDamp(axisCont.Controllers[0].Input.Gain,
values.axisLookGainX.targetValue, ref values.axisLookGainX.velocityRef,
values.axisLookGainX.smoothing);
axisCont.Controllers[1].Input.Gain = Mathf.SmoothDamp(axisCont.Controllers[1].Input.Gain,
values.axisLookGainY.targetValue, ref values.axisLookGainY.velocityRef,
values.axisLookGainY.smoothing);
orbit.TargetOffset = Vector3.SmoothDamp(orbit.TargetOffset,
values.orbitTargetOffset.targetValue, ref values.orbitTargetOffset.velocityRefV3,
values.orbitTargetOffset.smoothing);
orbit.TrackerSettings.PositionDamping = Vector3.SmoothDamp(orbit.TrackerSettings.PositionDamping,
values.orbitPositionDamping.targetValue, ref values.orbitPositionDamping.velocityRefV3,
values.orbitPositionDamping.smoothing);
orbit.Orbits.Top.Height = Mathf.SmoothDamp(orbit.Orbits.Top.Height,
values.orbitFollowTopHeight.targetValue, ref values.orbitFollowTopHeight.velocityRef,
values.orbitFollowTopHeight.smoothing);
orbit.Orbits.Top.Radius = Mathf.SmoothDamp(orbit.Orbits.Top.Radius,
values.orbitFollowTopRadius.targetValue, ref values.orbitFollowTopRadius.velocityRef,
values.orbitFollowTopRadius.smoothing);
orbit.Orbits.Center.Height = Mathf.SmoothDamp(orbit.Orbits.Center.Height,
values.orbitFollowCenterHeight.targetValue, ref values.orbitFollowCenterHeight.velocityRef,
values.orbitFollowCenterHeight.smoothing);
orbit.Orbits.Center.Radius = Mathf.SmoothDamp(orbit.Orbits.Center.Radius,
values.orbitFollowCenterRadius.targetValue, ref values.orbitFollowCenterRadius.velocityRef,
values.orbitFollowCenterRadius.smoothing);
orbit.Orbits.Bottom.Height = Mathf.SmoothDamp(orbit.Orbits.Bottom.Height,
values.orbitFollowBottomHeight.targetValue, ref values.orbitFollowBottomHeight.velocityRef,
values.orbitFollowBottomHeight.smoothing);
orbit.Orbits.Bottom.Radius = Mathf.SmoothDamp(orbit.Orbits.Bottom.Radius,
values.orbitFollowBottomRadius.targetValue, ref values.orbitFollowBottomRadius.velocityRef,
values.orbitFollowBottomRadius.smoothing);
rotComp.Composition.ScreenPosition = Vector2.SmoothDamp(rotComp.Composition.ScreenPosition,
values.rotationComposerScreenPos.targetValue, ref values.rotationComposerScreenPos.velocityRefV2,
values.rotationComposerScreenPos.smoothing);
offset.Offset = Vector3.SmoothDamp(offset.Offset,
values.cameraOffsetOffset.targetValue, ref values.cameraOffsetOffset.velocityRefV3,
values.cameraOffsetOffset.smoothing);
}
void Update(){ void Update(){
ProcessCameraValues(); SmoothCameraSettings();
ApplyCameraSettings();
}
void SmoothCameraSettings(){
var settings = data.GetAllSettings();
for (int i = 0; i < settings.Count; i++) {
settings[i].SmoothAndEase();
}
}
// Responsible for actively applying the settings to the Cinemachine components
void ApplyCameraSettings(){
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(){
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;
var allSettings = data.GetAllSettings();
for (int i = 0; i < allSettings.Count; i++) {
allSettings[i].Initialize();
allSettings[i].Verify();
}
} }
} }

View File

@@ -0,0 +1,10 @@
namespace Reset.Units{
public enum PlayerFacingDirection{
TowardsTarget = 0,
MatchInput,
MatchCamera,
Static,
Momentum,
SpecifiedDirection
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 81d909774c8e4b66be6e96fd13f9bff4
timeCreated: 1758478092

View File

@@ -0,0 +1,56 @@
using Reset.Core.Tools;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Reset.Units{
public class ResolvedMovement{
public struct MoveDirection{
private Transform owner;
// Both are in world space, and translated to local
private Vector2 _moveRaw;
private Vector2 _moveDir;
[ShowInInspector]
public Vector2 World{
get{
DebugOverlayDrawer.ChangeValue("Movement", "_moveDir", _moveDir);
return _moveDir;
}
set{
_moveDir = value;
}
}
[ShowInInspector]
public Vector2 Local => owner.InverseTransformDirection(_moveDir.ToVector3()).ToVector2();
[ShowInInspector, PropertySpace(5)]
public Vector2 RawWorld{
get{
DebugOverlayDrawer.ChangeValue("Movement", "_moveRaw", _moveRaw);
// return owner.TransformDirection(_moveDir.ToVector3()).ToVector2();
return _moveRaw;
}
set{
_moveRaw = value;
}
}
[ShowInInspector]
public Vector2 RawLocal => owner.InverseTransformDirection(_moveRaw.ToVector3()).ToVector2();
public MoveDirection(Transform ownerTransform){
owner = ownerTransform;
_moveDir = Vector2.zero;
_moveRaw = Vector2.zero;
}
}
[ShowInInspector, InlineProperty, BoxGroup("Direction"), HideLabel] public MoveDirection moveDirection;
public float moveSpeed;
public Quaternion rotation;
public float rotationSpeed;
public float gravity;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d663059052094322bff98f9ed2839fd9
timeCreated: 1758478092

View File

@@ -0,0 +1,107 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Serialization;
public interface IResettableSettingValue{
public void Verify();
public void SmoothAndEase();
public void Initialize();
}
[Serializable]
public class SettingValue<T> : IResettableSettingValue{
[HorizontalGroup("Settings", width: .3f), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Target")]
public T targetValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Current")]
public T currentValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Target"), ShowIf("@IsSmoothable()")]
public float targetSmoothing; // Smoothing changes how fast the value is changed.
[HorizontalGroup("Settings"), VerticalGroup("Settings/Easing"), BoxGroup("Settings/Easing/Easing"), LabelText("Target"), ShowIf("@IsSmoothable()")]
public float targetEasing; // Easing changes how fast smoothing is changed, when given a new value.
public T Value{
get => currentValue;
set => targetValue = value;
}
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Current"), ShowIf("@IsSmoothable()")]
public float currentSmoothing;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Default")]
public T defaultValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Default"), ShowIf("@IsSmoothable()")]
public float defaultSmoothing;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Easing"), BoxGroup("Settings/Easing/Easing"), LabelText("Default"), ShowIf("@IsSmoothable()")]
public float defaultEasing;
private float refVelFloat; // For use with SmoothDamp
private Vector3 refVelV3; // For use with SmoothDamp
private Vector2 refVelV2; // For use with SmoothDamp
private bool verified;
bool IsSmoothable(){
return (typeof(T) == typeof(float) || typeof(T) == typeof(Vector2) || typeof(T) == typeof(Vector3) || typeof(T) == typeof(Vector4) || typeof(T) == typeof(Quaternion) );
}
public SettingValue(T initValue, float defaultEasing = 2f, float defaultSmoothing = 1f){
targetValue = initValue;
defaultValue = initValue;
this.defaultSmoothing = defaultSmoothing;
this.defaultEasing = defaultEasing;
targetEasing = defaultEasing;
targetSmoothing = defaultSmoothing;
currentSmoothing = targetSmoothing;
currentValue = targetValue;
refVelFloat = 0;
refVelV3 = default;
refVelV2 = default;
}
public void Verify(){
if (targetValue.Equals(currentValue) == false) {
Debug.LogWarning($"A SettingValue ({this}) doesn't have its current and target value matching. This should have been set!");
}
verified = true;
}
public void SmoothAndEase(){
if (!verified) {
Debug.LogWarning($"A SettingValue ({this}) wasn't verified before being smoothed and eased. What's up with that?");
}
currentSmoothing = Mathf.MoveTowards(currentSmoothing, targetSmoothing, targetEasing * targetEasing * Time.deltaTime);
if (typeof(T) == typeof(float)) {
currentValue = (T)(object)Mathf.SmoothDamp((float)(object)currentValue, (float)(object)targetValue, ref refVelFloat, currentSmoothing * currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector2)) {
currentValue = (T)(object)Vector2.SmoothDamp((Vector2)(object)currentValue, (Vector2)(object)targetValue, ref refVelV2, currentSmoothing * currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector3)) {
currentValue = (T)(object)Vector3.SmoothDamp((Vector3)(object)currentValue, (Vector3)(object)targetValue, ref refVelV3, currentSmoothing * currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector4) || typeof(T) == typeof(Quaternion)) {
// I have... zero clue if this will work. There is no Vector4 or Quaternion SmoothDamp
Vector3 v3value = Vector3.SmoothDamp((Vector4)(object)currentValue, (Vector4)(object)targetValue, ref refVelV3, currentSmoothing * currentSmoothing * Time.deltaTime);
float v4value = Mathf.SmoothDamp(((Vector4)(object)currentValue).z, ((Vector4)(object)targetValue).z, ref refVelFloat, currentSmoothing * currentSmoothing * Time.deltaTime);
currentValue = (T)(object)new Vector4(v3value.x, v3value.y, v3value.z, v4value);
}
}
public void Initialize(){
currentValue = targetValue;
defaultValue = targetValue;
defaultSmoothing = targetSmoothing;
defaultEasing = targetEasing;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 03e2aa4743404e9fbf8b14033c5eda7b
timeCreated: 1758126336

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using ParadoxNotion.Design;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Reset.Units{
[Serializable]
public class UnitMovementData{
// Movement Direction
[Title("Direction Changing Softeness"), HideLabel, InlineProperty] public SettingValue<float> directionChangingSoftness = new SettingValue<float>(1f, defaultSmoothing: 1f);
[Title("Direction Spinning Hardness"), HideLabel, InlineProperty] public SettingValue<float> directionSpinningHardness = new SettingValue<float>(3f, defaultSmoothing: 1f);
[Title("Directoon Spinning Speed"), HideLabel, InlineProperty] public SettingValue<float> directionSpinningSpeed= new SettingValue<float>(3f, defaultSmoothing: 1f);
[SliderField(0,1)]
[Title("Air Direction Decay"), HideLabel, InlineProperty] public SettingValue<float> airDirectionDecay = new SettingValue<float>(1f); // TODO: Check default value
// Move Speed
[Title("Acceleration"), HideLabel, InlineProperty] public SettingValue<float> acceleration = new SettingValue<float>(5f);
[Title("Deacceleration"), HideLabel, InlineProperty] public SettingValue<float> deacceleration = new SettingValue<float>(5f);
[Title("Move Speed"), HideLabel, InlineProperty] public SettingValue<float> moveSpeed = new SettingValue<float>(15f, defaultSmoothing: 10f);
// Jumping
// [Title("Jump Power"), HideLabel, InlineProperty] [ShowInInspector] public SettingValue<float> jumpPower = new SettingValue<float>(0f);
// [Title("Move Smoothing"), HideLabel, InlineProperty] public SettingValue<float> jumpPowerDecay = new SettingValue<float>(3f); // TODO: Check default value
// Gravity
[Title("Gravity Power"), HideLabel, InlineProperty] [ShowInInspector] public SettingValue<float> gravityPower = new SettingValue<float>(1f);
[Title("Gravity Max"), HideLabel, InlineProperty] public SettingValue<float> gravityMax = new SettingValue<float>(8f);
[Title("Gravity Acceleration"), HideLabel, InlineProperty] public SettingValue<float> gravityAcceleration = new SettingValue<float>(1f);
[Title("Gravity Scale"), HideLabel, InlineProperty] public SettingValue<float> gravityScale = new SettingValue<float>(1f);
// Rotation
[Title("Rotate Facing"), HideLabel, InlineProperty] public SettingValue<PlayerFacingDirection> facingDirection = new SettingValue<PlayerFacingDirection>(initValue: PlayerFacingDirection.Momentum);
[Title("Rotation Speed"), HideLabel, InlineProperty] public SettingValue<float> rotationSpeed = new SettingValue<float>(5f);
public List<IResettableSettingValue> GetAllSettings(){
var outputList = new List<IResettableSettingValue>();
IResettableSettingValue[] settings = {
directionChangingSoftness,
directionSpinningHardness,
directionSpinningSpeed,
acceleration,
deacceleration,
airDirectionDecay,
moveSpeed,
gravityPower,
gravityMax,
gravityAcceleration,
gravityScale,
facingDirection,
rotationSpeed,
};
outputList.AddRange(settings);
return outputList;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7f5d86c96bcf450b888da32d1cf253e7
timeCreated: 1758478092

View File

@@ -1,366 +1,295 @@
using System; using System.Collections.Generic;
using NUnit.Framework.Internal;
using UnityEngine; using UnityEngine;
using ParadoxNotion.Design; using Reset.Core.Tools;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using UnityEngine.Serialization;
using Quaternion = UnityEngine.Quaternion;
public enum PlayerFacingDirection{
TowardsTarget = 0,
MatchForward,
MatchCamera,
Static,
Momentum,
SpecifiedDirection
}
namespace Reset.Units{ namespace Reset.Units{
// public interface IBuffSource{ - Unused good idea?
// public Object sourceObject();
// public
// }
[Serializable]
public class UnitMovementData : ICloneable{
// Movement Direction
public float accelerationSmoothing = 5f;
public float deaccelerationSmoothing = 5f;
// public AnimationCurve deaccelerationCurve; // Currently unused, may return
[SliderField(0,1)]
public float airDirectionDecay;
// Move Speed
public float moveSpeed = 15f;
public float moveSpeedSoothing = 10f;
// Jumping
[ShowInInspector, ReadOnly] public float jumpPower;
public float jumpPowerDecay = 3f;
// Gravity
[ShowInInspector, ReadOnly] public float gravityPower;
public float gravityMax = 8f;
public float gravityAcceleration = 1f;
public float gravityScale = 1f;
public float settingsChangeSmoothing = 6f;
// Rotation
[ShowInInspector, SerializeReference]
public Enum rotateFacing;
[FormerlySerializedAs("rotationSpeedTarget")] public float rotationSpeed = 5f;
public float rotationSmoothing = 1f;
public float rotationInputBlending = .3f;
public object Clone(){
return MemberwiseClone();
}
}
public class UnitMovementHandler : MonoBehaviour{ public class UnitMovementHandler : MonoBehaviour{
// class MovementFloatModifier{ [ShowInInspector, InlineProperty, HideLabel, FoldoutGroup("Resolved Movement", expanded: true)]
// // IBuffSource source public ResolvedMovement resolvedMovement;
// public float value;
// }
// // SmoothDamp Velocities
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private float outputSpeed; private Vector2 refVelocityDirectionChangingHardness;
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private float additionalSpeed;
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] public Vector3 outputMoveDirection;
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] public Vector3 additionalMoveDirection;
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private Quaternion outputRotation;
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private Quaternion specifiedRotation;
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private float outputRotationSpeed;
// Used by graph to gradually shift into new values rather than dump them. Even if they're smoothed values they need to be eased into // Smoothing Values
[FoldoutGroup("Smoothed Values"), ShowInInspector, ReadOnly] private float smoothedJumpDecay; private float directionChangeDotLerp;
[FoldoutGroup("Smoothed Values"), ShowInInspector, ReadOnly] private float smoothedGravityAccel; private Vector3 moveSmoothVelocityRef;
[FoldoutGroup("Smoothed Values"), ShowInInspector, ReadOnly] private float smoothedGravityScale; private float gravitySmoothVelocityRef;
[FoldoutGroup("Smoothed Values"), ShowInInspector, ReadOnly] private float settingsChangeRotationSpeed;
private float directionChangeDot;
private bool moveCallDisabledNextFrame;
private bool movedThisFrame;
// References
private CharacterController controller; private CharacterController controller;
private PlayerControls controls; private PlayerControls controls;
private LockOnManager lockOnManager; private LockOnManager lockOnManager;
private Vector3 moveSmooth; // Movement Data
public float gravitySmooth; [ShowInInspector, PropertyOrder(2), FoldoutGroup("Movement Data", expanded: true), InlineProperty, HideLabel] public UnitMovementData data = new();
private bool relativeToCamera;
[ShowInInspector, PropertyOrder(2)] // Other
public UnitMovementData data = new(); private Quaternion specifiedRotation; // Used for locking a specific direction
[HideInInspector]
public UnitMovementData defaultData;
void Awake(){ void Awake(){
controller = GetComponent<CharacterController>(); controller = GetComponent<CharacterController>();
controls = GetComponent<PlayerControls>(); controls = GetComponent<PlayerControls>();
lockOnManager = GetComponent<LockOnManager>(); lockOnManager = GetComponent<LockOnManager>();
InitAllSettings();
} }
private void Start(){ void Start(){
defaultData = (UnitMovementData)data.Clone(); resolvedMovement = new ResolvedMovement{
moveDirection = new ResolvedMovement.MoveDirection(transform)
};
} }
void Update(){ void Update(){
SmoothAllSettings();
UpdateCurrentDirection(); UpdateCurrentDirection();
UpdateCurrentGravity(); UpdateCurrentGravity();
UpdateCurrentSpeed(); UpdateCurrentSpeed();
UpdateCurrentRotation(); UpdateCurrentRotation();
DoMovement(); // Apply movement
} DoMovement(resolvedMovement.moveDirection.World, resolvedMovement.gravity, resolvedMovement.moveSpeed, data.gravityScale.Value);
// Add directly to the direction
public void AddToCurrentDirection(Vector3 inputDirection, float power){
additionalMoveDirection += inputDirection.normalized;
additionalSpeed = power;
}
public void SmoothToSpeed(float desiredSpeed, float smoothing){
additionalSpeed = Mathf.Lerp(additionalSpeed, desiredSpeed, smoothing * Time.deltaTime);
}
public void SetNewDirection(Vector3 inputDirection){ // NOTE: If smoothing desired add a default bool for smoothing maybe?
additionalMoveDirection = inputDirection.Flatten(null, 0f, null);
}
public void SetNewGravity(float value){
additionalMoveDirection.y = value;
}
// Hold a new rotation to be moved to during PlayerFacingDirection.SpecifiedRotation
public void SetSpecifiedRotation(Quaternion inputRotation){
specifiedRotation = inputRotation;
}
// Blend between the current direction and an input direction, based on the current controller input
public void OverwriteDirectionFromInput(Vector2 value, float priority, float speed = Mathf.Infinity){
// Create a new direction that is the current controller input * the amount of power they should have
Vector3 dirToAdd = new Vector3(controls.rawMoveInput.x * value.x, 0f, controls.rawMoveInput.y * value.y);
// Multiply it by the current magnitude (why? i forgor) DebugOverlayDrawer.ChangeValue("Movement", "Move Direction (Local)", resolvedMovement.moveDirection.Local);
dirToAdd *= controls.rawMoveInput.magnitude; DebugOverlayDrawer.ChangeValue("Movement", "Move Direction (World)", resolvedMovement.moveDirection.World);
// Blend the existing direction into it
dirToAdd = Vector3.Lerp(outputMoveDirection, dirToAdd, priority * controls.rawMoveInput.magnitude);
// Set the new direction
outputMoveDirection = new Vector3(dirToAdd.x, outputMoveDirection.y, dirToAdd.z);
// Everthing under here is for the speed now. If it's not set do...nothing. Otherwise set it to the max value between move speed and the new speed
if (float.IsPositiveInfinity(speed)) {
return;
}
outputSpeed = Mathf.Lerp(outputSpeed, Mathf.Max(data.moveSpeed, speed), priority);
} }
// Update the direction, called every frame // Update the direction, called every frame
private void UpdateCurrentDirection(){ private void UpdateCurrentDirection(){
// Get input value // Get input value
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y); Vector2 targetDirection = new Vector2(controls.rawMoveInput.x, controls.rawMoveInput.y);
// Construct move direction // Rotate input by camera rotation (instead of rotating the output direction by camera rotation)
Vector3 targetDirection = inputMovement; targetDirection = (Camera.main.transform.rotation * targetDirection.ToVector3()).ToVector2();
// Deadzone // Deadzone
if (inputMovement.magnitude < .05f) { if (targetDirection.magnitude < .08f) {
targetDirection = Vector3.zero; targetDirection = Vector2.zero;
} }
// Remove Y from variables // Set Raw Direction (this is used by the camera later)
Vector3 targetNoY = new Vector3(targetDirection.x, 0f, targetDirection.z); resolvedMovement.moveDirection.RawWorld = targetDirection;
Vector3 currentNoY = new Vector3(outputMoveDirection.x, 0f, outputMoveDirection.z);
// Also need to find the dot value of the current input versus the current move direction
Vector3 slerpedValue;
Vector3 lerpedValue;
float switchedDirection = Vector3.Dot(inputMovement, outputMoveDirection); // Get current direction
Vector2 currentDirection = resolvedMovement.moveDirection.World;
// Also need to find the dot value of the current input versus the current move direction
float switchedDirection = Vector3.Dot(targetDirection, currentDirection);
float switchedDirectionRemapped = Mathf.Lerp(0, 1, switchedDirection); float switchedDirectionRemapped = Mathf.Lerp(0, 1, switchedDirection);
directionChangeDot = Mathf.Lerp(switchedDirection, switchedDirectionRemapped, 5f * Time.deltaTime) ; // turn that .5f into a variable directionChangeDotLerp = Mathf.Lerp(switchedDirection, switchedDirectionRemapped, data.directionSpinningHardness.Value * Time.deltaTime);
DebugOverlayDrawer.ChangeValue("Movement", "Direction Change Dot", directionChangeDotLerp);
// Smooth movement. Use deaccel smoothing if the input magnitude is lower, and accel smoothing if it's higher // Smooth movement. Use deaccel smoothing if the input magnitude is lower, and accel smoothing if it's higher
// Also checks when grounded to only use Slerp on the ground // Also checks when grounded to only use Slerp on the ground
if (targetNoY.magnitude > currentNoY.magnitude) { Vector3 slerpedValue;
if (controller.isGrounded){ Vector2 lerpedValue;
slerpedValue = Vector3.Slerp(currentNoY, targetNoY, data.accelerationSmoothing * Time.deltaTime); Vector2 newDirection;
lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.accelerationSmoothing * Time.deltaTime);
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDot); if (controller.isGrounded){
} else { slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.directionSpinningSpeed.Value * Time.deltaTime);
currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.accelerationSmoothing * Time.deltaTime); lerpedValue = Vector2.SmoothDamp(currentDirection, targetDirection, ref refVelocityDirectionChangingHardness, data.directionChangingSoftness.Value * Time.deltaTime);
}
newDirection = Vector2.Lerp(slerpedValue, lerpedValue, directionChangeDotLerp);
} else { } else {
if (controller.isGrounded){ newDirection = Vector2.SmoothDamp(currentDirection, targetDirection, ref refVelocityDirectionChangingHardness, data.directionChangingSoftness.Value * data.airDirectionDecay.Value * Time.deltaTime);
slerpedValue = Vector3.Slerp(currentNoY, targetNoY, data.deaccelerationSmoothing * Time.deltaTime); }
lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.deaccelerationSmoothing * Time.deltaTime);
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDot);
} else {
currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.deaccelerationSmoothing * data.airDirectionDecay * Time.deltaTime);
}
}
// Commit move direction // Commit the new direction
outputMoveDirection = Vector3.SmoothDamp(outputMoveDirection, new Vector3(currentNoY.x, outputMoveDirection.y, currentNoY.z),ref moveSmooth , .5f *Time.deltaTime); resolvedMovement.moveDirection.World = newDirection;
} }
// Update the speed, called every frame // Update the speed, called every frame
private void UpdateCurrentSpeed(){ private void UpdateCurrentSpeed(){
Debug.Log(data.moveSpeed); // ""Smooth"" the speed
outputSpeed = Mathf.Lerp(outputSpeed, data.moveSpeed, data.moveSpeedSoothing * Time.deltaTime); float smoothedSpeed;
if (resolvedMovement.moveDirection.Local.magnitude < controls.rawMoveInput.magnitude) {
smoothedSpeed = Mathf.MoveTowards(resolvedMovement.moveSpeed, data.moveSpeed.Value, data.acceleration.Value * Time.deltaTime);
} else {
smoothedSpeed = Mathf.MoveTowards(resolvedMovement.moveSpeed, 0f, data.deacceleration.Value * Time.deltaTime);
}
// Commit the speed
resolvedMovement.moveSpeed = smoothedSpeed;
DebugOverlayDrawer.ChangeValue("Movement", "Resolved Speed", resolvedMovement.moveSpeed);
} }
// Update the gravity, called every frame // Update the gravity, called every frame
// NOTE: most gravity interactions, like when grounded or not, is now handled by the state machine
private void UpdateCurrentGravity(){ private void UpdateCurrentGravity(){
// Accelerate gravity // Accelerate gravity
data.gravityPower += smoothedGravityAccel * Time.deltaTime; if (!controller.isGrounded){
data.gravityPower = Mathf.Clamp(data.gravityPower, Mathf.NegativeInfinity, data.gravityMax); resolvedMovement.gravity -= data.gravityAcceleration.Value * Time.deltaTime;
// Apply a constant gravity if the player is grounded
if (controller.isGrounded) {
data.gravityPower = .1f;
} }
// Create the final gravity value // Create the final gravity value
float gravityMoveDirection = data.jumpPower + (Physics.gravity.y * data.gravityPower); float gravityMoveDirection = Physics.gravity.y * resolvedMovement.gravity;
// Commit gravity to move direction, ignoring XZ since those are done in UpdateMovementDirection
outputMoveDirection.y = Mathf.SmoothDamp(outputMoveDirection.y, gravityMoveDirection, ref gravitySmooth, .1f * Time.deltaTime);
} }
// Update the rotation, called every frame // Update the rotation, called every frame
private void UpdateCurrentRotation(){ private void UpdateCurrentRotation(){
// Get input value // Get input value
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y); Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
Quaternion targetRotation = Quaternion.identity;
// Switch the desired rotation based on current movement setting // Switch the desired rotation based on current movement setting
switch (data.rotateFacing) { switch (data.facingDirection.Value) {
// Just look at target // Just look at target
case PlayerFacingDirection.TowardsTarget: case PlayerFacingDirection.TowardsTarget:
// Look directly at the target // Look directly at the target
outputRotation = Quaternion.LookRotation(transform.position.DirectionTo(lockOnManager.mainTarget.gameObject.transform.position)); if (lockOnManager.mainTarget == null) {
Debug.LogError("Trying to rotate towards a target but there is no target. Not setting a rotation");
targetRotation = transform.rotation;
break;
}
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(lockOnManager.mainTarget.gameObject.transform.position));
break; break;
case PlayerFacingDirection.Momentum: case PlayerFacingDirection.Momentum:
// Look towards the current direction the agent is moving // Look towards the current direction the agent is moving
if (inputMovement.magnitude > .05f){ if (inputMovement.magnitude > .05f){
outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(outputMoveDirection); targetRotation = Quaternion.LookRotation(resolvedMovement.moveDirection.RawWorld.ToVector3(), Vector3.up);
} }
break; break;
case PlayerFacingDirection.MatchForward: case PlayerFacingDirection.MatchInput:
// Look towards the input direction....why??? I guess cause move direction is PlayerFacingDirection.Momentum. // Look towards the input direction- similar to Momentum but snappier
if (controls.rawMoveInput.magnitude < 0.05f) { break; } if (controls.rawMoveInput.magnitude < 0.05f) { break; }
outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement); targetRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
break; break;
case PlayerFacingDirection.MatchCamera: case PlayerFacingDirection.MatchCamera:
// Look the same direction as the camera // Look the same direction as the camera
outputRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0)); targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
break; break;
case PlayerFacingDirection.Static: case PlayerFacingDirection.Static:
// Don't change // Don't change
outputRotation = transform.rotation; targetRotation = resolvedMovement.rotation;
break;
case PlayerFacingDirection.SpecifiedDirection:
// Look at an inputed rotation
outputRotation = specifiedRotation;
break; break;
} }
DebugOverlayDrawer.ChangeValue("Rotation", "Target Rotation", targetRotation.eulerAngles);
// Add the current input into the created rotation // Add the current input into the created rotation
if (inputMovement.magnitude > .05){ if (inputMovement.magnitude > .05) {
outputRotation = Quaternion.Lerp(outputRotation, Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement), data.rotationInputBlending); resolvedMovement.rotation = targetRotation;
} else if (data.facingDirection.Value == PlayerFacingDirection.MatchCamera) {
resolvedMovement.rotation = targetRotation;
} }
// Calculate rotation speed, as in how fast the fella rotates. This value has it's own smoothing to allow for gradual increasing/decreasing of the speed till it reaches the target // Apply rotation to the character
outputRotationSpeed = Mathf.Lerp(outputRotationSpeed, data.rotationSpeed, settingsChangeRotationSpeed * Time.deltaTime); transform.rotation = Quaternion.Slerp(transform.rotation, resolvedMovement.rotation, data.rotationSpeed.Value * Time.deltaTime).Flatten(0, null, 0);
// Set final rotation
transform.rotation = Quaternion.Slerp(transform.rotation, outputRotation, outputRotationSpeed * Time.deltaTime).Flatten(0, null, 0);
} }
// Move with default settings
public void DoMovement(){
DoMovement(outputMoveDirection, outputSpeed, data.gravityScale);
}
public void DisableNextMoveCall(){
moveCallDisabledNextFrame = true;
}
// Custom move from input // Custom move from input
public void DoMovement(Vector3 moveDir, float speed, float gravityScale){ private void DoMovement(Vector2 moveDir, float gravDir, float speed, float gravityScale){
// Debug.Log($"moveDir: {moveDir}, agent velocity: {transform.InverseTransformDirection(controller.velocity.normalized)}");
// Seperate the different move directions. Additonal becomes it's own because it needs to be added independently of the other two // Seperate the different move directions. Additonal becomes it's own because it needs to be added independently of the other two
Vector3 moveXZDir = new Vector3(moveDir.x, 0f, moveDir.z); Vector2 moveXZDir = moveDir;
Vector3 moveYDir = new Vector3(0f, moveDir.y, 0f); float moveYDir = gravDir;
Vector3 addDir = additionalMoveDirection;
// Add their related speeds // Add their related speeds
moveXZDir *= speed * Time.deltaTime; moveXZDir *= speed * Time.deltaTime;
moveYDir *= smoothedGravityScale * Time.deltaTime; moveYDir *= data.gravityScale.Value * Time.deltaTime;
addDir *= additionalSpeed * Time.deltaTime;
// Construct the direction and move // Construct the direction and move
Vector3 finalDir = moveXZDir + moveYDir; Vector3 finalDir = new Vector3(moveXZDir.x, moveYDir, moveXZDir.y);
controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * finalDir) + addDir); controller.Move(finalDir);
}
void LateUpdate(){
UpdateGravityLate();
DecayAdditionalDirection();
SmoothingSettingsChanges();
}
private void SmoothingSettingsChanges(){
smoothedJumpDecay = Mathf.Lerp(smoothedJumpDecay, data.jumpPowerDecay, data.settingsChangeSmoothing * Time.deltaTime);
smoothedGravityAccel = Mathf.Lerp(smoothedGravityAccel, data.gravityAcceleration, data.settingsChangeSmoothing * Time.deltaTime);
smoothedGravityScale = Mathf.Lerp(smoothedGravityScale, data.gravityScale, data.settingsChangeSmoothing * Time.deltaTime);
settingsChangeRotationSpeed = Mathf.Lerp(settingsChangeRotationSpeed, data.rotationSpeed, data.settingsChangeSmoothing * Time.deltaTime);
}
void DecayAdditionalDirection(){
// Get input value
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
// Ignore values under deadzone
if (inputMovement.magnitude < .1f) {
inputMovement = Vector3.zero;
}
// Remove Y from variables
Vector3 currentNoY = new Vector3(additionalMoveDirection.x, 0f, additionalMoveDirection.z);
// Decay the direction
if (inputMovement.magnitude < currentNoY.magnitude) {
additionalMoveDirection = Vector3.Slerp(additionalMoveDirection, Vector3.zero,data.accelerationSmoothing * Time.deltaTime);
} else {
// float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude);
additionalMoveDirection = Vector3.Lerp(additionalMoveDirection, Vector3.zero, data.deaccelerationSmoothing * Time.deltaTime);
}
// Decay the gravity
additionalMoveDirection.y -= data.gravityPower;
additionalMoveDirection.y = Mathf.Max(0f, additionalMoveDirection.y);
} }
private void UpdateGravityLate(){ // Setting absolute to true will cause the current gravity to snap to the new gravity value.
// Decay jump power // Keeping it false will make it apply additively to the current gravity. Both options use relativty for linear interpolation.
data.jumpPower -= smoothedJumpDecay * Time.deltaTime; public void SetNewGravity(float value, float relativity, bool absolute){ // new
data.jumpPower = Mathf.Max(0f, data.jumpPower); if (absolute){
resolvedMovement.gravity = Mathf.Lerp(resolvedMovement.gravity, value, relativity);
} else {
resolvedMovement.gravity = Mathf.Lerp(resolvedMovement.gravity, resolvedMovement.gravity + value, relativity);
}
} }
public void SetNewDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default){ // new
Vector2 relativeValue = relativeTo + value;
if (absolute){
resolvedMovement.moveDirection.World = Vector2.Lerp(resolvedMovement.moveDirection.World, relativeValue, relativity);
} else {
resolvedMovement.moveDirection.World = Vector2.Lerp(resolvedMovement.moveDirection.World, resolvedMovement.moveDirection.World + relativeValue, relativity);
}
}
public void SetNewRawDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default){ // new
Vector2 relativeValue = relativeTo + value;
if (absolute){
resolvedMovement.moveDirection.RawWorld = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, relativeValue, relativity);
} else {
resolvedMovement.moveDirection.RawWorld = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, resolvedMovement.moveDirection.RawWorld + relativeValue, relativity);
}
}
public void SetNewSpeed(float value, float relativity, bool absolute, float relativeTo = Mathf.Infinity){ // new
if (absolute){
resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, value, relativity);
} else {
resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, resolvedMovement.moveSpeed + value, relativity);
}
}
public void SetNewRotation(Quaternion value, float relativity, bool absolute, Quaternion relativeTo = default){ // new
Quaternion relativeValue = relativeTo * value;
if (absolute){
resolvedMovement.rotation = Quaternion.Lerp(resolvedMovement.rotation, relativeValue, relativity);
} else {
resolvedMovement.rotation = Quaternion.Lerp(resolvedMovement.rotation, resolvedMovement.rotation * relativeValue, relativity);
}
}
public void SetSpecifiedRotation(Quaternion inputRotation){
specifiedRotation = inputRotation;
}
[Button("Initialize Settings", ButtonHeight = 30), PropertySpace(10,5 )]
void InitAllSettings(){
var settingsList = data.GetAllSettings();
foreach (IResettableSettingValue value in settingsList) {
value.Initialize();
value.Verify();
}
}
void SmoothAllSettings(){
var settingsList = data.GetAllSettings();
foreach (IResettableSettingValue value in settingsList) {
value.SmoothAndEase();
}
}
public void AddToCurrentDirection(Vector3 inputDirection, float power){ // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
public void SmoothToSpeed(float desiredSpeed, float smoothing){ // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
public void SetNewDirection(Vector3 inputDirection){ // NOTE: If smoothing desired add a default bool for smoothing maybe? // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
public void SetNewGravity(float value){
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
public void OverwriteDirectionFromInput(Vector2 value, float priority, float speed = Mathf.Infinity){ // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
} }
} }