private void PlaySomewhereAround(SoundClips clip, float volumeScale, float spatialBlend = 1f)
        {
            //Debug.LogFormat("Playing clip {0}", clip.ToString());
            Vector3 randomPos = playerBehaviour.transform.position +
                                Random.onUnitSphere * 5.2f;

            SpatializedPlayOneShot(clip, randomPos, volumeScale, spatialBlend);
        }
        private void PlaySomewhereOnHorizon(SoundClips clip, float volumeScale)
        {
            // Somewhere around, 20° above horizon
            Vector3 randomPos = playerBehaviour.transform.position +
                                Quaternion.AngleAxis(Mathf.Sqrt(Random.Range(0f, sqr(10000f))), Vector3.up) * new Vector3(0.94f, 0.34f, 0f);

            SpatializedPlayOneShot(clip, randomPos, volumeScale, 3000f);
        }
        private void SpatializedPlayOneShot(SoundClips clip, Vector3 position, float volumeScale, float spatialBlend = 1f)
        {
            AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);

            ambientAudioSource.transform.position = position;
            ambientAudioSource.spatialBlend       = spatialBlend;
            ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
        }
Example #4
0
        protected virtual void RaiseOnPlayEffectEvent(SoundClips clip)
        {
            AmbientEffectsEventArgs args = new AmbientEffectsEventArgs(clip);

            if (OnPlayEffect != null)
            {
                OnPlayEffect(args);
            }
        }
Example #5
0
        private AudioClip PlayLoop(SoundClips clip, float volumeScale)
        {
            AudioClip loopClip = dfAudioSource.GetAudioClip((int)clip);

            loopAudioSource.loop         = true;
            loopAudioSource.spatialBlend = 0;
            loopAudioSource.PlayWhenReady(loopClip, volumeScale);
            return(loopClip);
        }
        /// <summary>
        /// Gets AudioClip based on Daggerfall SoundClip enum.
        /// </summary>
        /// <param name="soundClip">SoundClip enum.</param>
        /// <returns>AudioClip or null.</returns>
        public AudioClip GetAudioClip(SoundClips soundClip)
        {
            if (!ReadyCheck())
            {
                return(null);
            }

            return(GetAudioClip((int)soundClip));
        }
Example #7
0
 private void AmbientPlayOneShot(SoundClips clip, float volumeScale)
 {
     if (!ambientAudioSource.isPlaying)
     {
         AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
         ambientAudioSource.spatialBlend = 0;
         ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
     }
 }
Example #8
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Example #9
0
    public void StopSound(string name)                                          // for stooping looping sounds
    {
        SoundClips s = Array.Find(soundClips, sound => sound.clipName == name); // Lambada expression

        if (s == null)
        {
            Debug.Log("Sound " + name + " not Found");
            return;
        }
        s.audioSource.Stop();
    }
Example #10
0
    public void Play(string name)
    {
        SoundClips s = Array.Find(soundClips, sound => sound.clipName == name); // Lambada expression

        if (s == null)
        {
            Debug.Log("Sound " + name + " not Found");
            return;
        }
        s.audioSource.Play();
    }
Example #11
0
	public AudioSource playSound(SoundClips clip, AudioSource source) {

		if (source == null) {
			source = gameObject.AddComponent<AudioSource>();
			source.PlayOneShot(mAudioClips [(int)clip]);
			Destroy(source,mAudioClips [(int)clip].length + 1);
		} else {
			source.PlayOneShot (mAudioClips [(int)clip]);
		}

		return source;
	}
        private void RelativePlayOneShot(SoundClips clip, Vector3 relativePosition, float volumeScale)
        {
            AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);

            ambientAudioSource.spatialBlend = 1f;
            ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
            if (relativePositionCoroutine != null)
            {
                StopCoroutine(relativePositionCoroutine);
            }
            relativePositionCoroutine = StartCoroutine(UpdateAmbientSoundRelativePosition(relativePosition));
        }
Example #13
0
 // Use this for initialization
 void Start()
 {
     _audio = GetComponent <AudioSource>();
     if (instance != null)
     {
         Destroy(this);
     }
     else
     {
         instance = this;
     }
 }
Example #14
0
 private void SpatializedPlayOneShot(SoundClips clip, Vector3 position, float volumeScale, float minDistance = 8f)
 {
     if (!ambientAudioSource.isPlaying)
     {
         AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
         ambientAudioSource.transform.position = position;
         ambientAudioSource.spatialBlend       = 1f;
         ambientAudioSource.minDistance        = minDistance;
         ambientAudioSource.maxDistance        = minDistance * 8;
         ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
     }
 }
Example #15
0
 public void PlayAttackVoice()
 {
     if (dfAudioSource)
     {
         PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
         SoundClips   sound        = DaggerfallEntity.GetRaceGenderAttackSound(playerEntity.Race, playerEntity.Gender, true);
         float        pitch        = dfAudioSource.AudioSource.pitch;
         dfAudioSource.AudioSource.pitch = pitch + UnityEngine.Random.Range(0, 0.3f);
         dfAudioSource.PlayOneShot(sound, 0, 1f);
         dfAudioSource.AudioSource.pitch = pitch;
     }
 }
Example #16
0
	public AudioSource playSound(SoundClips clip, bool isLoop = false, bool autoDestroy = true) {
		AudioSource source = gameObject.AddComponent<AudioSource>();
		//source.PlayOneShot(mAudioClips [(int)clip]);
		source.clip = mAudioClips [(int)clip];
		if (isLoop) {
			source.loop = true;
		} else {
			if(autoDestroy)
				Destroy (source, mAudioClips [(int)clip].length + 1);
		}
		source.Play();
		return source;
	}
 // Capture this message so we can play pain voice
 public void RemoveHealth(int amount)
 {
     if (dfAudioSource && DaggerfallUnity.Settings.CombatVoices && Random.Range(1, 101) <= 40)
     {
         Entity.PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
         bool       heavyDamage           = amount >= playerEntity.MaxHealth / 4;
         SoundClips sound = Entity.DaggerfallEntity.GetRaceGenderPainSound(playerEntity.Race, playerEntity.Gender, heavyDamage);
         float      pitch = dfAudioSource.AudioSource.pitch;
         dfAudioSource.AudioSource.pitch = pitch + Random.Range(0, 0.3f);
         dfAudioSource.PlayOneShot((int)sound, 0, 1f);
         dfAudioSource.AudioSource.pitch = pitch;
     }
 }
        public override void OnWeaponHitEntity(PlayerEntity playerEntity, DaggerfallEntity targetEntity = null)
        {
            const int chanceOfAttackSound = 10;
            const int chanceOfBarkSound   = 20;

            // Check if we killed an innocent and update satiation - do not need to be transformed
            if (KilledInnocent(targetEntity))
            {
                UpdateSatiation();
            }

            // Do nothing further if not transformed
            if (!isTransformed)
            {
                return;
            }

            // Lycanthrope characters emit both attack and bark sounds while attacking
            SoundClips customSound = SoundClips.None;

            if (infectionType == LycanthropyTypes.Werewolf)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWerewolfAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWerewolfBark;
                }
            }
            else if (infectionType == LycanthropyTypes.Wereboar)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWereboarAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWereboarBark;
                }
            }

            // Play sound through weapon
            FPSWeapon screenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

            if (screenWeapon && customSound != SoundClips.None)
            {
                screenWeapon.PlayAttackVoice(customSound);
            }
        }
Example #19
0
        private void PlayEffects()
        {
            // Do nothing if audio not setup
            if (ambientAudioSource == null || ambientSounds == null)
            {
                return;
            }

            // Get next sound index
            int index = random.Next(0, ambientSounds.Length);

            // Play effect
            if (Presets == AmbientSoundPresets.Storm)
            {
                if (PlayLightningEffect)
                {
                    // Play lightning effects together with appropriate sounds
                    StartCoroutine(PlayLightningEffects(index));
                }
                else
                {
                    // Play ambient sound as a one-shot 3D sound
                    SoundClips clip = ambientSounds[index];
                    PlaySomewhereOnHorizon(clip, 1f);

                    // AmbientPlayOneShot(clip, 5f);
                    RaiseOnPlayEffectEvent(clip);
                }
            }
            else
            {
                // Do not play ambient effect in castle blocks
                if (doNotPlayInCastle)
                {
                    if (playerEnterExit == null)
                    {
                        playerEnterExit = GameManager.Instance.PlayerEnterExit;
                    }
                    if (playerEnterExit && playerEnterExit.IsPlayerInsideDungeonCastle)
                    {
                        return;
                    }
                }

                // Play ambient sound as a one-shot 3D sound
                SoundClips clip = ambientSounds[index];
                PlaySomewhereAround(clip, 1f);
                RaiseOnPlayEffectEvent(clip);
            }
        }
Example #20
0
    /***
     * Sets up and plays an audio clip.
     *
     * @param sound The sound to play.
     */
    public void PlaySound(SoundClips sound)
    {
        GetComponent <AudioSource>().volume = 1.0f;
        GetComponent <AudioSource>().pitch  = 1.0f;
        if (sound == SoundClips.Smash_Common || sound == SoundClips.Smash_Rare || sound == SoundClips.Smash_UltraRare)
        {
            GetComponent <AudioSource>().volume = 0.7f;
            if (sound == SoundClips.Smash_Common)
            {
                GetComponent <AudioSource>().pitch += 0.25f * multiplier;
            }
        }

        GetComponent <AudioSource>().clip = audioClips[(int)sound];
        GetComponent <AudioSource>().Play();
    }
        public override bool GetCustomRaceGenderAttackSoundData(PlayerEntity entity, out SoundClips soundClipOut)
        {
            switch (entity.Gender)
            {
            default:
            case Genders.Male:
                soundClipOut = SoundClips.EnemyVampireAttack;
                break;

            case Genders.Female:
                soundClipOut = SoundClips.EnemyFemaleVampireAttack;
                break;
            }

            return(true);
        }
Example #22
0
        private void PlayCemeteryEffects()
        {
            // Do nothing if audio not setup
            if (ambientAudioSource == null)
            {
                return;
            }

            // Get next sound index
            int index = random.Next(0, cemeteryAmbientSounds.Length);

            // Play ambient sound as a one-shot 3D sound
            SoundClips clip = cemeteryAmbientSounds[index];

            PlaySomewhereAround(clip, 1f);
        }
        // Capture this message so we can play pain voice
        public void RemoveHealth(int amount)
        {
            // Racial override can suppress optional attack voice
            RacialOverrideEffect racialOverride = GameManager.Instance.PlayerEffectManager.GetRacialOverrideEffect();
            bool suppressCombatVoices           = racialOverride != null && racialOverride.SuppressOptionalCombatVoices;

            if (dfAudioSource && DaggerfallUnity.Settings.CombatVoices && !suppressCombatVoices && Dice100.SuccessRoll(40))
            {
                Entity.PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
                bool       heavyDamage           = amount >= playerEntity.MaxHealth / 4;
                SoundClips sound = Entity.DaggerfallEntity.GetRaceGenderPainSound(playerEntity.Race, playerEntity.Gender, heavyDamage);
                float      pitch = dfAudioSource.AudioSource.pitch;
                dfAudioSource.AudioSource.pitch = pitch + Random.Range(0, 0.3f);
                dfAudioSource.PlayOneShot((int)sound, 0, 1f);
                dfAudioSource.AudioSource.pitch = pitch;
            }
        }
        public override void OnWeaponHitEnemy(PlayerEntity playerEntity, EnemyEntity enemyEntity)
        {
            const int chanceOfAttackSound = 10;
            const int chanceOfBarkSound   = 20;

            // Do nothing if not transformed
            if (!isTransformed)
            {
                return;
            }

            // Lycanthrope characters emit both attack and bark sounds while attacking
            SoundClips customSound = SoundClips.None;

            if (infectionType == LycanthropyTypes.Werewolf)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWerewolfAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWerewolfBark;
                }
            }
            else if (infectionType == LycanthropyTypes.Wereboar)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWereboarAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWereboarBark;
                }
            }

            // Play sound through weapon
            FPSWeapon screenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

            if (screenWeapon && customSound != SoundClips.None)
            {
                screenWeapon.PlayAttackVoice(customSound);
            }
        }
        public void EditorPreviewByID()
        {
            if (!ReadyCheck())
            {
                return;
            }

            PreviewIndex = dfUnity.SoundReader.GetSoundIndex((uint)PreviewID);
            if (PreviewIndex >= 0)
            {
                PreviewClip = (SoundClips)PreviewIndex;
                EditorPreviewByIndex();
            }
            else
            {
                PreviewClip = SoundClips.None;
            }
        }
Example #26
0
        public void EditorPreviewByIndex()
        {
            if (!ReadyCheck())
            {
                return;
            }

            if (PreviewIndex < minIndex || PreviewIndex >= maxIndex)
            {
                return;
            }

            if (ReadyCheck())
            {
                PreviewID   = (int)dfUnity.SoundReader.GetSoundID(PreviewIndex);
                PreviewClip = (SoundClips)PreviewIndex;
                audioSource.PlayOneShot(dfUnity.SoundReader.GetAudioClip(PreviewIndex, false));
            }
        }
Example #27
0
        private static void AddAnimalAudioSource(GameObject go)
        {
            DaggerfallAudioSource source = go.AddComponent <DaggerfallAudioSource>();

            source.AudioSource.maxDistance = animalSoundMaxDistance;

            DaggerfallBillboard dfBillboard = go.GetComponent <DaggerfallBillboard>();
            SoundClips          sound       = SoundClips.None;

            switch (dfBillboard.Summary.Record)
            {
            case 0:
            case 1:
                sound = SoundClips.AnimalHorse;
                break;

            case 3:
            case 4:
                sound = SoundClips.AnimalCow;
                break;

            case 5:
            case 6:
                sound = SoundClips.AnimalPig;
                break;

            case 7:
            case 8:
                sound = SoundClips.AnimalCat;
                break;

            case 9:
            case 10:
                sound = SoundClips.AnimalDog;
                break;

            default:
                sound = SoundClips.None;
                break;
            }

            source.SetSound(sound, AudioPresets.PlayRandomlyIfPlayerNear);
        }
        public void EditorPreviewByIndex()
        {
            if (!ReadyCheck())
            {
                return;
            }

            if (PreviewIndex < minIndex || PreviewIndex >= maxIndex)
            {
                return;
            }

            if (ReadyCheck())
            {
                PreviewID   = (int)dfUnity.SoundReader.GetSoundID(PreviewIndex);
                PreviewClip = (SoundClips)PreviewIndex;
                AudioClip clip = dfUnity.SoundReader.GetAudioClip(PreviewIndex);
                DaggerfallUnity.Instance.StartCoroutine(PlayOneShotWhenReady(clip, 1.0f));
            }
        }
Example #29
0
        void Start()
        {
            // Store references
            dfUnity       = DaggerfallUnity.Instance;
            dfAudioSource = GetComponent <DaggerfallAudioSource>();
            playerMotor   = GetComponent <PlayerMotor>();

            // Add our own custom audio source at runtime as we need to change the pitch of footsteps.
            // We don't want that affecting to other sounds on this game object.
            customAudioSource              = gameObject.AddComponent <AudioSource>();
            customAudioSource.hideFlags    = HideFlags.HideInInspector;
            customAudioSource.playOnAwake  = false;
            customAudioSource.loop         = false;
            customAudioSource.dopplerLevel = 0f;

            // Set start position
            lastPosition = GetHorizontalPosition();

            // Set starting footsteps
            currentFootstepSound = FootstepSoundNormal;
        }
        void PlayLycanthropeMoveSound()
        {
            // Get sound based on infection type
            SoundClips customSound = SoundClips.None;

            if (infectionType == LycanthropyTypes.Werewolf)
            {
                customSound = SoundClips.EnemyWerewolfMove;
            }
            else if (infectionType == LycanthropyTypes.Wereboar)
            {
                customSound = SoundClips.EnemyWereboarMove;
            }

            // Play sound through weapon
            FPSWeapon screenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

            if (screenWeapon && customSound != SoundClips.None)
            {
                screenWeapon.PlayAttackVoice(customSound);
            }
        }
Example #31
0
        private void PlayEffects()
        {
            // Do nothing if audio not setup
            if (dfAudioSource == null || ambientSounds == null)
            {
                return;
            }

            // Get next sound index
            int index = random.Next(0, ambientSounds.Length);

            // Play effect
            if (Presets == AmbientSoundPresets.Storm && PlayLightningEffect)
            {
                // Play lightning effects together with appropriate sounds
                StartCoroutine(PlayLightningEffects(index));
            }
            else
            {
                // Do not play ambient effect in palace blocks
                if (doNotPlayInPalace)
                {
                    PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit;
                    if (playerEnterExit)
                    {
                        if (playerEnterExit.IsPlayerInsideDungeonPalace)
                        {
                            return;
                        }
                    }
                }

                // Play ambient sound as a one-shot 2D sound
                SoundClips clip = ambientSounds[index];
                dfAudioSource.PlayOneShot((int)clip, 0);
                RaiseOnPlayEffectEvent(clip);
            }
        }
        void Start()
        {
            // Store references
            dfUnity          = DaggerfallUnity.Instance;
            dfAudioSource    = GetComponent <DaggerfallAudioSource>();
            playerMotor      = GetComponent <PlayerMotor>();
            playerEnterExit  = GetComponent <PlayerEnterExit>();
            transportManager = GetComponent <TransportManager>();

            // CustomAudioSource was here for adjusting pitch. It should be removable now, but doing so makes the swimming sound loud, so leaving it for now.
            customAudioSource              = gameObject.AddComponent <AudioSource>();
            customAudioSource.hideFlags    = HideFlags.HideInInspector;
            customAudioSource.playOnAwake  = false;
            customAudioSource.loop         = false;
            customAudioSource.dopplerLevel = 0f;
            customAudioSource.spatialBlend = 0f;

            // Set start position
            lastPosition = GetHorizontalPosition();

            // Set starting footsteps
            currentFootstepSound1 = FootstepSoundDungeon1;
            currentFootstepSound2 = FootstepSoundDungeon2;
        }
 /// <summary>
 /// Plays sound clip once without changing clip on AudioSource.
 /// </summary>
 public void PlayOneShot(SoundClips soundClip, float spatialBlend = 1, float volumeScale = 1f)
 {
     PlayOneShot((int)soundClip, spatialBlend, volumeScale);
 }
 /// <summary>
 /// Quick set from clip name.
 /// </summary>
 public void SetSound(SoundClips soundClip, AudioPresets preset = AudioPresets.OnDemand, float spatialBlend = 1)
 {
     SoundIndex = (int)soundClip;
     Preset = preset;
     Apply(spatialBlend);
 }
        public void EditorPreviewByID()
        {
            if (!ReadyCheck())
                return;

            PreviewIndex = dfUnity.SoundReader.GetSoundIndex((uint)PreviewID);
            if (PreviewIndex >= 0)
            {
                PreviewClip = (SoundClips)PreviewIndex;
                EditorPreviewByIndex();
            }
            else
            {
                PreviewClip = SoundClips.None;
            }
        }
        /// <summary>
        /// Gets AudioClip based on Daggerfall SoundClip enum.
        /// </summary>
        /// <param name="soundClip">SoundClip enum.</param>
        /// <returns>AudioClip or null.</returns>
        public AudioClip GetAudioClip(SoundClips soundClip)
        {
            if (!ReadyCheck())
                return null;

            return GetAudioClip((int)soundClip);
        }
 public void SetDungeonDoorSounds()
 {
     OpenSound = SoundClips.DungeonDoorOpen;
     CloseSound = SoundClips.DungeonDoorClose;
     BashSound = SoundClips.PlayerDoorBash;
     LockedSound = SoundClips.ActivateLockUnlock;
 }
 public void SetInteriorDoorSounds()
 {
     OpenSound = SoundClips.NormalDoorOpen;
     CloseSound = SoundClips.NormalDoorClose;
     BashSound = SoundClips.PlayerDoorBash;
     LockedSound = SoundClips.ActivateLockUnlock;
 }
Example #39
0
 public AudioClip GetAudioClip(SoundClips clip)
 {
     return dfAudioSource.GetAudioClip((int)clip);
 }
        void FixedUpdate()
        {
            // Get player inside flag
            // Can only do this when PlayerEnterExit is available, otherwise default to true
            bool playerInside = (playerEnterExit == null) ? true : playerEnterExit.IsPlayerInside;

            // Change footstep sounds between winter/summer variants or when player enters/exits an interior space
            if (dfUnity.WorldTime.Now.SeasonValue != currentSeason || isInside != playerInside)
            {
                currentSeason = dfUnity.WorldTime.Now.SeasonValue;
                isInside = playerInside;
                if (currentSeason == DaggerfallDateTime.Seasons.Winter && !isInside)
                    currentFootstepSound = FootstepSoundSnow;
                else
                    currentFootstepSound = FootstepSoundNormal;

                clip = null;
            }

            // Reload clip if needed
            if (clip == null)
            {
                clip = dfAudioSource.GetAudioClip((int)currentFootstepSound);
            }

            // Check if player is grounded
            if (!IsGrounded())
            {
                // Player has lost grounding
                distance = 0f;
                lostGrounding = true;
                return;
            }
            else
            {
                // Player is grounded but we might need to reset after losing grounding
                if (lostGrounding)
                {
                    distance = 0f;
                    lastPosition = GetHorizontalPosition();
                    lostGrounding = false;
                    return;
                }
            }

            // Get distance player travelled horizontally
            Vector3 position = GetHorizontalPosition();
            distance += Vector3.Distance(position, lastPosition);
            lastPosition = position;

            // Get threshold
            float threshold = WalkStepInterval;
            if (playerMotor)
                threshold = (playerMotor.IsRunning) ? RunStepInterval : WalkStepInterval;

            // Play sound if over distance threshold
            if (distance > threshold && customAudioSource && clip)
            {
                // Set a random pitch so footsteps don't sound too mechanical
                customAudioSource.pitch = Random.Range(1f - PitchVariance, 1f + PitchVariance);
                customAudioSource.PlayOneShot(clip, FootstepVolumeScale);
                distance = 0f;
            }
        }
        public void EditorPreviewByIndex()
        {
            if (!ReadyCheck())
                return;

            if (PreviewIndex < minIndex || PreviewIndex >= maxIndex)
                return;

            if (ReadyCheck())
            {
                PreviewID = (int)dfUnity.SoundReader.GetSoundID(PreviewIndex);
                PreviewClip = (SoundClips)PreviewIndex;
                audioSource.PlayOneShot(dfUnity.SoundReader.GetAudioClip(PreviewIndex));
            }
        }
Example #42
0
        void Start()
        {
            // Save references
            dfAudioSource = GetComponent<DaggerfallAudioSource>();
            player = GameObject.FindGameObjectWithTag("Player");
            mobile = GetComponentInChildren<DaggerfallMobileUnit>();

            // Setup audio source
            dfAudioSource.AudioSource.maxDistance = AttractRadius;
            if (LinearRolloff)
                dfAudioSource.AudioSource.rolloffMode = AudioRolloffMode.Linear;
            dfAudioSource.AudioSource.spatialBlend = 1;

            // Assign sounds from mobile
            if (SoundsFromMobile && mobile)
            {
                MoveSound = (SoundClips)mobile.Summary.Enemy.MoveSound;
                BarkSound = (SoundClips)mobile.Summary.Enemy.BarkSound;
                AttackSound = (SoundClips)mobile.Summary.Enemy.AttackSound;
            }

            // Start attrack timer
            StartWaiting();
        }
 protected virtual void RaiseOnPlayEffectEvent(SoundClips clip)
 {
     AmbientEffectsEventArgs args = new AmbientEffectsEventArgs(clip);
     if (OnPlayEffect != null)
         OnPlayEffect(args);
 }
 /// <summary>Constructor helper.</summary>
 public AmbientEffectsEventArgs(SoundClips clip)
     : base()
 {
     this.Clip = clip;
 }
        void Start()
        {
            // Store references
            dfUnity = DaggerfallUnity.Instance;
            dfAudioSource = GetComponent<DaggerfallAudioSource>();
            playerMotor = GetComponent<PlayerMotor>();
            playerEnterExit = GetComponent<PlayerEnterExit>();

            // Add our own custom audio source at runtime as we need to change the pitch of footsteps.
            // We don't want that affecting to other sounds on this game object.
            customAudioSource = gameObject.AddComponent<AudioSource>();
            customAudioSource.hideFlags = HideFlags.HideInInspector;
            customAudioSource.playOnAwake = false;
            customAudioSource.loop = false;
            customAudioSource.dopplerLevel = 0f;
            customAudioSource.spatialBlend = 0f;

            // Set start position
            lastPosition = GetHorizontalPosition();

            // Set starting footsteps
            currentFootstepSound = FootstepSoundNormal;
        }
Example #46
0
 public void PlayOneShot(SoundClips clip)
 {
     if (dfAudioSource)
         dfAudioSource.PlayOneShot(clip, 0);
 }