added: movement settings changing within graph
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using Reset.Core;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions {
|
||||
[Category("Reset")]
|
||||
[Description("Change Cinemachine camera settings for the player")]
|
||||
|
||||
214
Assets/Scripts/Core/Graph Tasks/ChangeMovementSettings.cs
Normal file
214
Assets/Scripts/Core/Graph Tasks/ChangeMovementSettings.cs
Normal file
@@ -0,0 +1,214 @@
|
||||
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> {
|
||||
//Use for initialization. This is called only once in the lifetime of the task.
|
||||
// Move Speed
|
||||
[ParadoxNotion.Design.Header("Speed")]
|
||||
public FloatValueGroup moveSpeedTarget = new (newLabel: "Move Speed");
|
||||
public FloatValueGroup moveSpeedSoothing = new (newLabel: "Move Speed Smoothing");
|
||||
|
||||
[ParadoxNotion.Design.Header("Speed")]
|
||||
public Vector3ValueGroup feedNewDirection = new Vector3ValueGroup("Feed New Direction");
|
||||
public float newDirectionPower;
|
||||
|
||||
public FloatValueGroup accelerationSmoothing = new (newLabel: "Acceleration Smoothing");
|
||||
public FloatValueGroup deaccelerationSmoothing = new (newLabel: "Deacceleration Smoothing");
|
||||
public CurveValueGroup deaccelerationCurve = new (newLabel: "Deacceleration Curve");
|
||||
|
||||
// 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");
|
||||
|
||||
// Rotation
|
||||
[ParadoxNotion.Design.Header("Rotation")]
|
||||
public EnumValueGroup rotateFacing = new EnumValueGroup("Facing Direction", PlayerFacingDirection.TowardsTarget);
|
||||
public FloatValueGroup rotationSpeedTarget = new (newLabel: "Rotation Speed");
|
||||
public FloatValueGroup rotationSmoothing = new (newLabel: "Rotation Smoothing");
|
||||
public BBParameter<Vector3> feedNewRotation;
|
||||
public BBParameter<Vector3> feedRelativeTo;
|
||||
public Space rotationRelativeSpace;
|
||||
|
||||
private Vector3 feedDir;
|
||||
|
||||
|
||||
//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() {
|
||||
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);
|
||||
|
||||
UpdateFloatValue(moveSpeedTarget, ref agent.data.moveSpeedTarget, ref agent.defaultData.moveSpeedTarget);
|
||||
UpdateFloatValue(moveSpeedSoothing, ref agent.data.moveSpeedSoothing, ref agent.defaultData.moveSpeedSoothing);
|
||||
|
||||
UpdateFloatValue(jumpPower, ref agent.data.jumpPower, ref agent.defaultData.jumpPower);
|
||||
UpdateFloatValue(jumpPowerDecay, ref agent.data.jumpPowerDecay, ref agent.defaultData.jumpPowerDecay);
|
||||
|
||||
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);
|
||||
|
||||
UpdateEnumValue(rotateFacing, ref agent.data.rotateFacing, ref agent.defaultData.rotateFacing);
|
||||
|
||||
UpdateFloatValue(rotationSpeedTarget, ref agent.data.rotationSpeedTarget, ref agent.defaultData.rotationSpeedTarget);
|
||||
UpdateFloatValue(rotationSmoothing, ref agent.data.rotationSmoothing, ref agent.defaultData.rotationSmoothing);
|
||||
|
||||
UpdateVector3Value(feedNewDirection, ref feedDir, ref feedDir);
|
||||
|
||||
// Debug.Log(feedDir);
|
||||
|
||||
if (feedDir != Vector3.zero) {
|
||||
agent.AddToCurrentDirection(agent.transform.rotation * feedDir.normalized, newDirectionPower);
|
||||
feedDir = Vector3.zero;
|
||||
}
|
||||
|
||||
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;
|
||||
break;
|
||||
case ValueChangeAction.ResetValue:
|
||||
targetProperty = defaultProperty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5132a76af4f722e49bc7fbbc75edcaf1
|
||||
@@ -65,6 +65,7 @@ namespace Reset.Player.Movement {
|
||||
case PlayerFacingDirection.Static:
|
||||
targetRotation = agent.transform.rotation;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Set final rotation
|
||||
|
||||
Reference in New Issue
Block a user