Skip to content

ECS implementation for cell lists algorithm

License

MIT, Unknown licenses found

Licenses found

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

KOTlK/CellLists

Repository files navigation

CellLists

Algorithm that divides world into small same pieces for cheaper collision detection etc.

Dependencies

LeoEcsLite

LeoEcsLite-di

Unity dependencies - inside Package.json

Installation

Git

Make sure you have standalone git installed.

  • Install dependencies listed above.
  • Unity -> PackageManager -> Add package from git URL
  • Paste: https://github.com/KOTlK/CellLists.git

As Unity Package

  • Download latest package from release page
  • Assets -> Import Package -> Custom Package...
  • Select downloaded package in explorer window

Usage

Simple example of usage can be found inside Samples~ folder

  • Add CellListsInitSystem into your systems
  • Add InsertTransformSystem into your systems
  • Add RemoveFromCellListsSystem into your systems
  • Add CellListsRebuildSystem into your systems
  • Create CellListsConfig and inject it in your systems
var world = new EcsWorld();
var systems = new EcsSystems(world);
var config = new CellListsConfig()
{
    Center = Vector2.zero,
    Size = new Vector2(100, 100),
    Height = 10,
    Width = 10
};

systems
    .Add(new CellListsInitSystem())
    .Add(new InsertTransformSystem())
    .Add(new RemoveFromCellListsSystem())
    .Add(new CellListsRebuildSystem())
    .Inject(config)
    .Init();

To insert Transform into cells add component InsertInCellLists to transform.

To remove Transform component from cell, create new entity with RemoveFromCellLists component on it and fill field TransformEntity

To get cells, filter components with Cell, CellNeighbours components.

Cell is a cell. CellNeighbours contains indexes of Cells, closest to the cell, and indexes of Transform components, that belongs to the cell. Transform components contains its position and cell, it belongs to.

CellListsRebuildSystem can be called with some interval via Interval Systems extension.

About

ECS implementation for cell lists algorithm

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Languages