add FindEntityByName function

This commit is contained in:
2025-10-26 13:12:04 +08:00
parent 9c45444354
commit e8dec2e2d3
13 changed files with 129 additions and 37 deletions

View File

@ -5,6 +5,12 @@ namespace Hazel
{
public static class InternalCalls
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static ulong Entity_FindEntityByName(String name);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static object GetScriptInstance(ulong entityID);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static bool Entity_HasComponent(ulong entityID, Type componentType);

View File

@ -32,11 +32,26 @@ namespace Hazel{
public T GetComponent<T>() where T : Component, new()
{
if(!HasComponent<T>())
if (!HasComponent<T>())
return null;
T component = new T() { Entity = this };
return component;
}
public Entity FindEntityByName(string name)
{
ulong entityID = InternalCalls.Entity_FindEntityByName(name);
if (entityID == 0)
return null;
return new Entity(entityID);
}
public T As<T>() where T : Entity, new()
{
object instance = InternalCalls.GetScriptInstance(ID);
return instance as T;
}
}
}

View File

@ -40,6 +40,13 @@ namespace Hazel
Z = scale;
}
public Vector3(Vector2 xy, float z)
{
X = xy.X;
Y = xy.Y;
Z = z;
}
public Vector3(float x, float y, float z) {
X = x;
Y = y;