// --------------- 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(); } } }
// -------------------- public void ControlByTouch(TouchController ctrl, DemoRpgGameCS game) { TouchStick stickWalk = ctrl.GetStick(DemoRpgGameCS.STICK_WALK); TouchZone zoneScreen = ctrl.GetZone(DemoRpgGameCS.ZONE_SCREEN), zoneAction = ctrl.GetZone(DemoRpgGameCS.ZONE_ACTION), zoneFire = ctrl.GetZone(DemoRpgGameCS.ZONE_FIRE); // Get stick's normalized direction in world space relative to camera's angle... Vector3 moveWorldDir = stickWalk.GetVec3d(TouchStick.Vec3DMode.XZ, true, game.camOrbitalAngle); // Get stick's angle in world space by adding it to camera's angle.. float stickWorldAngle = stickWalk.GetAngle() + game.camOrbitalAngle; // Get walking speed from stick's current tilt... float speed = stickWalk.GetTilt(); // Get gun's trigger state by checking Fire zone's state (including mid-frame press) bool gunTriggerState = zoneFire.UniPressed(true, false); // Check if Action should be performed - either by pressing the Action button or // by tapping on the right side of the screen... bool performAction = zoneAction.JustUniPressed(true, true) || zoneScreen.JustTapped(); if ((this.charaState == CharaState.IDLE) || (this.charaState == CharaState.WALK) || (this.charaState == CharaState.RUN)) { if (speed > this.walkStickThreshold) { float moveSpeed = 0; // Walk... if (speed < this.runStickThreshold) { moveSpeed = this.walkSpeed; if (this.charaState != CharaState.WALK) { this.StartWalking(); } // Set animation speed... this.charaAnim[this.ANIM_WALK_F].speed = this.walkAnimSpeed; } // Run! else { moveSpeed = this.runSpeed; if (this.charaState != CharaState.RUN) { this.StartRunning(); } // Set animation speed... this.charaAnim[this.ANIM_RUN_F].speed = this.runAnimSpeed; } // Update player's angle... this.angle = DampAngle(this.angle, stickWorldAngle, this.angleSmoothingTime, this.turnMaxSpeed, Time.deltaTime); // Move player's collider... this.charaCtrl.Move(moveWorldDir * moveSpeed * Time.deltaTime); } else if ((this.charaState == CharaState.WALK) || (this.charaState == CharaState.RUN)) { // Stop... this.StartIdle(); } // Perform Action... if (performAction) { this.PerformUseAction(); } } // Every other state than USE... if (this.charaState != CharaState.USE) { if (this.gun != null) { this.gun.SetTriggerState(gunTriggerState); } if (performAction) { this.PerformUseAction(); } } // USE state updates... else { if (this.gun != null) { this.gun.SetTriggerState(false); } this.useElapsed += Time.deltaTime; if (this.useElapsed > this.useAnimDuration) { this.StartIdle(); } } }