Skip to content

Commit

Permalink
Expose charater landing event
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere committed Oct 10, 2020
1 parent 0f4d544 commit ae76fef
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 2 deletions.
10 changes: 10 additions & 0 deletions API/Character-SetOnLandedCallback(CharacterLandedDelegate).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### [UnrealEngine.Framework](./UnrealEngine-Framework.md 'UnrealEngine.Framework').[Character](./Character.md 'UnrealEngine.Framework.Character')
## Character.SetOnLandedCallback(UnrealEngine.Framework.CharacterLandedDelegate) Method
Sets the callback function that is called when the character landing after falling
```csharp
public void SetOnLandedCallback(UnrealEngine.Framework.CharacterLandedDelegate callback);
```
#### Parameters
<a name='UnrealEngine-Framework-Character-SetOnLandedCallback(UnrealEngine-Framework-CharacterLandedDelegate)-callback'></a>
`callback` [CharacterLandedDelegate(UnrealEngine.Framework.Hit)](./CharacterLandedDelegate(Hit).md 'UnrealEngine.Framework.CharacterLandedDelegate(UnrealEngine.Framework.Hit)')

1 change: 1 addition & 0 deletions API/Character.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.O
- [Crouch()](./Character-Crouch().md 'UnrealEngine.Framework.Character.Crouch()')
- [Jump()](./Character-Jump().md 'UnrealEngine.Framework.Character.Jump()')
- [Launch(System.Numerics.Vector3, bool, bool)](./Character-Launch(Vector3_bool_bool).md 'UnrealEngine.Framework.Character.Launch(System.Numerics.Vector3, bool, bool)')
- [SetOnLandedCallback(UnrealEngine.Framework.CharacterLandedDelegate)](./Character-SetOnLandedCallback(CharacterLandedDelegate).md 'UnrealEngine.Framework.Character.SetOnLandedCallback(UnrealEngine.Framework.CharacterLandedDelegate)')
- [StopCrouching()](./Character-StopCrouching().md 'UnrealEngine.Framework.Character.StopCrouching()')
- [StopJumping()](./Character-StopJumping().md 'UnrealEngine.Framework.Character.StopJumping()')
10 changes: 10 additions & 0 deletions API/CharacterLandedDelegate(Hit).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### [UnrealEngine.Framework](./UnrealEngine-Framework.md 'UnrealEngine.Framework')
## CharacterLandedDelegate(UnrealEngine.Framework.Hit) Delegate
Delegate for character landing events
```csharp
public delegate void CharacterLandedDelegate(in UnrealEngine.Framework.Hit hit);
```
#### Parameters
<a name='UnrealEngine-Framework-CharacterLandedDelegate(UnrealEngine-Framework-Hit)-hit'></a>
`hit` [Hit](./Hit.md 'UnrealEngine.Framework.Hit')

1 change: 1 addition & 0 deletions API/UnrealEngine-Framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
- [ActorHitDelegate(UnrealEngine.Framework.ActorReference, UnrealEngine.Framework.ActorReference, System.Numerics.Vector3, UnrealEngine.Framework.Hit)](./ActorHitDelegate(ActorReference_ActorReference_Vector3_Hit).md 'UnrealEngine.Framework.ActorHitDelegate(UnrealEngine.Framework.ActorReference, UnrealEngine.Framework.ActorReference, System.Numerics.Vector3, UnrealEngine.Framework.Hit)')
- [ActorKeyDelegate(UnrealEngine.Framework.ActorReference, string)](./ActorKeyDelegate(ActorReference_string).md 'UnrealEngine.Framework.ActorKeyDelegate(UnrealEngine.Framework.ActorReference, string)')
- [ActorOverlapDelegate(UnrealEngine.Framework.ActorReference, UnrealEngine.Framework.ActorReference)](./ActorOverlapDelegate(ActorReference_ActorReference).md 'UnrealEngine.Framework.ActorOverlapDelegate(UnrealEngine.Framework.ActorReference, UnrealEngine.Framework.ActorReference)')
- [CharacterLandedDelegate(UnrealEngine.Framework.Hit)](./CharacterLandedDelegate(Hit).md 'UnrealEngine.Framework.CharacterLandedDelegate(UnrealEngine.Framework.Hit)')
- [ComponentCursorDelegate(UnrealEngine.Framework.ComponentReference)](./ComponentCursorDelegate(ComponentReference).md 'UnrealEngine.Framework.ComponentCursorDelegate(UnrealEngine.Framework.ComponentReference)')
- [ComponentHitDelegate(UnrealEngine.Framework.ComponentReference, UnrealEngine.Framework.ComponentReference, System.Numerics.Vector3, UnrealEngine.Framework.Hit)](./ComponentHitDelegate(ComponentReference_ComponentReference_Vector3_Hit).md 'UnrealEngine.Framework.ComponentHitDelegate(UnrealEngine.Framework.ComponentReference, UnrealEngine.Framework.ComponentReference, System.Numerics.Vector3, UnrealEngine.Framework.Hit)')
- [ComponentKeyDelegate(UnrealEngine.Framework.ComponentReference, string)](./ComponentKeyDelegate(ComponentReference_string).md 'UnrealEngine.Framework.ComponentKeyDelegate(UnrealEngine.Framework.ComponentReference, string)')
Expand Down
4 changes: 3 additions & 1 deletion Source/Managed/Framework/Codegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace UnrealEngine.Framework {
// Automatically generated

internal static class Shared {
internal const int checksum = 0x29D;
internal const int checksum = 0x29E;
internal static Dictionary<int, IntPtr> userFunctions = new();
private const string dynamicTypesAssemblyName = "UnrealEngine.DynamicTypes";
private static readonly ModuleBuilder moduleBuilder = AssemblyBuilder.DefineDynamicAssembly(new(dynamicTypesAssemblyName), AssemblyBuilderAccess.RunAndCollect).DefineDynamicModule(dynamicTypesAssemblyName);
Expand Down Expand Up @@ -333,6 +333,7 @@ internal static unsafe Dictionary<int, IntPtr> Load(IntPtr* events, IntPtr funct
Character.stopCrouching = (delegate* unmanaged[Cdecl]<IntPtr, void>)characterFunctions[head++];
Character.jump = (delegate* unmanaged[Cdecl]<IntPtr, void>)characterFunctions[head++];
Character.stopJumping = (delegate* unmanaged[Cdecl]<IntPtr, void>)characterFunctions[head++];
Character.setOnLandedCallback = (delegate* unmanaged[Cdecl]<IntPtr, IntPtr, void>)characterFunctions[head++];
}

unchecked {
Expand Down Expand Up @@ -1524,6 +1525,7 @@ unsafe partial class Character {
internal static delegate* unmanaged[Cdecl]<IntPtr, void> stopCrouching;
internal static delegate* unmanaged[Cdecl]<IntPtr, void> jump;
internal static delegate* unmanaged[Cdecl]<IntPtr, void> stopJumping;
internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr, void> setOnLandedCallback;
}

unsafe partial class Controller {
Expand Down
15 changes: 15 additions & 0 deletions Source/Managed/Framework/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,11 @@ public override bool Equals(object value) {
/// </summary>
public delegate void ComponentKeyDelegate(ComponentReference component, string key);

/// <summary>
/// Delegate for character landing events
/// </summary>
public delegate void CharacterLandedDelegate(in Hit hit);

/// <summary>
/// Provides additional static constants and methods for mathematical functions that are lack in <see cref="System.Math"/>, <see cref="System.MathF"/>, and <see cref="System.Numerics"/>
/// </summary>
Expand Down Expand Up @@ -5442,6 +5447,16 @@ public Character(string name = null, Blueprint blueprint = null) {
/// Stops the character from jumping on the next update
/// </summary>
public void StopJumping() => stopJumping(Pointer);

/// <summary>
/// Sets the callback function that is called when the character landing after falling
/// </summary>
public void SetOnLandedCallback(CharacterLandedDelegate callback) {
if (callback == null)
throw new ArgumentNullException(nameof(callback));

setOnLandedCallback(Pointer, Collector.GetFunctionPointer(callback));
}
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Source/Native/Source/UnrealCLR/Private/UnrealCLR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ void UnrealCLR::Module::StartupModule() {
Shared::CharacterFunctions[head++] = (void*)&UnrealCLRFramework::Character::StopCrouching;
Shared::CharacterFunctions[head++] = (void*)&UnrealCLRFramework::Character::Jump;
Shared::CharacterFunctions[head++] = (void*)&UnrealCLRFramework::Character::StopJumping;
Shared::CharacterFunctions[head++] = (void*)&UnrealCLRFramework::Character::SetOnLandedCallback;

checksum += head;
}
Expand Down Expand Up @@ -1351,6 +1352,8 @@ void UnrealCLR::Module::Invoke(void(*ManagedFunction)(), Argument Value) {
reinterpret_cast<UnrealCLRFramework::ComponentCursorDelegate>(ManagedFunction)(static_cast<UPrimitiveComponent*>(Value.Callback.Parameters[0]));
else if (Value.Callback.Type == CallbackType::ComponentKeyDelegate)
reinterpret_cast<UnrealCLRFramework::ComponentKeyDelegate>(ManagedFunction)(static_cast<UPrimitiveComponent*>(Value.Callback.Parameters[0]), static_cast<const char*>(Value.Callback.Parameters[1]));
else if (Value.Callback.Type == CallbackType::CharacterLandedDelegate)
reinterpret_cast<UnrealCLRFramework::CharacterLandedDelegate>(ManagedFunction)(static_cast<const UnrealCLRFramework::Hit*>(Value.Callback.Parameters[0]));
break;
}

Expand Down
8 changes: 8 additions & 0 deletions Source/Native/Source/UnrealCLR/Private/UnrealCLRFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,14 @@ namespace UnrealCLRFramework {
void StopJumping(ACharacter* Character) {
Character->StopJumping();
}

void SetOnLandedCallback(ACharacter* Character, CharacterLandedDelegate Callback) {
UUnrealCLRCharacter* character = NewObject<UUnrealCLRCharacter>(Character);

character->LandedCallback = (void*)Callback;

Character->LandedDelegate.AddDynamic(character, &UUnrealCLRCharacter::Landed);
}
}

namespace Controller {
Expand Down
12 changes: 12 additions & 0 deletions Source/Native/Source/UnrealCLR/Private/UnrealCLRLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ FManagedFunction UUnrealCLRLibrary::FindManagedFunction(FString Method, bool Opt
Result = managedFunction.Pointer != nullptr;

return managedFunction;
}

UUnrealCLRCharacter::UUnrealCLRCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { }

void UUnrealCLRCharacter::Landed(const FHitResult& Hit) {
UnrealCLRFramework::Hit hit(Hit);

void* parameters[1] = {
&hit
};

UnrealCLR::ManagedCommand(UnrealCLR::Command(LandedCallback, UnrealCLR::Callback(parameters, UnrealCLR::CallbackType::CharacterLandedDelegate)));
}
3 changes: 2 additions & 1 deletion Source/Native/Source/UnrealCLR/Public/UnrealCLR.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ namespace UnrealCLR {
ComponentOverlapDelegate,
ComponentHitDelegate,
ComponentCursorDelegate,
ComponentKeyDelegate
ComponentKeyDelegate,
CharacterLandedDelegate
};

enum struct ArgumentType : int32 {
Expand Down
3 changes: 3 additions & 0 deletions Source/Native/Source/UnrealCLR/Public/UnrealCLRFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ namespace UnrealCLRFramework {

typedef void (*ComponentKeyDelegate)(UPrimitiveComponent* Component, const char* Key);

typedef void (*CharacterLandedDelegate)(const Hit* Hit);

// Enumerable

enum struct ObjectType : int32 {
Expand Down Expand Up @@ -550,6 +552,7 @@ namespace UnrealCLRFramework {
static void StopCrouching(ACharacter* Character);
static void Jump(ACharacter* Character);
static void StopJumping(ACharacter* Character);
static void SetOnLandedCallback(ACharacter* Character, CharacterLandedDelegate Callback);
}

namespace Controller {
Expand Down
12 changes: 12 additions & 0 deletions Source/Native/Source/UnrealCLR/Public/UnrealCLRLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ class UUnrealCLRLibrary : public UBlueprintFunctionLibrary {

UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = ".NET", meta = (ToolTip = "Finds the managed function from loaded assembly, optional parameter suppresses errors if the function was not found"))
static FManagedFunction FindManagedFunction(FString Method, bool Optional, bool& Result);
};

UCLASS()
class UUnrealCLRCharacter : public UObject {
GENERATED_UCLASS_BODY()

public:

void* LandedCallback;

UFUNCTION()
void Landed(const FHitResult& Hit);
};

0 comments on commit ae76fef

Please sign in to comment.