Files
XCEngine/参考/Fermion/Photon/Scene/Entity.cs

63 lines
1.1 KiB
C#

using System;
using System.Runtime.CompilerServices;
namespace Fermion
{
public class Entity
{
protected Entity() { ID = 0; }
internal Entity(ulong id)
{
ID = id;
}
public ulong ID;
public Vector3 Translation
{
get
{
InternalCalls.TransformComponent_GetTranslation(ID, out Vector3 result);
return result;
}
set
{
InternalCalls.TransformComponent_SetTranslation(ID, ref value);
}
}
public bool HasComponent<T>() where T : Component, new()
{
Type componentType = typeof(T);
return InternalCalls.Entity_HasComponent(ID, componentType);
}
public T GetComponent<T>() where T : Component, new()
{
if (!HasComponent<T>())
return null;
T component = new T() { Entity = this };
return component;
}
public T AddComponent<T>() where T : Component, new()
{
Type componentType = typeof(T);
InternalCalls.Entity_AddComponent(ID, componentType);
return GetComponent<T>();
}
public Entity FindEntityByName(string name)
{
ulong entityID = InternalCalls.Entity_FindEntityByName(name);
if (entityID == 0)
return null;
return new Entity(entityID);
}
}
}