static void moveSystem(Context context) { var entities = context.GetEntities(Matcher.AllOf(Matcher.Move, Matcher.Position)); foreach(var entity in entities) { var move = entity.move; var pos = entity.position; entity.ReplacePosition(pos.x, pos.y + move.speed); } }
/// <summary> /// override this in Scene subclasses and do your loading here. This is called from the contructor after the scene sets itself up but /// before begin is ever called. /// </summary> public virtual void Initialize() { Global.DebugRenderEnabled = false; // // start ECS (Game entities & components & systems) // EntityContext = Entitas.Contexts.Default; Global.EntityContext = EntityContext; // // List of all entities, List of entities destroyed // GameEntities = new List <Entity>(); Global.GameEntityToDestroy = new Dictionary <Entity, bool>(); SceneEntities = new List <Entity>(); Global.SceneEntityToDestroy = new Dictionary <Entity, bool>(); // // start ECS (Scene UI & components) // SceneContext = Entitas.Contexts.Default; //SceneSystems = new Feature(null); Global.SceneContext = SceneContext; //znznznznznznznznznznznznznznznznznzn // Camera 2D setup //znznznznznznznznznznznznznznznznznzn Camera = new Camera2D(); Camera.target = Global.WindowCenter; Camera.offset = Global.WindowCenter; Camera.rotation = 0; Camera.zoom = 1.0f; CameraEnabled = false; CameraType2D = Camera2DType.FollowPlayer; //free camera no bounds }
static void groupExample(Context context) { context.GetGroup(Matcher.Position).GetEntities(); // ---------------------------- context.GetGroup(Matcher.Position).OnEntityAdded += (group, entity, index, component) => { // Do something }; }
protected ReactiveSystem(Context context) { _collector = GetTrigger(context); _buffer = new List<Entity>(); }
/// Specify the collector that will trigger the ReactiveSystem. protected abstract Collector GetTrigger(Context context);
public ContextStillHasRetainedEntitiesException(Context context) : base("'" + context + "' detected retained entities " + "although all entities got destroyed!", "Did you release all entities? Try calling context.ClearGroups() " + "and systems.ClearReactiveSystems() before calling " + "context.DestroyAllEntities() to avoid memory leaks.") { }
public ContextInfoException(Context context, ContextInfo contextInfo) : base("Invalid ContextInfo for '" + context + "'!\nExpected " + context.totalComponents + " componentName(s) but got " + contextInfo.componentNames.Length + ":", string.Join("\n", contextInfo.componentNames)) { }
public ContextEntityIndexDoesNotExistException(Context context, string name) : base("Cannot get EntityIndex '" + name + "' from context '" + context + "'!", "No EntityIndex with this name has been added.") { }
public ContextEntityIndexDoesAlreadyExistException(Context context, string name) : base("Cannot add EntityIndex '" + name + "' to context '" + context + "'!", "An EntityIndex with this name has already been added.") { }
static void collectorExample(Context context) { var group = context.GetGroup(Matcher.Position); var collector = group.CreateCollector(GroupEvent.Added); // ---------------------------- foreach(var e in collector.collectedEntities) { // do something } collector.ClearCollectedEntities(); // ---------------------------- collector.Deactivate(); }
static void animatingComponent(Context context) { var e = context.animatingEntity; var isAnimating = context.isAnimating; context.isAnimating = true; context.isAnimating = false; }
#pragma warning disable static void userComponent(Context context, UserComponent component) { var e = context.userEntity; var name = context.user.name; var has = context.hasUser; context.SetUser("John", 42); context.ReplaceUser("Max", 24); context.RemoveUser(); }