// --------------- void Update() { // If the game is paused... if ((this.popupBox != null) && this.popupBox.IsVisible()) { if (Input.GetKeyUp(KeyCode.Escape)) { this.popupBox.End(); } // Unpause... if (this.popupBox.IsComplete()) { this.popupBox.Hide(); // Enable controller... this.ctrl.EnableController(); // Unpause the player... this.player.OnUnpause(); } } // When not paused... else { // Return to Main menu... if (Input.GetKeyUp(KeyCode.Escape)) { DemoSwipeMenuCS.LoadMenuScene(); return; } // Handle input... if (this.ctrl) { // Get stick and zone references by IDs... TouchStick walkStick = this.ctrl.GetStick(STICK_WALK), fireStick = this.ctrl.GetStick(STICK_FIRE); TouchZone //screenZone = this.ctrl.GetZone(ZONE_SCREEN), pauseZone = this.ctrl.GetZone(ZONE_PAUSE); // If the PAUSE zone (or SPACEBAR) is released, show info box... if (pauseZone.JustUniReleased() || Input.GetKeyUp(KeyCode.Space)) { // Show popup box... this.popupBox.Show(INFO_TITLE, INFO_BODY, INFO_BUTTON_TEXT); // Disable controller to stop it from reacting to touch input... this.ctrl.DisableController(); // Pause the game... this.player.OnPause(); } else { // Walk when left stick is pressed... if (walkStick.Pressed()) { // Use stick's normalized XZ vector and tilt to move... this.player.Move(walkStick.GetVec3d(true, 0), walkStick.GetTilt()); } // Stop when stick is released... else { this.player.Move(Vector3.zero, 0); } // Shoot when right stick is pressed... if (fireStick.Pressed()) { this.player.SetTriggerState(true); // Get target angle and stick's tilt to determinate turning speed. this.player.Aim(fireStick.GetAngle(), fireStick.GetTilt()); } // ...or stop shooting and aiming when right stick is released. else { this.player.SetTriggerState(false); this.player.Aim(0, 0); } } } } // Update character... this.player.UpdateChara(); // Update camera... if (this.cam != null) { Transform camTf = this.cam.transform; camTf.position = this.player.transform.position + this.camOfs; } }
// ---------------------- // Update() // ---------------------- void Update() { if (this.ctrl != null) { // ---------------------- // Stick and Zone Variables // ---------------------- TouchStick walkStick = this.ctrl.GetStick(STICK_WALK); TouchZone actionZone = this.ctrl.GetZone(ZONE_ACTION); TouchZone screenZone = this.ctrl.GetZone(ZONE_SCREEN); // ---------------------- // Input Handling Code // ---------------------- // ---------------- // Stick 'Walk'... // ---------------- if (walkStick.Pressed()) { Vector2 walkVec = walkStick.GetVec(); float walkTilt = walkStick.GetTilt(); float walkAngle = walkStick.GetAngle(); TouchStick.StickDir walkDir = walkStick.GetDigitalDir(true); Vector3 walkWorldVec = walkStick.GetVec3d(false, 0); // Your code here. } // ---------------- // Zone 'Action'... // ---------------- if (actionZone.JustUniPressed()) { Vector2 actionPressStartPos = actionZone.GetUniStartPos(TouchCoordSys.SCREEN_PX); } // Uni-touch pressed... if (actionZone.UniPressed()) { float actionUniDur = actionZone.GetMultiTouchDuration(); Vector2 actionUniPos = actionZone.GetMultiPos(); Vector2 actionUniDragDelta = actionZone.GetMultiDragDelta(); Vector2 actionUniRawDrawDelta = actionZone.GetMultiDragDelta(true); } // Uni-Touch Just Released if (actionZone.JustUniReleased()) { Vector2 actionUniRelStartPos = actionZone.GetReleasedUniStartPos(); Vector2 actionUniRelEndPos = actionZone.GetReleasedUniEndPos(); int actionUniRelStartBox = TouchZone.GetBoxPortion(2, 2, actionZone.GetReleasedUniStartPos(TouchCoordSys.SCREEN_NORMALIZED)); int actionUniRelEndBox = TouchZone.GetBoxPortion(2, 2, actionZone.GetReleasedUniEndPos(TouchCoordSys.SCREEN_NORMALIZED)); Vector2 actionUniRelDragVel = actionZone.GetReleasedUniDragVel(); Vector2 actionUniRelDragVec = actionZone.GetReleasedUniDragVec(); } // ---------------- // Zone 'SCREEN'... // ---------------- if (screenZone.JustMultiPressed()) { Vector2 screenMultiPressStartPos = screenZone.GetMultiStartPos(TouchCoordSys.SCREEN_PX); } if (screenZone.JustUniPressed()) { Vector2 screenPressStartPos = screenZone.GetUniStartPos(TouchCoordSys.SCREEN_PX); } // Multi-Pressed... if (screenZone.MultiPressed()) { float screenMultiDur = screenZone.GetMultiTouchDuration(); Vector2 screenMultiPos = screenZone.GetMultiPos(); Vector2 screenMultiDragDelta = screenZone.GetMultiDragDelta(); Vector2 screenMultiRawDrawDelta = screenZone.GetMultiDragDelta(true); // Multi-touch drag... if (screenZone.JustMultiDragged()) { } if (screenZone.MultiDragged()) { } // Just Twisted... if (screenZone.JustTwisted()) { } // Twisted... if (screenZone.Twisted()) { float screenTwistDelta = screenZone.GetTwistDelta(); float screenTwistTotal = screenZone.GetTotalTwist(); } // Just Pinched... if (screenZone.JustPinched()) { } // Pinched... if (screenZone.Pinched()) { float screenPinchRelScale = screenZone.GetPinchRelativeScale(); float screenPinchAbsScale = screenZone.GetPinchScale(); float screenFingerDist = screenZone.GetPinchDist(); } } // Uni-touch pressed... if (screenZone.UniPressed()) { float screenUniDur = screenZone.GetMultiTouchDuration(); Vector2 screenUniPos = screenZone.GetMultiPos(); Vector2 screenUniDragDelta = screenZone.GetMultiDragDelta(); Vector2 screenUniRawDrawDelta = screenZone.GetMultiDragDelta(true); // Just Uni-touch dragged... if (screenZone.JustUniDragged()) { } // Uni-Touch drag... if (screenZone.UniDragged()) { } } // Multi-Touch Just Released if (screenZone.JustMultiReleased()) { Vector2 screenMultiRelStartPos = screenZone.GetReleasedMultiStartPos(); Vector2 screenMultiRelEndPos = screenZone.GetReleasedMultiEndPos(); int screenMultiRelStartBox = TouchZone.GetBoxPortion(2, 2, screenZone.GetReleasedMultiStartPos(TouchCoordSys.SCREEN_NORMALIZED)); int screenMultiRelEndBox = TouchZone.GetBoxPortion(2, 2, screenZone.GetReleasedMultiEndPos(TouchCoordSys.SCREEN_NORMALIZED)); Vector2 screenMultiRelDragVel = screenZone.GetReleasedMultiDragVel(); Vector2 screenMultiRelDragVec = screenZone.GetReleasedMultiDragVec(); // Released multi-touch was dragged... if (screenZone.ReleasedMultiDragged()) { } // Released multi-touch was twisted... if (screenZone.ReleasedTwisted()) { float screenRelTwistAngle = screenZone.GetReleasedTwistAngle(); float screenRelTwistVel = screenZone.GetReleasedTwistVel(); } // Released multi-touch was pinched... if (screenZone.ReleasedPinched()) { float screenRelPinchStartDist = screenZone.GetReleasedPinchStartDist(); float screenRelPinchEndDist = screenZone.GetReleasedPinchEndDist(); float screenRelPinchScale = screenZone.GetReleasedPinchScale(); } } // Uni-Touch Just Released if (screenZone.JustUniReleased()) { Vector2 screenUniRelStartPos = screenZone.GetReleasedUniStartPos(); Vector2 screenUniRelEndPos = screenZone.GetReleasedUniEndPos(); int screenUniRelStartBox = TouchZone.GetBoxPortion(2, 2, screenZone.GetReleasedUniStartPos(TouchCoordSys.SCREEN_NORMALIZED)); int screenUniRelEndBox = TouchZone.GetBoxPortion(2, 2, screenZone.GetReleasedUniEndPos(TouchCoordSys.SCREEN_NORMALIZED)); Vector2 screenUniRelDragVel = screenZone.GetReleasedUniDragVel(); Vector2 screenUniRelDragVec = screenZone.GetReleasedUniDragVec(); // Released uni-touch was dragged... if (screenZone.ReleasedUniDragged()) { } } // Double multi-finger tap... if (screenZone.JustMultiDoubleTapped()) { Vector2 screenMultiDblTapPos = screenZone.GetMultiTapPos(); } else // Simple multi-finger tap... if (screenZone.JustMultiTapped()) { Vector2 screenMultiTapPos = screenZone.GetMultiTapPos(); } else // Double one-finger tap... if (screenZone.JustDoubleTapped()) { Vector2 screenDblTapPos = screenZone.GetTapPos(); } else // Simple one-finger tap... if (screenZone.JustTapped()) { Vector2 screenTapPos = screenZone.GetTapPos(); } } }
// --------------- private void Update() { // If controller's layout changed, reset menu's width... if ((this.ctrl != null) && this.ctrl.LayoutChanged()) { this.menu.SetWindowSize(Screen.width, this.ctrl.GetDPI()); } // Fade-in phase... if (this.fadeInTimer.Enabled) { this.fadeInTimer.Update(Time.deltaTime); if (this.fadeInTimer.Completed) { this.fadeInTimer.Disable(); } } // Control... else { if (Input.GetKeyUp(KeyCode.Escape)) { Application.LoadLevel(EXIT_SCREEN_SCENE_NAME); return; //Application.Quit(); } // Get first and the only one touch zone (no need for IDs)... TouchZone zone = this.ctrl.GetZone(0); // Handle tap... if (zone.JustTapped()) { this.menu.OnTap(); } // Handle unified-touch press... if (zone.JustUniPressed()) { this.menu.OnPress(); } // If unified-touch moved, use it's drag delta... if (zone.UniDragged()) { this.menu.Move(-zone.GetUniDragDelta(TouchCoordSys.SCREEN_PX).x); } // On unfied-touch release, get released drag velocity to detect those quick swipes... else if (zone.JustUniReleased()) { this.menu.OnRelease(-zone.GetReleasedUniDragVel().x); } } // If swipe-menu completed - go to selected mode... this.menu.UpdateMenu(); if (this.menu.JustCompleted()) { switch (this.menu.GetCurItem()) { case ITEM_FPP: this.StartDemo(FPP_DEMO_SCENE_NAME); return; case ITEM_RPG: this.StartDemo(RPG_DEMO_SCENE_NAME); return; case ITEM_MAP: this.StartDemo(MAP_DEMO_SCENE_NAME); return; case ITEM_DSS: this.StartDemo(DUAL_STICK_DEMO_SCENE_NAME); return; } } }