Async Managed Entity-Component Framework for Unity
- Open Unity Package Manager
- Click ➕ button → “Add package from git URL…”
- Enter https://github.com/Hoodrij/Yogurt.git
-
⚔️ Roguelike sample project
https://github.com/Hoodrij/Yogurt-Roguelike -
💣 Arena more complex sample project
https://github.com/Hoodrij/Yogurt-Arena
An Entity is nothing more than storage for components.
Entity entity = Entity.Create();
Assert.IsTrue(entity != Entity.Null);
Assert.IsTrue(entity != default);
Assert.IsTrue(entity.Exist);
entity.Kill();
Assert.IsFalse(entity.Exist);
Components are classes that contain data.
public class Health : IComponent
{
public int Value;
}
Entity has a bunch of methods to operate with components.
entity.Add(new Health());
entity.Set(new Health());
entity.Has<Health>();
entity.Remove<Health>();
entity.Get<Health>();
entity.TryGet(out Health health);
Aspect is an Entity with a defined set of Components. Used to speed up the interaction with Entity.
public struct PlayerAspect : IAspect
{
public Entity Entity { get; set; }
public PlayerTag Tag => this.Get<PlayerTag>();
public Health Health => this.Get<Health>();
public Transform Transform => this.Get<Transform>();
public NestedAspect NestedAspect => this.Get<NestedAspect>();
}
PlayerAspect player = anyEntity.As<PlayerAspect>();
player.Health.Value -= 1;
player.Add(new OtherComponent());
player.Exist();
player.Kill();
Query is used to get required Entities.
-
Getting a Query
// Query of an Entity var query = Query.Of<Health>() .With<PlayerTag>() .Without<DeadTag>(); // Or Query of an Aspect var query = Query.Of<PlayerAspect>();
-
Operating with Query
// Iterate over foreach (Entity entity in query) { } // Or get Single Entity entity = query.Single(); // Common IEnumerable methods query.Where(entity => entity.Get<Health>().Value > 50) .Any();
-
Fast Single Query
// Of Component
GameData data = Query.Single<GameData>();
// Or of an Aspect
PlayerAspect playerAspect = Query.Single<PlayerAspect>();
Entity provides few methods to combine them into a Parent-Child relationship. All Childs will be killed after a Parent death.
entity.SetParent(parentEntity);
entity.UnParent();
You can access all the Entities list with full meta like this
new Yogurt.Debug().Entities;
You can Execute this at debug mode right inside of you IDE.
To enable debug logging add YOGURT_DEBUG to your Scripting Define Symbols