public override void Update() { //seems actually I found a bug in unity. GetMousebuttonDown returns true for 2 consecutive frames. //weird if (Input.GetMouseButtonDown(0)) { Snap = true; } if (Input.GetMouseButtonDown(1)) { Snap = false; } if (Snap != OldSnap) { OldSnap = Snap; LifterLandingEvent landEvent = new LifterLandingEvent { LifterID = 1, LiftableID = 2, Landed = Snap }; // Simulate the Sequencer by just calling "Step" lifterCollectionEngine.Step(ref landEvent, 0); } movementPhaser.ScheduleMovement(); }
/// <summary> /// Wire all the game logic and setup the engines /// </summary> private IEnumerator SetupEngines(EnginesRoot ecs) { IEntityFactory entityFactory = ecs.GenerateEntityFactory(); IEntityFunctions entityFunctions = ecs.GenerateEntityFunctions(); MovementScheduler movementPhaser = new MovementScheduler(); Sequencer landingEventResponseSequence = new Sequencer(); var lifterCollection = new LifterCollectionEngine(); var lifterMovement = new LifterMovementEngine(movementPhaser); var movingPosition = new MovingPositionEngine(movementPhaser); var lifterSnap = new AnyLifterSnapEngine(movementPhaser, landingEventResponseSequence); ecs.AddEngine(lifterCollection); ecs.AddEngine(lifterMovement); ecs.AddEngine(movingPosition); // a sequence is just a set of "labels" each label can be triggered by the owning engine // and cause the listed engines to receive the messages. landingEventResponseSequence.SetSequence ( new Steps { { // LABEL // owning engine lifterSnap, // when lifterSnap calls "next" the message is delivered "To"... //listed engines new To { lifterCollection //.. lifterCollection } } } ); while (true) { movementPhaser.ScheduleMovement(); yield return(null); } }