Added ability to play an animation from C#
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user