Example #1
0
    public static Sound MakeSound(Vector3 position, Sound.Type soundType, float soundLevel, float lifetime)
    {
        Sound newSound = MakeSound(position, soundType, soundLevel);

        newSound.lifetimeSec = lifetime;
        return(newSound);
    }
Example #2
0
    public static Sound MakeSound(Transform parent, Sound.Type soundType, float soundLevel, float lifetime)
    {
        Sound newSound = MakeSound(parent, soundType, soundLevel);

        newSound.lifetimeSec = lifetime;
        return(newSound);
    }
Example #3
0
    public static Sound MakeSound(Vector3 position, Sound.Type soundType, float soundLevel, uint lifetimeFrames)
    {
        Sound newSound = MakeSound(position, soundType, soundLevel);

        newSound.lifetimeFrames = lifetimeFrames;
        return(newSound);
    }
Example #4
0
 public SoundRecord(Sound.Type soundType, float effectiveSoundLevel, Vector3 location)
 {
     this.soundType           = soundType;
     this.effectiveSoundLevel = effectiveSoundLevel;
     this.location            = location;
     this.timeHeard           = Time.time;
 }
Example #5
0
    // Various options for instantiating a sound
    // Combinations of: transform parent vs vector position, frames lifetime vs seconds lifetime
    public static Sound MakeSound(Transform parent, Sound.Type soundType, float soundLevel, uint lifetimeFrames)
    {
        Sound newSound = MakeSound(parent, soundType, soundLevel);

        newSound.lifetimeFrames = lifetimeFrames;
        return(newSound);
    }
 public SoundRecord(Sound.Type soundType, float effectiveSoundLevel, Vector3 location)
 {
     this.soundType = soundType;
     this.effectiveSoundLevel = effectiveSoundLevel;
     this.location = location;
     this.timeHeard = Time.time;
 }
Example #7
0
    public static Sound MakeSound(Vector3 position, Sound.Type soundType, float soundLevel)
    {
        GameObject obj      = new GameObject();
        Sound      newSound = obj.AddComponent <Sound>();

        newSound.transform.position = position;
        newSound.soundType          = soundType;
        newSound.soundLevel         = soundLevel;
        return(newSound);
    }
Example #8
0
 public void ChangeAudioVolume(float newVolume, Sound.Type soundType)
 {
     foreach (Sound s in sounds)
     {
         if (s.SoundType == soundType)
         {
             s.source.volume = newVolume * MasterVolume;
         }
     }
 }
Example #9
0
    public void PlaySound(Sound.Type soundName)
    {
        Sound sound = GetSoundByName(soundName);

        if (sound == null)
        {
            Debug.LogWarning("Could not find Sound " + soundName.ToString());
            return;
        }

        audioSource.PlayOneShot(sound.clip);
        audioSource.volume = sound.volume;
        audioSource.pitch  = sound.pitch;
    }
Example #10
0
 private Sound GetSoundByName(Sound.Type soundName)
 {
     return(Array.Find(sounds, s => s.soundName == soundName));
 }
Example #11
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);

        for (int i = 0; i < System.Enum.GetValues(typeof(Sound.Type)).Length; i++)
        {
            Sound.Type temp_type  = (Sound.Type)i;
            GameObject new_object = new GameObject(temp_type.ToString());
            new_object.transform.SetParent(this.transform);
        }

        foreach (Sound s in sounds)
        {
            if (s.type == Sound.Type.Menu_Sound)
            {
                s.source = transform.Find("Menu_Sounds").gameObject.AddComponent <AudioSource>();
            }

            else if (s.type == Sound.Type.Player1_Sounds)
            {
                s.source = transform.Find("Player1_Sounds").gameObject.AddComponent <AudioSource>();
            }

            else if (s.type == Sound.Type.Player2_Sounds)
            {
                s.source = transform.Find("Player2_Sounds").gameObject.AddComponent <AudioSource>();
            }

            else if (s.type == Sound.Type.Player3_Sounds)
            {
                s.source = transform.Find("Player3_Sounds").gameObject.AddComponent <AudioSource>();
            }

            else if (s.type == Sound.Type.Player4_Sounds)
            {
                s.source = transform.Find("Player4_Sounds").gameObject.AddComponent <AudioSource>();
            }

            else if (s.type == Sound.Type.All_Players_Sounds)
            {
                s.source = transform.Find("All_Players_Sounds").gameObject.AddComponent <AudioSource>();
            }

            else if (s.type == Sound.Type.Environment_Sound)
            {
                s.source = transform.Find("Environment_Sound").gameObject.AddComponent <AudioSource>();
            }

            s.source.clip      = s.clip;
            s.source.volume    = s.volume;
            s.source.loop      = s.looping;
            s.source.panStereo = s.stereo;
        }
    }