Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// KawaiiPhysics : Copyright (c) 2019-2024 pafuhana1213, MIT License

#include "AnimNotifyState_KawaiiPhysics.h"
#include "KawaiiPhysicsLibrary.h"
#include "KawaiiPhysicsExternalForce.h"
#include "Misc/UObjectToken.h"

#define LOCTEXT_NAMESPACE "KawaiiPhysics_AnimNotifyState"

UAnimNotifyState_KawaiiPhysicsAddExternalForce::UAnimNotifyState_KawaiiPhysicsAddExternalForce(
const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
#if WITH_EDITORONLY_DATA
NotifyColor = FColor(255, 170, 0, 255);
#endif // WITH_EDITORONLY_DATA
}

FString UAnimNotifyState_KawaiiPhysicsAddExternalForce::GetNotifyName_Implementation() const
{
return FString(TEXT("KP: Add ExternalForce"));
}

void UAnimNotifyState_KawaiiPhysicsAddExternalForce::NotifyBegin(USkeletalMeshComponent* MeshComp,
UAnimSequenceBase* Animation,
float TotalDuration)
{
UKawaiiPhysicsLibrary::AddExternalForcesToComponent(MeshComp, AdditionalExternalForces, this,
FilterTags, bFilterExactMatch);
Super::NotifyBegin(MeshComp, Animation, TotalDuration);
}

void UAnimNotifyState_KawaiiPhysicsAddExternalForce::NotifyEnd(USkeletalMeshComponent* MeshComp,
UAnimSequenceBase* Animation)
{
UKawaiiPhysicsLibrary::RemoveExternalForcesFromComponent(MeshComp, this, FilterTags, bFilterExactMatch);

Super::NotifyEnd(MeshComp, Animation);
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// KawaiiPhysics : Copyright (c) 2019-2024 pafuhana1213, MIT License

#pragma once

#include "GameplayTagContainer.h"
#include "Animation/AnimNotifies/AnimNotifyState.h"

#include "AnimNotifyState_KawaiiPhysics.generated.h"

class UKawaiiPhysics_ExternalForce;

/**
* UAnimNotifyState_KawaiiPhysicsAddExternalForce
*
* This class represents an animation notify state that adds external forces to a skeletal mesh component
* during an animation sequence. It inherits from UAnimNotifyState and provides functionality to add and remove
* external forces at the beginning and end of the animation notify state.
*/
UCLASS(Blueprintable, meta = (DisplayName = "KawaiiPhyiscs: Add ExternalForce"))
class KAWAIIPHYSICS_API UAnimNotifyState_KawaiiPhysicsAddExternalForce : public UAnimNotifyState
{
GENERATED_BODY()

public:
/**
* Constructor for UAnimNotifyState_KawaiiPhysicsAddExternalForce.
*
* @param ObjectInitializer - The object initializer for this class.
*/
UAnimNotifyState_KawaiiPhysicsAddExternalForce(const FObjectInitializer& ObjectInitializer);

/**
* Gets the name of the notify state.
*
* @return The name of the notify state as a string.
*/
virtual FString GetNotifyName_Implementation() const override;

/**
* Called when the animation notify state begins.
*
* @param MeshComp - The skeletal mesh component.
* @param Animation - The animation sequence.
* @param TotalDuration - The total duration of the notify state.
*/
virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration) override;

/**
* Called when the animation notify state ends.
*
* @param MeshComp - The skeletal mesh component.
* @param Animation - The animation sequence.
*/
virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;

/**
* Additional external forces to be applied to the skeletal mesh component.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced, Category = "ExternalForce",
meta = (BaseStruct = "/Script/KawaiiPhysics.KawaiiPhysics_ExternalForce", ExcludeBaseStruct))
TArray<UKawaiiPhysics_ExternalForce*> AdditionalExternalForces;

/**
* Tags used to filter which external forces are applied.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ExternalForce")
FGameplayTagContainer FilterTags;

/**
* Whether to filter tags to exact matches (if False, parent tags will also be included).
* Tagのフィルタリングにて完全一致にするか否か(Falseの場合は親Tagも含めます)
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ExternalForce")
bool bFilterExactMatch;

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// KawaiiPhysics : Copyright (c) 2019-2024 pafuhana1213, MIT License

#include "AnimNotify_KawaiiPhysics.h"
#include "KawaiiPhysicsLibrary.h"
#include "KawaiiPhysicsExternalForce.h"
#include "Misc/UObjectToken.h"
#include "Logging/MessageLog.h"

#define LOCTEXT_NAMESPACE "KawaiiPhysics_AnimNotify"

UAnimNotify_KawaiiPhysicsAddExternalForce::UAnimNotify_KawaiiPhysicsAddExternalForce(
const FObjectInitializer& ObjectInitializer)
{
#if WITH_EDITORONLY_DATA
NotifyColor = FColor(255, 170, 0, 255);
#endif // WITH_EDITORONLY_DATA
}

FString UAnimNotify_KawaiiPhysicsAddExternalForce::GetNotifyName_Implementation() const
{
return FString(TEXT("KP: Add ExternalForce"));
}

void UAnimNotify_KawaiiPhysicsAddExternalForce::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
UKawaiiPhysicsLibrary::AddExternalForcesToComponent(MeshComp, AdditionalExternalForces, this,
FilterTags, bFilterExactMatch, true);

Super::Notify(MeshComp, Animation);
}

#if WITH_EDITOR
void UAnimNotify_KawaiiPhysicsAddExternalForce::ValidateAssociatedAssets()
{
static const FName NAME_AssetCheck("AssetCheck");

if (const UAnimSequenceBase* ContainingAsset = Cast<UAnimSequenceBase>(GetContainingAsset()))
{
for (auto& ForceInstancedStruct : AdditionalExternalForces)
{
if (ForceInstancedStruct == nullptr)
{
FMessageLog AssetCheckLog(NAME_AssetCheck);

const FText MessageLooping = FText::Format(
NSLOCTEXT("AnimNotify", "ExternalForce_ShouldSet",
" AnimNotify(KawaiiPhysics_AddExternalForce) doesn't have a valid ExternalForce in {0}"),
FText::AsCultureInvariant(ContainingAsset->GetPathName()));

AssetCheckLog.Warning()
->AddToken(FUObjectToken::Create(ContainingAsset))
->AddToken(FTextToken::Create(MessageLooping));

if (GIsEditor)
{
constexpr bool bForce = true;
AssetCheckLog.Notify(MessageLooping, EMessageSeverity::Warning, bForce);
}
}

//const auto& ExternalForce = ForceInstancedStruct.Get<FKawaiiPhysics_ExternalForce>();
}
}
}
#endif

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// KawaiiPhysics : Copyright (c) 2019-2024 pafuhana1213, MIT License

#pragma once

#include "GameplayTagContainer.h"
#include "Animation/AnimNotifies/AnimNotify.h"

#include "AnimNotify_KawaiiPhysics.generated.h"

class UKawaiiPhysics_ExternalForce;

/**
* UAnimNotify_KawaiiPhysicsAddExternalForce
*
* This class represents an animation notify that adds external forces to a skeletal mesh component
* during an animation sequence. It inherits from UAnimNotify and provides functionality to add and remove
* external forces when the notify is triggered.
*/
UCLASS(Blueprintable, meta = (DisplayName = "KawaiiPhyiscs: Add ExternalForce"))
class KAWAIIPHYSICS_API UAnimNotify_KawaiiPhysicsAddExternalForce : public UAnimNotify
{
GENERATED_BODY()

public:
/**
* Constructor for UAnimNotify_KawaiiPhysicsAddExternalForce.
*
* @param ObjectInitializer - The object initializer for this class.
*/
UAnimNotify_KawaiiPhysicsAddExternalForce(const FObjectInitializer& ObjectInitializer);

/**
* Gets the name of the notify.
*
* @return The name of the notify as a string.
*/
virtual FString GetNotifyName_Implementation() const override;

/**
* Called when the animation notify is triggered.
*
* @param MeshComp - The skeletal mesh component.
* @param Animation - The animation sequence.
*/
virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;

public:
/**
* Additional external forces to be applied to the skeletal mesh component.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced, Category = "ExternalForce",
meta = (BaseStruct = "/Script/KawaiiPhysics.KawaiiPhysics_ExternalForce", ExcludeBaseStruct))
TArray<UKawaiiPhysics_ExternalForce*> AdditionalExternalForces;

/**
* Tags used to filter which external forces are applied.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ExternalForce")
FGameplayTagContainer FilterTags;

/**
* Whether to filter tags to exact matches (if False, parent tags will also be included).
* Tagのフィルタリングにて完全一致にするか否か(Falseの場合は親Tagも含めます)
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ExternalForce")
bool bFilterExactMatch;

#if WITH_EDITOR
/**
* Validates the associated assets in the editor.
*/
virtual void ValidateAssociatedAssets() override;
#endif
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2026 pafuhana1213. All Rights Reserved.
// KawaiiPhysics : Copyright (c) 2019-2024 pafuhana1213, MIT License

using UnrealBuildTool;

Expand All @@ -13,6 +13,7 @@ public KawaiiPhysics(ReadOnlyTargetRules Target) : base(Target)
{
"Core",
"AnimGraphRuntime",
"GameplayTags"
}
);

Expand All @@ -28,8 +29,7 @@ public KawaiiPhysics(ReadOnlyTargetRules Target) : base(Target)
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"GameplayTags"
"SlateCore"
}
);

Expand Down
Loading