using NodeCanvas.Framework; using ParadoxNotion.Design; using Unity.Mathematics.Geometry; using UnityEngine; namespace Reset.Units { [Category("Reset/Movement")] [Description("Sets a new value for gravity. Additively, or absolutely.")] public class SetNewGravity : ActionTask{ public BBParameter 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 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 relativity; [Tooltip("If using during execute, multiply by delta time")] [Space(5)] public BBParameter deltaTime; [Tooltip("This is only used if the value is set in an Update loop. Set to 0 to remove decay")] public BBParameter decayRate; //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() { } //Called once per frame while the action is active. protected override void OnUpdate(){ float finalValue = newGravity.value ; if (decayRate.value != 0) { finalValue -= decayRate.value * elapsedTime; } if (deltaTime.value) { finalValue *= Time.deltaTime; } agent.SetNewGravity(finalValue, relativity.value, absolute.value); EndAction(true); } //Called when the task is disabled. protected override void OnStop() { } //Called when the task is paused. protected override void OnPause() { } } }