private void CheckMenuOpen() { if (LockPauseModule.GetInputLockState() == InputLockType.All) { return; } bool menuToggled = UnityEngine.Input.GetKeyDown(KeyCode.Escape) || MappedInput.GetButtonDown(Input.DefaultControls.OpenMenu); if (menuToggled) { //if we're locked out, let the menu be closed but not opened if (!AllowMenu) { if (IsOpen) { Close(); } } else { //otherwise, flip state Toggle(); } } }
private void Update() { if (!((LockPauseModule.GetPauseLockState() ?? PauseLockType.AllowCutscene) > PauseLockType.AllowMenu)) //handle pauses { return; } if (LockPauseModule.GetInputLockState() == InputLockType.All) { return; } //this probably won't work, but it's supposed to reselect after a return from the menu if (EventSystem.currentSelectedGameObject == null || !EventSystem.currentSelectedGameObject.activeInHierarchy) { SelectButton(SelectedButton); } //update our view of SelectedButton if (EventSystem.currentSelectedGameObject != CurrentButtons[SelectedButton].gameObject) { int newIndex = CurrentButtons.IndexOf(EventSystem.currentSelectedGameObject.GetComponent <Button>()); if (newIndex >= 0) { SelectedButton = newIndex; } //Debug.Log($"selected {SelectedButton}"); } }
private void OnDestroy() { if (CCBase.Terminated) { return; //nop, game is ended anyway and there's nothing we can meaningfully do } ScriptingModule.CallNamedHooked("DialogueOnClose", this); CurrentDialogue = null; LockPauseModule.UnpauseGame(this.gameObject); AudioPlayer.Instance.ClearMusic(MusicSlot.Cinematic); if (CameraController) { Destroy(CameraController.gameObject); } UnhideAllObjects(); CurrentTarget = null; UnsetPlayerFlags(); if (CurrentCallback != null) { try { CurrentCallback(); } catch (Exception e) { Debug.LogException(e); } finally { CurrentCallback = null; } } }
public override void OnDisable() { base.OnDisable(); LockPauseModule.UnlockControls(this); LockPauseModule.UnpauseGame(this); }
private void CloseDialogue() { CurrentDialogue = null; LockPauseModule.UnpauseGame(this.gameObject); AudioPlayer.Instance.ClearMusic(MusicSlot.Cinematic); if (CameraController) { Destroy(CameraController.gameObject); } Destroy(this.gameObject); if (CurrentCallback != null) { try { CurrentCallback(); } catch (Exception e) { Debug.LogException(e); } finally { CurrentCallback = null; } } }
public override void Start() { base.Start(); LockPauseModule.PauseGame(PauseLockType.AllowMenu, this); CalculateValues(); PaintAll(); }
public override void SignalInitialPaint() { base.SignalInitialPaint(); LockPauseModule.LockControls(InputLockType.All, this); LoadControlMap(); SetupControlList(); }
void Update() { if (LockPauseModule.IsPaused()) { return; } UpdateState(); }
private void LateUpdate() { if (LockPauseModule.IsPaused()) { return; } if (FollowPlayer) { //multiple player handling for hmslug Vector2 centroid; if (PlayerTransforms.Count == 1) { centroid = PlayerTransforms[0].position; } else { centroid = Vector2.zero; int validPlayers = 0; foreach (var t in PlayerTransforms) { if (t == null) //skip invalid transforms { continue; } centroid += (Vector2)t.position; validPlayers++; } centroid /= validPlayers; } //max y dist handling float yPos = transform.position.y - YOffset; float yPosToCentroid = centroid.y - yPos; float distYPosToCentroid = Mathf.Abs(yPosToCentroid); if (distYPosToCentroid > MaxYDist) { yPos += Mathf.Sign(yPosToCentroid) * (distYPosToCentroid - MaxYDist); } transform.position = new Vector3(centroid.x, yPos + YOffset, transform.position.z); } else if (MoveTarget.HasValue) { //move to target Vector3 vecToTarget = MoveTarget.Value - transform.position; float distToTarget = vecToTarget.magnitude; if (distToTarget > TargetDistanceThreshold) { //move! float moveDistance = Mathf.Min(distToTarget, MoveSpeed * Time.fixedDeltaTime); transform.Translate(moveDistance * vecToTarget.normalized); } } }
public override void Start() { base.Start(); LockPauseModule.LockControls(InputLockType.GameOnly, this); LockPauseModule.PauseGame(PauseLockType.All, this); ClearState(); PaintAll(); }
private void Update() { if (LockPauseModule.IsPaused()) { return; } HandleCriticalInput(); HandleInvulnerability(); HandleGrenadeThrow(); }
private void Update() { if (LockPauseModule.IsPaused()) { return; } HandleMovement(); HandleAttack(); HandleDeathFall(); }
private void Update() { if (LockPauseModule.IsPaused()) { return; } HandleTargeting(); HandleMovement(); HandleAttack(); HandleDeathGravity(); }
public static void InitiateDialogue(string dialogue, bool pause, DialogueFinishedDelegate callback) { DialogueController.CurrentDialogue = dialogue; DialogueController.CurrentCallback = callback; var prefab = CoreUtils.LoadResource <GameObject>("UI/DialogueSystem"); var go = GameObject.Instantiate <GameObject>(prefab, CoreUtils.GetWorldRoot()); if (pause) { LockPauseModule.PauseGame(PauseLockType.All, go); } }
public override void Update() { base.Update(); if (LockPauseModule.IsPaused()) { return; } TotalTickCount++; TimeInState += Time.deltaTime; UpdateState(); }
public static void TestWeakReferencePauseLock() { AsyncUtils.RunWithExceptionHandling(async() => { object lockObject = new object(); WeakReference untypedWeakReference = new WeakReference(lockObject); LockPauseModule.PauseGame(PauseLockType.AllowMenu, untypedWeakReference); Debug.Log("Untyped lock added!"); await Task.Delay(3000); AsyncUtils.ThrowIfEditorStopped(); lockObject = null; CoreUtils.CollectGarbage(false); Debug.Log("Untyped lock released!"); await Task.Yield(); AsyncUtils.ThrowIfEditorStopped(); LockPauseModule.ForceCleanLocks(); Debug.Log("Locks cleaned!"); await Task.Delay(5000); AsyncUtils.ThrowIfEditorStopped(); IEnumerable typedLockObject = new string[] { "lol", "hi" }; WeakReference <IEnumerable> typedWeakReference = new WeakReference <IEnumerable>(typedLockObject); LockPauseModule.PauseGame(PauseLockType.AllowMenu, typedWeakReference); Debug.Log("Typed lock added!"); await Task.Delay(3000); AsyncUtils.ThrowIfEditorStopped(); typedLockObject = null; CoreUtils.CollectGarbage(false); Debug.Log("Typed lock released!"); await Task.Yield(); AsyncUtils.ThrowIfEditorStopped(); LockPauseModule.ForceCleanLocks(); Debug.Log("Locks cleaned!"); }); }
//TODO STRETCH GOAL: temporary upgrades private void Update() { if (LockPauseModule.IsPaused()) { return; } if (TimeUntilNextShot > 0) { TimeUntilNextShot -= Time.deltaTime; } HandleShooting(); HandlePivot(); }
/// <summary> /// Waits a specified number of seconds in scaled time (respecting pause state), can be skipped with skip button /// </summary> /// <remarks>Can only be used from the main thread</remarks> public static async Task DelayScaled(float time, PauseLockType lowestPauseState, bool useRealtime = false) { for (float elapsed = 0; elapsed < time;) { await Task.Yield(); var pls = LockPauseModule.GetPauseLockState(); if (pls == null || pls >= lowestPauseState) { float timeScale = useRealtime ? 1 : (Mathf.Approximately(Time.timeScale, 0) ? 1 : Time.timeScale); elapsed += Time.unscaledDeltaTime * timeScale; } } await Task.Yield(); }
private void FixedUpdate() { if (LockPauseModule.IsPaused()) { return; } if (TimeUntilNextJump > 0) { TimeUntilNextJump -= Time.fixedDeltaTime; } HandleMovement(); HandleBounds(); HandleDeathGravity(); }
private void LateUpdate() { if (LockPauseModule.IsPaused()) { return; } if (!ConfigState.Instance.GetGameplayConfig().BobEffects) //cancel viewbob if disabled { TargetPosition = Vector3.zero; transform.localPosition = TargetPosition; return; } //set new target if (!(MovementComponent.IsMoving || (MovementComponent.IsOnSlope && MovementComponent.Velocity.sqrMagnitude > 0)) || !MovementComponent.IsGrounded || !PlayerController.PlayerInControl) { TargetPosition = Vector3.zero; } else if ((transform.localPosition - TargetPosition).magnitude < Threshold) { float yDirection = -Mathf.Sign(TargetPosition.y); //bob up and down float extraDisplacement = VelocityDisplacementFactor * MovementComponent.Velocity.GetFlatVector().magnitude; TargetPosition = new Vector3(0, yDirection * (YDisplacement + Random.Range(-YJitter + extraDisplacement, YJitter + extraDisplacement)), 0); } //animate toward target Vector3 vecToTarget = TargetPosition - transform.localPosition; float distToTarget = vecToTarget.magnitude; if (distToTarget > Threshold) { //get extra velocity from movement speed float extraVelocity = VelocityFactor * MovementComponent.Velocity.GetFlatVector().magnitude; Vector3 dirToTarget = vecToTarget.normalized; float moveDist = Mathf.Min(distToTarget, (BaseVelocity + extraVelocity) * Time.deltaTime); transform.Translate(moveDist * dirToTarget, Space.Self); } else if (TargetPosition == Vector3.zero) { transform.localPosition = Vector3.zero; } }
/// <summary> /// Waits a specified number of seconds in real time, can be skipped with skip button /// </summary> /// <remarks>Can only be used from the main thread</remarks> public static async Task DelayRealtime(float time) { for (float elapsed = 0; elapsed < time; elapsed += Time.unscaledDeltaTime) { if (!LockPauseModule.IsInputLocked()) { if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton)) { break; } } await Task.Yield(); } await Task.Yield(); }
/// <summary> /// Waits for specified time (in real time), can be skipped with skip button /// </summary> public static IEnumerator WaitForSecondsRealtime(float time) { for (float elapsed = 0; elapsed < time; elapsed += Time.unscaledDeltaTime) { if (!LockPauseModule.IsInputLocked()) { if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton)) { break; } } yield return(null); } yield return(null); //necessary for debouncing }
private bool GetSkipKeyDown() { if (LockPauseModule.IsInputLocked()) { return(false); } if (UseUnityInput && (UnityEngine.Input.GetButtonDown("Submit") || UnityEngine.Input.GetKeyDown(KeyCode.Space))) { return(true); } if (UseMappedInput && (MappedInput.GetButtonDown(DefaultControls.Confirm) || MappedInput.GetButtonDown(DefaultControls.Fire) || MappedInput.GetButtonDown(DefaultControls.Use))) { return(true); } return(false); }
private void HandleGrenadeThrow() { if (LockPauseModule.IsInputLocked() || !PlayerInControl || PlayerIsDead || !PlayerCanShoot) { return; } if (GetButtonDown("Fire2") && Bombs > 0) { Vector2 fireVector = (Quaternion.AngleAxis(GrenadeAngle, Vector3.forward) * Vector3.right) * new Vector2(Mathf.Sign(transform.localScale.x), 1); Quaternion bulletRotation = Quaternion.FromToRotation(Vector3.right, fireVector); var go = Instantiate(GrenadePrefab, GrenadeThrowPoint.position, bulletRotation, CoreUtils.GetWorldRoot()); var rb = go.GetComponent <Rigidbody2D>(); rb.velocity = (fireVector * GrenadeVelocity);// + Rigidbody.velocity; Bombs--; } }
//should be fixedupdate, probably public override void Update() { HandleMessages(); if (Time.timeScale == 0 || LockPauseModule.IsPaused()) { return; } if (HandleDeath) { HandleDying(); } if (PlayerInControl && !LockPauseModule.IsInputLocked()) { HandleView(); HandleInteraction(); //HandleWeapons(); } }
/// <summary> /// Waits for specified time (respecting pause state), can be skipped with skip button /// </summary> public static IEnumerator WaitForSeconds(float time, PauseLockType lowestPauseState, bool useRealtime = false) { for (float elapsed = 0; elapsed < time;) { if (RequestedSkip) { break; } yield return(null); var pls = LockPauseModule.GetPauseLockState(); if (pls == null || pls >= lowestPauseState) { float timeScale = useRealtime ? 1 : (Mathf.Approximately(Time.timeScale, 0) ? 1 : Time.timeScale); elapsed += Time.unscaledDeltaTime * timeScale; } } yield return(null); //necessary for debouncing }
private void HandleShooting() { DidJustFire = false; if (LockPauseModule.IsInputLocked() || !PlayerController.PlayerInControl || PlayerController.PlayerIsDead || !PlayerController.PlayerCanShoot) { return; } if (PlayerController.GetButtonDown(DefaultControls.Fire) && TimeUntilNextShot <= 0) { var gunPivot = PlayerController.IsCrouched ? GunPivotCrouched : GunPivot; //aiming! Vector2 fireVector = (Vector2)transform.right * Mathf.Sign(PlayerController.transform.localScale.x); float spawnDistance = ((Vector2)transform.position - (Vector2)GunPivot.position).magnitude; float aimY = PlayerController.GetAxis("Vertical"); if (aimY > AimDeadzone || (!PlayerController.IsTouchingGround && aimY < -AimDownDeadzone)) { float aimX = PlayerController.GetAxis("Horizontal"); fireVector = new Vector2(aimX, aimY).normalized; } Vector2 spawnPosition = (Vector2)gunPivot.position + fireVector * spawnDistance; //this technique misaligns the bullet if the muzzle isn't aligned with the pivot. Can you fix it? LastFireVector = fireVector; Quaternion bulletRotation = Quaternion.FromToRotation(Vector3.right, fireVector); var go = Instantiate(BulletPrefab, spawnPosition, bulletRotation, CoreUtils.GetWorldRoot()); var rb = go.GetComponent <Rigidbody2D>(); rb.velocity = (fireVector * BulletVelocity);// + (Vector2.right * PlayerController.Rbody.velocity.x); var bs = go.GetComponent <BulletScript>(); bs.Damage = BulletDamage; TimeUntilNextShot += FireInterval; DidJustFire = true; //play effect, anim AttackSound.Ref()?.Play(); GunAnimator.Play("Fire"); //we rely on the Animator to return to idle state } }
private void LateUpdate() { if (LockPauseModule.IsPaused()) { return; } if (Target != null) { Elapsed += Time.deltaTime; if (Elapsed >= TimeToNext) { //change to next if (transform.localEulerAngles.magnitude < Threshold) //we're at zero, so end { Elapsed = 0; transform.localEulerAngles = Vector3.zero; Original = transform.localRotation; Target = null; } else //we're at target, so try to return to zero { Elapsed = 0; TimeToNext = TimeToZero; Original = transform.localRotation; Target = Quaternion.identity; } } else { //lerp toward target float ratio = Elapsed / TimeToNext; Quaternion rotation = Quaternion.Slerp(Original, Target.Value, ratio); transform.localRotation = rotation; } } }
static void PurgeDialogueSystems() { DialogueController.CurrentDialogue = null; DialogueController.CurrentCallback = null; var ds = GameObject.Find("DialogueSystem"); if (ds != null) { LockPauseModule.UnpauseGame(ds); GameObject.Destroy(ds); } var dc = GameObject.Find("DialogueCamera"); if (dc != null) { GameObject.Destroy(dc); } AudioPlayer.Instance.ClearMusic(MusicSlot.Cinematic); LockPauseModule.ForceCleanLocks(); //useless since objects aren't *yet* destroyed }
//we may rework this to use an explicit update from PlayerController void Update() { if (Time.timeScale == 0 || LockPauseModule.IsPaused()) { return; } //HandleDynamicMovement(); //reset these IsMoving = false; IsRunning = false; DidJump = false; DidChangeCrouch = false; if (PlayerController.PlayerInControl && !LockPauseModule.IsInputLocked()) { HandleLook(); if (Clipping) { HandleMovement(); } } if (Clipping) { HandleDynamicMovement(); HandleOutOfBounds(); } HandleNoclip(); HandleCrouchAnimation(); HandleAnimation(); HandleSounds(); }