// init invoked from TouchFSM public void fire(Events e, TouchScreenPosition t) { //States oldState = currentState; switch (currentState) { case States.FollowingPlayer: switch (e) { case Events.Press: if (!touchModel.isGuiItem(t)) { uiPlayAreaPressSignal.Dispatch(t); } break; case Events.Pan: currentState = States.Pan; break; case Events.LongPress: currentState = States.PlayerAction; uiPlayerActionSignal.Dispatch(t, true); break; default: break; } break; case States.Menu: break; case States.Pan: switch (e) { case Events.Press: currentState = States.FollowingPlayer; uiPanBackToPlayerSignal.Dispatch(); break; default: break; } break; case States.PlayerAction: switch (e) { case Events.Release: currentState = States.FollowingPlayer; uiPlayerActionSignal.Dispatch(t, false); break; } break; } // UnityEngine.Debug.Log ("UIFSM - " + oldState + " (" + e +") -> " + currentState); }
public static bool IsTouchOnWater(TouchScreenPosition touchScreenPosition) { return (Physics2D.GetRayIntersection( new Ray( (Vector3)touchScreenPosition.world - Vector3.forward, Vector3.forward), Mathf.Infinity ).transform == null); }
void OnPlayerActionSignal(TouchScreenPosition notUsedHere, bool startOrStop) { // if current inventory item is drill then start or stop drilling if (inventoryModel.getCurrentInvItem().id == InvItem.IDType.DrillActive) { view.isDrillingGameInputEventReceived = startOrStop; } // stop drilling if this is false even if not the drill is active if (!startOrStop) { view.isDrillingGameInputEventReceived = false; } }
// checks if the touch is within any GUI item or not public bool isGuiItem(TouchScreenPosition tsp) { // invert y as screen is bottom-up, GUI is top-down tsp.pixel.y = Screen.height - tsp.pixel.y; foreach (Rect guiRect in guiRectList) { // check if the touch is within a GUI item if (guiRect.Contains(tsp.pixel)) { return(true); } } return(false); }
public bool isTouchWithinEllipse(TouchScreenPosition t) { // if the touch is within the smoke bomb ellipse GameObject e = smokeBombCircleGameObject; float rx = e.GetComponent <SpriteRenderer>().sprite.bounds.extents.x; float ry = e.GetComponent <SpriteRenderer>().sprite.bounds.extents.y; float h = e.transform.position.x; float k = e.transform.position.y; float x = t.world.x; float y = t.world.y; // check if the touch is within the ellipse return((x - h) * (x - h) / rx / rx + (y - k) * (y - k) / ry / ry < 1); }
void dispatchFireTouchEventSignal(TouchFSM.Events e, Vector2 firstFingerPixelPosition) { TouchScreenPosition p = new TouchScreenPosition() { pixel = firstFingerPixelPosition, screen = new Vector2( (firstFingerPixelPosition).x / Screen.width, (firstFingerPixelPosition).y / Screen.height), world = (Vector2)cam.ScreenToWorldPoint(new Vector3( (firstFingerPixelPosition).x, (firstFingerPixelPosition).y )) }; _fireTouchEventSignal.Dispatch(e, p); }
void OnPlayerGotoSignal(TouchScreenPosition p) { view.playClickAnimationAt(p.world, gameModel.pauseStatus == TeamBrookvale.Game.PauseStatus.RUN); }
// SHOULD NOT BE CALLED DIRECTLY, only through InventoryEventFireSignal public InvItem.IDType fire(Events e, TouchScreenPosition t) { // InvItem.IDType prevStateId = currentStateId; // any state transitions except in uboat if (currentStateId != InvItem.IDType.UBoat) { switch (e) { case Events.ApproachUBoat: currentStateId = InvItem.IDType.UBoat; break; case Events.ApproachDrillableShip: currentStateId = InvItem.IDType.DrillActive; break; case Events.ApproachSunkShip: currentStateId = InvItem.IDType.DrillInactive; break; case Events.ApproachBridgeOrDamWithoutLocalBomb: currentStateId = InvItem.IDType.TimeBombActive; break; case Events.ApproachBridgeOrDamWithLocalBomb: currentStateId = InvItem.IDType.TimeBombInactive; break; case Events.ApproachBridgeOrDamWithAllBombs: currentStateId = InvItem.IDType.TimeBombInactiveTick; break; case Events.AbandonShipBridgeOrDam: currentStateId = InvItem.IDType.SmokeBombInactive; break; default: break; } } // state dependent transitions switch (currentStateId) { case InvItem.IDType.SmokeBombInactive: if ((e == Events.ButtonPush || e == Events.MoreSmokeBombs) && smokeBombsLeft > 0 && cachedIsSmokeBombEnabledOnThisLevel) { currentStateId = InvItem.IDType.SmokeBombActive; } break; // Smoke bomb explosion is handled by PlayerActionCommand case InvItem.IDType.SmokeBombActive: if (e == Events.ButtonPush || e == Events.TouchOutOfSmokeBombCircle || e == Events.TouchWithinSmokeBombCircle) { currentStateId = InvItem.IDType.SmokeBombInactive; } break; case InvItem.IDType.UBoat: if (e == Events.AbandonUBoat) { currentStateId = InvItem.IDType.SmokeBombInactive; } break; default: break; } // Debug.Log (prevStateId + " ("+e+") -> " + currentStateId); return(currentStateId); }
void OnPlayerGotoSignal(TouchScreenPosition touchScreenPosition) { playerModel.pathGoal = touchScreenPosition.world; }
// Fired by FireTouchEventCommand public States fireTouchEvent(Events e, TouchScreenPosition t) { //States oldState = currentState; switch (currentState) { case States.Idle: switch (e) { case Events.FirstFingerBegan: currentState = States.FirstFingerBegan; break; default: break; } break; case States.FirstFingerBegan: switch (e) { case Events.FirstFingerMoved: currentState = States.Pan; uiFSM.fire(UIFSM.Events.Pan, t); break; case Events.AnyFingersEnded: currentState = States.Idle; uiFSM.fire(UIFSM.Events.Press, t); break; case Events.SecondFingerBegan: currentState = States.SecondFingerBegan; break; case Events.FirstFingerLongTouch: currentState = States.LongPress; uiFSM.fire(UIFSM.Events.LongPress, t); break; default: break; } break; case States.SecondFingerBegan: switch (e) { case Events.AnyFingersEnded: currentState = States.Idle; break; case Events.FirstFingerMoved: currentState = States.Pan; uiFSM.fire(UIFSM.Events.Pan, t); break; case Events.PinchZoom: currentState = States.PinchZoom; break; default: break; } break; case States.Pan: switch (e) { case Events.PinchZoom: currentState = States.PinchZoom; break; case Events.AnyFingersEnded: currentState = States.Idle; break; default: break; } break; case States.PinchZoom: switch (e) { case Events.AnyFingersEnded: currentState = States.Idle; break; default: break; } break; case States.LongPress: switch (e) { case Events.AnyFingersEnded: uiFSM.fire(UIFSM.Events.Release, t); currentState = States.Idle; break; default: break; } break; default: break; } // UnityEngine.Debug.Log ("TouchFSM - " + oldState + " (" + e +") -> " + currentState); return(currentState); }
public void fireTouchEvent(TouchFSM.Events e, TouchScreenPosition t) { currentState = touchFSM.fireTouchEvent(e, t); }
internal void OnSmokeBombExplodedSignal(TouchScreenPosition t) { OnSmokeBombExplodedSignal(t.world, Const.SpotlightReturnToNormalTime); }