Created
July 22, 2019 07:45
-
-
Save mzaks/cc46cc7cbd88a92526a476ce279b861d to your computer and use it in GitHub Desktop.
Examples for Entity extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static T GetComponentData<T>(this Entity entity, World world = null) where T: struct, IComponentData | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
return world.EntityManager.GetComponentData<T>(entity); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void AddComponent<T>(this Entity entity, World world = null) where T: struct, IComponentData | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
world.EntityManager.AddComponent(entity, ComponentType.ReadWrite<T>()); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void AddComponentData<T>(this Entity entity, T componentData, World world = null) where T: struct, IComponentData | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
world.EntityManager.AddComponentData(entity, componentData); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void SetComponentData<T>(this Entity entity, T componentData, World world = null) where T: struct, IComponentData | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
world.EntityManager.SetComponentData(entity, componentData); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static bool HasComponent<T>(this Entity entity, World world = null) where T: struct, IComponentData | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
return world.EntityManager.HasComponent<T>(entity); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void RemoveComponent<T>(this Entity entity, World world = null) where T: struct, IComponentData | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
world.EntityManager.RemoveComponent<T>(entity); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void DestroyEntity(this Entity entity, World world = null) | |
{ | |
if (world == null) | |
{ | |
world = World.Active; | |
} | |
world.EntityManager.DestroyEntity(entity); | |
} | |
public static void DestroyLater(this Entity entity, EntityCommandBuffer buffer) | |
{ | |
buffer.DestroyEntity(entity); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment