Changes
Groups
Previously groups worked with entity index taken from a group. Now all groups correspond to entity directly.
This lead to several changes in code:
- Events such as Group.OnAdd/OnRemove listen to the entity, not the group index.
- Use foreach to iterate through entities in groups:
foreach (var entity in groupMotion)
{
var cMotion = entity.ComponentMotion();
var cRigid = entity.ComponentRigidBody();
var cBounds = entity.ComponentBounds();
var pos = cRigid.body.position;
pos += cMotion.stepFixed;
pos.x = Mathf.Clamp(pos.x, cBounds.limitation.min.x, cBounds.limitation.max.x);
pos.y = Mathf.Clamp(pos.y, cBounds.limitation.min.y, cBounds.limitation.max.y);
cRigid.body.MovePosition(pos);
}
Components
To use components directly from entities you will have to write some extension methods to a component script:
[Serializable]
public class ComponentMotion : IComponent
{
public TemplateMotion template;
[FoldoutGroup("Debug")] public float speedActual;
[FoldoutGroup("Debug")] public Vector2 direction;
[FoldoutGroup("Debug")] public Vector2 step;
[FoldoutGroup("Debug")] public Vector2 stepFixed;
[HideInInspector] public float speedOverride = 1;
}
// The extension methods pattern you will need to add to each component.
public static partial class Game
{
public static ComponentMotion ComponentMotion(this int entity)
{
return Storage<ComponentMotion>.Instance.components[entity];
}
public static bool TryGetComponentMotion(this int entity, out ComponentMotion component)
{
component = Storage<ComponentMotion>.Instance.TryGet(entity);
return component != null;
}
}