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> /// The step is triggered in response to another event /// </summary> /// <param name="token"></param> /// <param name="condition"></param> public void Step(ref LifterLandingEvent token, int condition) { if (token.Landed) { LandEvent(token.LifterID, token.LiftableID); } else { LeaveEvent(token.LifterID, token.LiftableID); } }
public override void DoStuff() { LifterLandingEvent landEvent = new LifterLandingEvent { LifterID = 10, LiftableID = 20, Landed = false }; lifterCollectionEngine.Step(ref landEvent, 0); }
/// <summary> /// If a liftable is not snapped to a engine it is snapped to it, and viceversa /// </summary> public void InvertSnap() { var lifters = entityViewsDB.QueryIndexableEntityViews <AnyLifterSnapView>(); var liftables = entityViewsDB.QueryIndexableEntityViews <AnyLiftableSnapView>(); // This is very inefficient. It is just to setup quickly a demo. foreach (var liftable in liftables) { int liftableID = liftable.Key; var liftableView = liftable.Value; var lifterPos = liftableView.position.Position; float minDistance = float.MaxValue; int nearestLifterID = -1; foreach (var lifter in lifters) { int lifterID = lifter.Key; var lifterView = lifter.Value; var position = lifterView.position.Position; float tempDistance = (lifterPos - position).SqrMagnitude(); // find nearest lifter if (tempDistance < minDistance) { minDistance = tempDistance; nearestLifterID = lifterID; } } bool isCurrentlyLanded = liftableView.liftable.Carrier != -1; var landingEvent = new LifterLandingEvent { LifterID = nearestLifterID, LiftableID = liftableID, Landed = !isCurrentlyLanded // invert the landing state }; landSequence.Next(this, ref landingEvent); } }