public static bool CanPlaySound(SoundManager.Sound sound) { switch (sound) { default: return(true); case SoundManager.Sound.PlayerMove: if (soundTimerDictionary.ContainsKey(sound)) { float lastTimePlayed = soundTimerDictionary[sound]; float playerMoveTimerMax = 0.05f; if (lastTimePlayed + playerMoveTimerMax < Time.time) { soundTimerDictionary[sound] = Time.time; return(true); } else { return(false); } } else { return(true); } } }
public void PlaySound(SoundManager.Sound sound) { var soundGameObject = ObjectPooler.Instance.SpawnFromPool("Sound", Vector3.zero, Quaternion.identity); var audioSource = soundGameObject.GetComponent <AudioSource>(); audioSource.PlayOneShot(GetAudioClip(sound)); }
public static void PlaySound(SoundManager.Sound sound) { if (CanPlaySound(sound)) { GameObject soundGameObject = new GameObject("Sound"); AudioSource audioSource = soundGameObject.AddComponent <AudioSource>(); audioSource.PlayOneShot(GetAudioClip(sound)); } }
//TODO fix this public bool CanPlaySound(SoundManager.Sound sound) { if (soundAudioClip.soundDelay < Time.time) { return(true); } return(false); }
private static AudioClip GetAudioClip(SoundManager.Sound sound) { foreach (SoundManager.SoundAudioClip soundAudioClip in SoundManager.soundAudioClips) { if (soundAudioClip.sound == sound) { return(soundAudioClip.audioClip); } } Debug.LogError("Sound " + sound + " not found"); return(null); }
public void TakeDmg(SoundManager.Sound sound, GameObject particle, float amount = 1) { if (canTakeDmg) { animator.SetTrigger("TakeDmg"); GameObject particleClone = Instantiate(particle, transform.position, particle.transform.rotation); canTakeDmg = false; currentHeatlh -= amount; healthBar.UpdateFillAmount(currentHeatlh / startHealth); SoundManager.PlaySound(sound, Random.Range(0.8f, 1.2f)); if (currentHeatlh <= 0) { Death(); } else { StartCoroutine(FadeSprite(0.3f, 5)); } } }
private bool ExecuteActions() { turn = 0; foreach (Action action in GetSortedActionArray()) { // Update and display turn number turn++; turnTotal++; TextManager.SetTurnText(turn); // If an actor was killed before its turn, ignore the turn if (action.Actor == null || action.Actor.IsDead()) { continue; } // Apply the action to each target foreach (MonoMonster target in action.Targets) { // Ignore invalid target and spells against the dead if (target == null || (action.Spell != null && target.IsDead())) { continue; } TextManager.SetActorText(action.Actor.Name); Thread.Sleep(gameTick); // If the action is nothing, display and bail out if (action.Nothing) { TextManager.SetResultsText("Nothing"); continue; } TextManager.SetTargetText(target.Name); Thread.Sleep(gameTick); if (action.Physical) { // Physical attacks can target the dead, but are ineffective if (target.IsDead()) { TextManager.SetResultsText("Ineffective"); continue; } // Apply the attack and display the results AttackResult atkRes = AttackManager.AttackMonster(action.Actor, target); // On a miss, display and bail out if (string.Equals(atkRes.DamageMessage, "Miss")) { TextManager.SetDamageText("Miss"); continue; } // Flicker sprite // TODO: Different sounds and animations need to play based on the attack type if (gameTick > 30) { SoundManager.PlaySound(SoundManager.Sound.Physical); target.Flicker(16); } TextManager.SetHitsText(atkRes.HitsMessage); Thread.Sleep(gameTick); TextManager.SetDamageText(atkRes.DamageMessage); Thread.Sleep(gameTick); // Fade the monster if dead // TODO: This is awkward here if (target.IsDead()) { target.StartDeath(); Thread.Sleep(30); // 300 } // Display each result, tearing down existing results as needed for (int i = 0; i < atkRes.Results.Count; i++) { string res = atkRes.Results[i]; TextManager.SetResultsText(res); if (i < atkRes.Results.Count - 1) { Thread.Sleep(gameTick * 2); TextManager.TearDownResults(); Thread.Sleep(teardownTick); } } break; } else { // Casting a spell TextManager.SetHitsText(action.Spell.Name + " " + action.SpellLevel); Thread.Sleep(gameTick); // Cast the spell and display the results SpellResult spellRes = SpellManager.CastSpell(action.Actor, target, action.Spell, action.SpellLevel, action.Targets.Count > 1); // Set the spell animation and sound based on the spell's effect (kinda). This is awkward but fine for now. MagicSprite.MagicAnimation magicAnim = MagicSprite.MagicAnimation.Attack; SoundManager.Sound magicSnd = SoundManager.Sound.AttackSpell; if (action.Spell.Effect == "Buff") { magicAnim = MagicSprite.MagicAnimation.Buff; magicSnd = SoundManager.Sound.Buff; } if (action.Spell.Effect == "Debuff" || action.Spell.Effect == "TempStatus" || action.Spell.Effect == "PermStatus") { magicAnim = MagicSprite.MagicAnimation.Debuff; magicSnd = SoundManager.Sound.Debuff; } if (action.Spell.Effect == "Heal" || action.Spell.Effect == "Revive" || action.Spell.Effect == "ItemFullRestore") { magicAnim = MagicSprite.MagicAnimation.Heal; magicSnd = SoundManager.Sound.Heal; } MagicSpriteManager.GenerateSpellBurst((int)target.Position.X, (int)target.Position.Y, target.Width, target.Height, magicAnim); SoundManager.PlaySound(magicSnd); Thread.Sleep(SPELL_ANIMATION_DELAY); if (spellRes.Damage >= 0) { TextManager.SetDamageText(spellRes.Damage.ToString()); Thread.Sleep(gameTick); } // Kill the target if it's dead. // TODO: This is weird here, should be handled by the monster itself? if (target.IsDead()) { target.StartDeath(); Thread.Sleep(300); } // Display each result, tearing down existing results as needed for (int i = 0; i < spellRes.Results.Count; i++) { string res = spellRes.Results[i]; TextManager.SetResultsText(res); if (i < spellRes.Results.Count - 1) { Thread.Sleep(gameTick * 2); TextManager.TearDownResults(); Thread.Sleep(teardownTick); } } // Tear down between each target Thread.Sleep(gameTick * 5); while (TextManager.TearDownText()) { Thread.Sleep(teardownTick); } } // TODO: If both scenes only contain "Soul" enemies, they cannot kill eachother if (!sceneOne.HasLivingMonsters() || !sceneTwo.HasLivingMonsters() || round >= ROUND_LIMIT) { break; } } // Turn end, clean up text display Thread.Sleep(gameTick * 5); while (TextManager.TearDownText()) { Thread.Sleep(teardownTick); } if (!sceneOne.HasLivingMonsters() || !sceneTwo.HasLivingMonsters() || round >= ROUND_LIMIT) { break; } } return(false); }
private void PlayDamageSound(SoundManager.Sound soundToPlay) { SoundManager.Instance.PlaySound(soundToPlay); }
/// <summary> /// Removes a sound from the list of sounds the AttackFXManager may pick to play. /// </summary> /// <param name="sound">The sound.</param> public void RemoveSound(SoundManager.Sound sound) { PotentialSounds.Remove(sound); }
/// <summary> /// Adds a sound to the list of sounds the AttackFXManager may pick to play. /// </summary> /// <param name="sound">The sound.</param> public void AddSound(SoundManager.Sound sound) { PotentialSounds.Add(sound); }
private void UpdateDataRPC(int id, bool isMoving, float rotX, float h, float s, float b, bool headIsInWater, bool isDead, bool isBurning, bool isOiled, bool isQuiet, bool isDamageBoosted, bool isFallen, bool isTrap, bool isSlow, bool isInWater, bool feetIsInWater, Vector3 pos, Vector3 rot) { if (id != Array.IndexOf(gc.AvatarToUserId, PhotonNetwork.AuthValues.UserId)) { Vector3 vec = new Vector3(rotX, 0, 0); gc.players[id].PlayerModel.transform.localEulerAngles = rot; gc.players[id].SpotLight.transform.localEulerAngles = vec; vec.y = rot.y; gc.players[id].PlayerCamera.transform.localEulerAngles = vec; } SoundManager.Sound soundNeeded = SoundManager.Sound.Walk; if (gc.playersActions[id].headIsInWater) { soundNeeded = SoundManager.Sound.Swim; } else if (gc.playersActions[id].feetIsInWater) { soundNeeded = SoundManager.Sound.FeetOnWater; } else if (gc.playersActions[id].isOnMetalSheet) { soundNeeded = SoundManager.Sound.MetalSheet; } gc.soundManager.playWalkSound(id, isMoving, soundNeeded, isQuiet); if (isMoving) { gc.players[id].PlayerAnimator.Play("Movement"); } PlayerStats ps = gc.players[id].PlayerStats; ps.currentHp = h; ps.currentStamina = s; ps.currentBreath = b; ps.isDead = isDead; gc.playersActions[id].headIsInWater = headIsInWater; gc.playersActions[id].isBurning = isBurning; gc.playersActions[id].isOiled = isOiled; gc.playersActions[id].isDamageBoosted = isDamageBoosted; gc.playersActions[id].isFallen = isFallen; gc.playersActions[id].isSlow = isSlow; gc.playersActions[id].isTrap = isTrap; gc.playersActions[id].isInWater = isInWater; gc.playersActions[id].feetIsInWater = feetIsInWater; if (isFallen) { gc.players[id].PlayerModel.transform.localEulerAngles = new Vector3(90.0f, gc.players[id].PlayerModel.transform.localEulerAngles.y, gc.players[id].PlayerModel.transform.localEulerAngles.z); gc.players[id].PlayerCamera.transform.localEulerAngles = new Vector3(90.0f, gc.players[id].PlayerCamera.transform.localEulerAngles.y, gc.players[id].PlayerCamera.transform.localEulerAngles.z); } else { gc.players[id].PlayerModel.transform.localEulerAngles = new Vector3(0.0f, gc.players[id].PlayerModel.transform.localEulerAngles.y, gc.players[id].PlayerModel.transform.localEulerAngles.z); } int playerIndex = System.Array.IndexOf(gc.AvatarToUserId, PhotonNetwork.AuthValues.UserId); if (gc.AvatarToUserId[id] == PhotonNetwork.AuthValues.UserId) { gc.inventoryGui.updateBar(ps.currentHp, ps.currentStamina, ps.currentBreath); } if (isDead) { gc.players[id].PlayerGameObject.SetActive(false); } if (isDead && (id == se.sm.idCamSpectate || id == playerIndex)) { se.sm.WantToSwitchCam(); } }