/////////////////////////////////////////////////////////// // reloads the current shooter with 'amount' ammo and deals // with states and timers concerning reloading /////////////////////////////////////////////////////////// public void Reload(int amount) { if (CurrentShooter == null) { return; } if (Time.time < CurrentShooter.NextAllowedReloadTime) { return; } if (m_ReenableWeaponStatesTimer != null) { m_ReenableWeaponStatesTimer.Cancel(); } SetState("Reload", true); CurrentShooter.Reload(amount); if (m_DoneReloadingTimer != null) { m_DoneReloadingTimer.Cancel(); } m_DoneReloadingTimer = vp_Timer.In(CurrentShooter.AmmoReloadTime, delegate() { SetState("Reload", false); }); }
/////////////////////////////////////////////////////////// // static version of the Cancel method. NOTE: calling // 'CancelInvoke' on a vp_Timer is the same as calling // 'Cancel'. /////////////////////////////////////////////////////////// public static void Cancel(vp_Timer timer) { if (timer == null) { return; } timer.Cancel(); }
/////////////////////////////////////////////////////////// // cancels any already ongoing weapon switching activity /////////////////////////////////////////////////////////// public void CancelWeaponSwitch() { if (m_SwitchWeaponTimer != null) { m_SwitchWeaponTimer.Cancel(); } if (m_ShowWeaponTimer != null) { m_ShowWeaponTimer.Cancel(); } }
/////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////// void Update() { Demo.Update(); // special case to make sure the weapon doesn't flicker into // view briefly in the first frame if (Demo.CurrentScreen == 1 && m_Player.Camera.CurrentWeaponID != 0) { m_Player.Camera.SetWeapon(0); } // input special cases for the 'EXAMPLES' screen if (Demo.CurrentScreen == 2) { if ((Input.mousePosition.x < 150) || ((Input.mousePosition.y > (Screen.height - 130))) && (Input.mousePosition.x < ((Screen.width * 0.5f) - 290) || Input.mousePosition.x > ((Screen.width * 0.5f) + 290) )) { m_Player.LockCursor = false; } else { if (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2)) { m_Player.LockCursor = true; } } // switch weapon examples using the 1-0 number keys if (Input.GetKeyDown(KeyCode.Backspace)) { Demo.ButtonSelection = 0; } if (Input.GetKeyDown(KeyCode.Alpha1)) { Demo.ButtonSelection = 1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { Demo.ButtonSelection = 2; } if (Input.GetKeyDown(KeyCode.Alpha3)) { Demo.ButtonSelection = 3; } if (Input.GetKeyDown(KeyCode.Alpha4)) { Demo.ButtonSelection = 4; } if (Input.GetKeyDown(KeyCode.Alpha5)) { Demo.ButtonSelection = 5; } if (Input.GetKeyDown(KeyCode.Alpha6)) { Demo.ButtonSelection = 6; } if (Input.GetKeyDown(KeyCode.Alpha7)) { Demo.ButtonSelection = 7; } if (Input.GetKeyDown(KeyCode.Alpha8)) { Demo.ButtonSelection = 8; } if (Input.GetKeyDown(KeyCode.Alpha9)) { Demo.ButtonSelection = 9; } if (Input.GetKeyDown(KeyCode.Alpha0)) { Demo.ButtonSelection = 10; } // cycle to previous example if (Input.GetKeyDown(KeyCode.Q)) { Demo.ButtonSelection--; if (Demo.ButtonSelection < 1) { Demo.ButtonSelection = 10; } } // cycle to next example if (Input.GetKeyDown(KeyCode.E)) { Demo.ButtonSelection++; if (Demo.ButtonSelection > 10) { Demo.ButtonSelection = 1; } } // if user presses 'ENTER' toggle the mouse pointer if (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.KeypadEnter)) { m_Player.LockCursor = !m_Player.LockCursor; } } // special case to cancel the crashing airplane example zoom reset // if user navigates away from the 'EXTERNAL FORCES' screen if (Demo.CurrentScreen != 3 && m_ChrashingAirplaneRestoreTimer != null) { m_ChrashingAirplaneRestoreTimer.Cancel(); } }
/////////////////////////////////////////////////////////// // static version of the Cancel method. NOTE: calling // 'CancelInvoke' on a vp_Timer is the same as calling // 'Cancel'. /////////////////////////////////////////////////////////// public static void Cancel(vp_Timer timer) { if (timer == null) return; timer.Cancel(); }
private void DoExamplePistolReloadSequence() { // NOTE: (the 'Reload' state is activated in the 'Reload' // method of vp_FPSPlayer so the pistol is already tilted // to the side) // always disable the timer if it's running, to avoid hickups // caused by button spamming if (m_PistolReloadTimer != null) { m_PistolReloadTimer.Cancel(); } // after 0.4 seconds, simulate replacing the clip m_PistolReloadTimer = vp_Timer.In(0.4f, delegate() { // but first make sure we're still reloading since the player // may have switched weapons if (!m_Player.Camera.CurrentWeapon.StateEnabled("Reload")) { return; } // apply a force as if hitting the gun from below m_Player.Camera.CurrentWeapon.AddForce2(new Vector3(0, 0.05f, 0), new Vector3(0, 0, 0)); // 0.15 seconds later, twist the gun backwards if (m_PistolReloadTimer != null) { m_PistolReloadTimer.Cancel(); } m_PistolReloadTimer = vp_Timer.In(0.15f, delegate() { if (!m_Player.Camera.CurrentWeapon.StateEnabled("Reload")) { return; } // to do this, switch from the pistol 'Reload' state to // its 'Reload2' state m_Player.Camera.SetState("Reload", false); m_Player.Camera.CurrentWeapon.SetState("Reload", false); m_Player.Camera.CurrentWeapon.SetState("Reload2", true); m_Player.Camera.CurrentWeapon.RotationOffset.z = 0; m_Player.Camera.CurrentWeapon.Refresh(); // after 0.35 seconds, pull the slide if (m_PistolReloadTimer != null) { m_PistolReloadTimer.Cancel(); } m_PistolReloadTimer = vp_Timer.In(0.35f, delegate() { if (!m_Player.Camera.CurrentWeapon.StateEnabled("Reload2")) { return; } // apply a force pulling the whole gun backwards briefly m_Player.Camera.CurrentWeapon.AddForce2(new Vector3(0, 0, -0.05f), new Vector3(5, 0, 0)); // 0.1 seconds later, disable the reload state to point // the gun forward again if (m_PistolReloadTimer != null) { m_PistolReloadTimer.Cancel(); } m_PistolReloadTimer = vp_Timer.In(0.1f, delegate() { m_Player.SetState("Reload2", false); // if the player is crouching, restore the zoom state on the pistol if (m_Player.Controller.StateEnabled("Zoom")) { m_Player.Camera.CurrentWeapon.SetState("Zoom", true); } m_Player.CurrentShooter.NextAllowedFireTime = Time.time + 0.5f; m_Player.CurrentShooter.NextAllowedReloadTime = Time.time + 0.5f; }); }); }); }); }