Skip to content
/ Yogurt Public

🥛 Async Managed Component-Oriented framework for Unity

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

Hoodrij/Yogurt

Repository files navigation

🥛 Yogurt

Async Managed Entity-Component Framework for Unity

Installation

  1. Open Unity Package Manager
  2. Click ➕ button → “Add package from git URL…
  3. Enter https://github.com/Hoodrij/Yogurt.git

Examples

Overview

🏷️ Entity

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);

🏷️ Component

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

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

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 hierarchy

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();

🏷️ Debug

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