static public void Initialization()
    {
        XmlDocument doc = UniGameResources.currentUniGameResources.LoadResource_XmlFile("SoundEffect.xml");

        if (doc == null)
        {
            throw new Exception("SoundEffectPlayer Initialization Err!");
        }
        XmlNode     root     = doc.SelectSingleNode("SoundEffect");
        XmlNodeList nodelist = root.SelectNodes("item");

        for (int i = 0; i < nodelist.Count; i++)
        {
            XmlNode         n    = nodelist[i];
            SoundEffectData data = new SoundEffectData(n.Attribute("name"),
                                                       n.Attribute("resourcename"),
                                                       Convert.ToSingle(n.Attribute("volume")),
                                                       n.Attribute("language") == "1");
            try
            {
                soundEffectList.Add(data.Id, data);
            }
            catch (System.Exception ex)
            {
                Debug.Log(ex.ToString());
            }
        }
    }
示例#2
0
        public static AudioSource PlaySfx(this SoundEffectData data, bool looping = false, float volume = 1)
        {
            if (data.Clip != null)
            {
                return(PlaySfx(data.Clip, data.Volume * volume, looping));
            }

            return(null);
        }
示例#3
0
 public void PlaySound(SoundEffectData soundToPlay, Vector3 position)
 {
     if (!remainingRepeatPreventionData.Contains(soundToPlay))
     {
         float pitch = 1.0f + UnityEngine.Random.Range(-soundToPlay.pitchVariation, soundToPlay.pitchVariation);
         PlaySound(soundToPlay.soundEffect, position, soundToPlay.volume, pitch);
         remainingRepeatPreventionData.Add(soundToPlay);
         remainingRepeatPreventionTimes.Add(soundToPlay.timeBetweenMultipleSounds);
     }
 }
示例#4
0
        public SoundEffectSystem(
            ICommunication communication)
        {
            this.communication = communication;

            dataFilePath = BGC.IO.DataManagement.PathForDataFile("Config", "SoundEffects.json");

            if (File.Exists(dataFilePath))
            {
                soundEffectData = JsonSerializer.Deserialize <SoundEffectData>(File.ReadAllText(dataFilePath));
                soundEffectData.VerifyAndPopulate(communication);
            }
            else
            {
                soundEffectData = new SoundEffectData();
                File.WriteAllText(dataFilePath, JsonSerializer.Serialize(soundEffectData));
            }
        }
    public static void PlayStandalone(string name)
    {
        SoundEffectData data = FindSoundEffect(name);

        if (data == null)
        {
            return;
        }
        if (soundEffectPlayer == null)
        {
            return;
        }
        if (data.playerSource != null)
        {
            if (data.playerSource.isPlaying)
            {
                return;
            }
            data.playerSource.Play();
        }
        else
        {
            data.playerSource = soundEffectPlayer.CreateStandAloneAudioSource();
            AudioClip sound = null;
            if (data.isLanguage)
            {
                sound = UniGameResources.currentUniGameResources.LoadLanguageResource_AudioClip(data.resourceName);
            }
            else
            {
                sound = UniGameResources.currentUniGameResources.LoadResource_AudioClip(data.resourceName);
            }
            if (sound == null)
            {
                return;
            }
            data.playerSource.clip   = sound;
            data.playerSource.volume = data.volume;
            data.playerSource.Play();
        }
    }
    static public void Play(string name)
    {
        SoundEffectData data = FindSoundEffect(name);

        if (data == null)
        {
            return;
        }
        if (soundEffectPlayer == null)
        {
            return;
        }
        AudioSource audioSource = soundEffectPlayer.audioSource;

        if (audioSource == null)
        {
            return;
        }
        AudioClip sound = null;

        if (data.isLanguage)
        {
            sound = UniGameResources.currentUniGameResources.LoadLanguageResource_AudioClip(data.resourceName);
        }
        else
        {
            sound = UniGameResources.currentUniGameResources.LoadResource_AudioClip(data.resourceName);
        }

        if (sound == null)
        {
            return;
        }
        audioSource.clip   = sound;
        audioSource.volume = data.volume;
        audioSource.Play();
    }