|
|
@ -74,14 +74,6 @@ public unsafe class EntityRef |
|
|
|
public override EntityRef Remove(Identifier id) { ecs_remove_id(World, this, id); return this; } |
|
|
|
public override EntityRef Remove(Identifier id) { ecs_remove_id(World, this, id); return this; } |
|
|
|
public override bool Has(Identifier id) => ecs_has_id(World, this, id); |
|
|
|
public override bool Has(Identifier id) => ecs_has_id(World, this, id); |
|
|
|
|
|
|
|
|
|
|
|
public override T Get<T>(Identifier id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var ptr = ecs_get_id(World, this, id); |
|
|
|
|
|
|
|
if (ptr == null) throw new Exception($"Component {typeof(T)} not found on {this}"); |
|
|
|
|
|
|
|
return typeof(T).IsValueType ? Unsafe.Read<T>(ptr) |
|
|
|
|
|
|
|
: (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target!; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override T? GetOrNull<T>(Identifier id) |
|
|
|
public override T? GetOrNull<T>(Identifier id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var ptr = ecs_get_id(World, this, id); |
|
|
|
var ptr = ecs_get_id(World, this, id); |
|
|
@ -95,6 +87,14 @@ public unsafe class EntityRef |
|
|
|
return (ptr != null) ? (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target! : null; |
|
|
|
return (ptr != null) ? (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target! : null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override T GetOrThrow<T>(Identifier id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var ptr = ecs_get_id(World, this, id); |
|
|
|
|
|
|
|
if (ptr == null) throw new Exception($"Component {typeof(T)} not found on {this}"); |
|
|
|
|
|
|
|
return typeof(T).IsValueType ? Unsafe.Read<T>(ptr) |
|
|
|
|
|
|
|
: (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target!; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override ref T GetRefOrNull<T>(Identifier id) |
|
|
|
public override ref T GetRefOrNull<T>(Identifier id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var @ref = ecs_ref_init_id(World, this, id); |
|
|
|
var @ref = ecs_ref_init_id(World, this, id); |
|
|
|