Beispiel #1
0
        public AudioSource PlayLoop(MG_PlayAudioType audioType)
        {
            AudioSource result = PlayOneShot(audioType);

            result.loop = true;
            return(result);
        }
Beispiel #2
0
        public AudioSource PlayOneShot(MG_PlayAudioType audioType)
        {
            int _typeIndex = (int)audioType;

            if (dic_type_ac.TryGetValue(_typeIndex, out AudioClip tempAC))
            {
                if (tempAC is null)
                {
                    Debug.LogError("Play MG_ShotAudio Error : loadedDic has key , but content is null.");
                    return(null);
                }
                bool hasPlayed = false;
                int  asCount   = as_all.Count;
                for (int i = 0; i < asCount; i++)
                {
                    if (!as_all[i].isPlaying)
                    {
                        AudioSource tempAS = as_all[i];
                        tempAS.clip        = tempAC;
                        tempAS.loop        = false;
                        tempAS.playOnAwake = false;
                        tempAS.mute        = !MG_Manager.Instance.Get_Save_SoundOn();
                        tempAS.Play();
                        hasPlayed = true;
                        return(tempAS);
                    }
                }
                if (!hasPlayed)
                {
                    AudioSource tempAS = go_root.AddComponent <AudioSource>();
                    tempAS.clip        = tempAC;
                    tempAS.loop        = false;
                    tempAS.playOnAwake = false;
                    tempAS.mute        = !MG_Manager.Instance.Get_Save_SoundOn();
                    tempAS.Play();
                    as_all.Add(tempAS);
                    return(tempAS);
                }
            }
            else
            {
                if (dic_type_Path.TryGetValue(_typeIndex, out string tempPath))
                {
                    if (string.IsNullOrEmpty(tempPath))
                    {
                        Debug.LogError("Play MG_ShotAudio Error : audioPathDic has key , but content is null.");
                        return(null);
                    }
                    tempAC = Resources.Load <AudioClip>(tempPath);
                    dic_type_ac.Add(_typeIndex, tempAC);
                    return(PlayOneShot(audioType));
                }
                else
                {
                    Debug.LogError("Play MG_ShotAudio Error : audioPathDic not has this audio. type : " + audioType);
                    return(null);
                }
            }
            return(null);
        }