github PixeyeHQ/actors.unity 2018.10.27
ACTORS framework

latest releases: 2020.06.5, 2020.06.4, 2020.06.3...
6 years ago

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

Don't miss a new actors.unity release

NewReleases is sending notifications on new releases.