Successful implementation of UlxScriptedAnimations

This commit is contained in:
2025-10-10 17:33:39 -04:00
parent 4b0f85ef19
commit e7cb47db5b
6 changed files with 235 additions and 8 deletions

View File

@@ -6,9 +6,96 @@
#include "Kismet/KismetSystemLibrary.h"
#include "Input/Events.h"
#include "CommonTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "UtilityLibrary.generated.h"
class UEnhancedInputLocalPlayerSubsystem;
class UAnimSequenceBase;
USTRUCT(BlueprintType)
struct INTEGRATION_API FlxScriptedAnimation
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UAnimSequenceBase *Sequence;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double FadeIn = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double FadeOut = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double StartTime = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double AdjustedLength = 0.0;
};
USTRUCT(BlueprintType)
struct INTEGRATION_API FlxScriptedAnimationProgress : public FlxScriptedAnimation
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double UpdateTime = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double EndTime = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double ElapsedTime = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double TimeLeft = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double FadeInAlpha = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double FadeOutAlpha = 0.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
double FadeAlpha = 0.0;
};
UCLASS(BlueprintType)
class INTEGRATION_API UlxScriptedAnimations : public UObject
{
GENERATED_BODY()
private:
UPROPERTY()
int KeepCount = 3;
UPROPERTY()
TArray<FlxScriptedAnimation> Animations;
// If the number of elements in the array exceeds the count, discard.
//
void Keep(int n);
public:
// Allow read-only access anywhere.
//
const TArray<FlxScriptedAnimation> &GetAnimations() const { return Animations; }
// Add a scripted animation to the end of the array.
//
UFUNCTION(BlueprintCallable, Category = "Luprex|Scripted Animations", meta=(WorldContext = "WorldContextObject"))
void AddAnimation(
UObject *WorldContextObject, UAnimSequenceBase* Sequence, double FadeInTime = 0.2, double FadeOutTime = 0.2);
// Truncate all current animations: force them all to begin fading out.
//
UFUNCTION(BlueprintCallable, Category = "Luprex|Scripted Animations", meta=(WorldContext = "WorldContextObject"))
void FadeOutAll(UObject *WorldContextObject);
};
/**
*
@@ -18,7 +105,7 @@ class UEnhancedInputLocalPlayerSubsystem;
*
*/
UCLASS()
class INTEGRATION_API UlxUtilityLibrary : public UObject
class INTEGRATION_API UlxUtilityLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
@@ -133,6 +220,29 @@ public:
UFUNCTION(BlueprintPure, Category="Widget")
static void GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D &UpperLeftXY, FVector2D &LowerRightXY);
// Calculate the progress of a Scripted Animation.
//
// Given a scripted animation and the current time, calculates
// how much time has elapsed, how much time is left, and several
// other parameters pertaining to the passage of time for
// this animation.
//
UFUNCTION(BlueprintPure, Category = "Luprex|Scripted Animations", meta=(BlueprintThreadSafe))
static FlxScriptedAnimationProgress ScriptedAnimationProgress(const FlxScriptedAnimation &Animation, double CurrentTime);
// Get the data to drive Sequence Evaluators and Multi Blend
//
// To apply scripted animations in an Anim Graph, you will need
// three sequence evaluators and a multi-blend node. This
// function outputs the input parameters for all of those nodes.
//
UFUNCTION(BlueprintPure, Category = "Luprex|Scripted Animations", meta=(BlueprintThreadSafe))
static void ScriptedAnimationEvaluatorData(const UlxScriptedAnimations *Animations, double CurrentTime,
UAnimSequenceBase *&Sequence0, float &ExplicitTime0,
UAnimSequenceBase *&Sequence1, float &ExplicitTime1,
UAnimSequenceBase *&Sequence2, float &ExplicitTime2,
float &BaseAlpha, float &Sequence0Alpha, float &Sequence1Alpha, float &Sequence2Alpha);
// Check if a given key is used by the specified mapping context.
//
// This is true if the key is mapped to anything at all within