Added ability to play an animation from C#

This commit is contained in:
Antoine Pilote
2024-03-16 12:15:52 -04:00
parent ea1339a8e8
commit a80fb5241e
2 changed files with 40 additions and 1 deletions

View File

@@ -169,6 +169,33 @@ namespace Nuake {
return false;
}
void Play(int entityId, Coral::NativeString animation)
{
Entity entity = Entity((entt::entity)(entityId), Engine::GetCurrentScene().get());
if (entity.IsValid() && entity.HasComponent<SkinnedModelComponent>())
{
auto& skinnedModel = entity.GetComponent<SkinnedModelComponent>();
if (skinnedModel.ModelResource)
{
auto& model = skinnedModel.ModelResource;
// Find animation from name
int animIndex = 0;
for (const auto& anim : model->GetAnimations())
{
if (anim->GetName() == animation.ToString())
{
model->PlayAnimation(animIndex);
}
animIndex++;
}
}
}
}
void Nuake::SceneNetAPI::RegisterMethods()
{
RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent);
@@ -182,6 +209,8 @@ namespace Nuake {
RegisterMethod("CharacterControllerComponent.MoveAndSlideIcall", &MoveAndSlide);
RegisterMethod("CharacterControllerComponent.IsOnGroundIcall", &IsOnGround);
RegisterMethod("SkinnedModelComponent.PlayIcall", &Play);
}
}

View File

@@ -152,10 +152,20 @@ namespace Nuake.Net
public class SkinnedModelComponent : IComponent
{
public SkinnedModelComponent(int entityId) { }
internal static unsafe delegate*<int, NativeString, void> PlayIcall;
public SkinnedModelComponent(int entityId)
{
EntityID = entityId;
}
public bool Playing { get; set; }
public int CurrentAnimation { get; set; }
public void Play(String name)
{
unsafe { PlayIcall(EntityID, name); }
}
}
public class BoneComponent : IComponent