Added Get/Set for entity name in .Net API

This commit is contained in:
Antoine Pilote
2024-08-15 19:08:50 -04:00
parent 711a9a9751
commit ead6ff6645
4 changed files with 70 additions and 13 deletions

View File

@@ -177,6 +177,29 @@ namespace Nuake {
return scene->GetRelativeEntityFromPath(entity, input).GetHandle();
}
Coral::String EntityGetName(int handle)
{
Entity entity = { (entt::entity)(handle), Engine::GetCurrentScene().get() };
if (!entity.IsValid())
{
return Coral::String();
}
return Coral::String::New(entity.GetComponent<NameComponent>().Name);
}
void EntitySetName(int handle, Coral::String newName)
{
Entity entity = { (entt::entity)(handle), Engine::GetCurrentScene().get() };
if (!entity.IsValid())
{
return;
}
const std::string newEntityName = Engine::GetCurrentScene()->GetUniqueEntityName(newName);
entity.GetComponent<NameComponent>().Name = newEntityName;
}
void TransformSetPosition(int entityId, float x, float y, float z)
{
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
@@ -336,25 +359,33 @@ namespace Nuake {
RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent);
RegisterMethod("Entity.EntityHasManagedInstanceIcall", &EntityHasManagedInstance);
RegisterMethod("Entity.EntityGetEntityIcall", &EntityGetEntity);
RegisterMethod("Entity.EntityGetNameIcall", &EntityGetName);
RegisterMethod("Entity.EntitySetNameIcall", &EntitySetName);
// Scene
RegisterMethod("Scene.GetEntityIcall", &GetEntity);
RegisterMethod("Scene.GetEntityScriptFromNameIcall", &GetEntityScriptFromName);
RegisterMethod("Scene.GetEntityScriptFromHandleIcall", &GetEntityScriptFromHandle);
RegisterMethod("Scene.InstancePrefabIcall", &InstancePrefab);
// Components
// Transform
RegisterMethod("TransformComponent.SetPositionIcall", &TransformSetPosition);
RegisterMethod("TransformComponent.GetPositionIcall", &TransformGetPosition);
RegisterMethod("TransformComponent.GetGlobalPositionIcall", &TransformGetGlobalPosition);
RegisterMethod("TransformComponent.RotateIcall", &TransformRotate);
// Camera
RegisterMethod("CameraComponent.GetDirectionIcall", &CameraGetDirection);
// Character Controller
RegisterMethod("CharacterControllerComponent.MoveAndSlideIcall", &MoveAndSlide);
RegisterMethod("CharacterControllerComponent.IsOnGroundIcall", &IsOnGround);
// Skinned
RegisterMethod("SkinnedModelComponent.PlayIcall", &Play);
// Navigation Mesh
RegisterMethod("NavMeshVolumeComponent.FindPathIcall", &NavMeshComponentFindPath);
}

View File

@@ -367,9 +367,7 @@ namespace Nuake
else
{
// In the case where the entity doesnt have an instance, we create one
auto newEntity = m_BaseEntityType.CreateInstance();
newEntity.SetPropertyValue("ECSHandle", scriptEntity.GetHandle());
newEntity.SetPropertyValue("ID", scriptEntity.GetID());
auto newEntity = m_BaseEntityType.CreateInstance(scriptEntity.GetHandle());
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, newEntity);
}
}

View File

@@ -24,6 +24,9 @@ namespace Nuake.Net
internal static unsafe delegate*<int, int, bool> EntityHasComponentIcall;
internal static unsafe delegate*<int, bool> EntityHasManagedInstanceIcall;
internal static unsafe delegate*<int, NativeString, int> EntityGetEntityIcall;
internal static unsafe delegate*<int, NativeString> EntityGetNameIcall;
internal static unsafe delegate*<int, NativeString, void> EntitySetNameIcall;
public enum ComponentTypes
{
Unknown = -1,
@@ -55,6 +58,37 @@ namespace Nuake.Net
public int ID { get; set; }
public int ECSHandle { get; set; }
public string Name
{
get
{
unsafe
{
NativeString name = EntityGetNameIcall(ECSHandle);
return name;
}
}
set
{
if(String.IsNullOrEmpty(value))
{
Engine.Log("Invalid entity name: cannot be empty.");
return;
}
unsafe
{
EntitySetNameIcall(ECSHandle, value);
}
}
}
public Entity() { }
public Entity(int handle)
{
ECSHandle = handle;
}
public virtual void OnInit() { }
public virtual void OnUpdate(float dt) { }
public virtual void OnFixedUpdate(float dt) { }
@@ -78,7 +112,7 @@ namespace Nuake.Net
}
else
{
entityInstance = new Entity { ECSHandle = entity };
entityInstance = new Entity(ECSHandle);
}
}
@@ -144,7 +178,7 @@ namespace Nuake.Net
}
else
{
entityInstance = new Entity { ECSHandle = entityHandle };
entityInstance = new Entity(entityHandle);
}
}

View File

@@ -49,10 +49,7 @@ namespace Nuake.Net
throw new Exception("Entity not found");
}
Entity entity = new Entity
{
ECSHandle = handle
};
Entity entity = new Entity(handle);
return entity;
}
@@ -76,10 +73,7 @@ namespace Nuake.Net
// return entity as T;
//}
Entity entity = new Entity
{
ECSHandle = handle
};
Entity entity = new Entity(handle);
return entity;
}