Пример #1
0
        public bool Play(AudioAsset audioAsset, bool loop = false, AudioMixerGroup audioMixerGroup = null)
        {
            if (IsPlaying)
            {
                return(false);
            }

            if (audioAsset.AudioClip == null)
            {
                Debug.LogError("[AudioChannel] " + audioAsset + " has no AudioClip.", audioAsset);
                return(false);
            }

            audioSource.clip = audioAsset.AudioClip;
            audioSource.outputAudioMixerGroup = audioMixerGroup ?? audioAsset.AudioMixerGroup;

            Volume        = audioAsset.Volume;
            Pitch         = audioAsset.Pitch;
            PanStereo     = audioAsset.StereoPan;
            SpatialBlend  = audioAsset.SpatialBlend;
            ReverbZoneMix = audioAsset.ReverbZoneMix;
            Loop          = loop;

            AudioAsset = audioAsset;

            audioSource.Play();
            return(true);
        }
Пример #2
0
        public bool PlayRandom(AudioAssetGroup audioAssetGroup, bool loop = false)
        {
            List <AudioAsset> audioAssets = new List <AudioAsset>(audioAssetGroup.AudioAssets);
            AudioAsset        target      = audioAssets[Random.Range(0, audioAssets.Count)];

            return(Play(audioAssetGroup, target, loop));
        }
Пример #3
0
        private static void CreateAudioAssets()
        {
            if (Selection.objects.Length > 0)
            {
                foreach (Object obj in Selection.objects)
                {
                    if (obj.GetType() == typeof(AudioClip))
                    {
                        string path = AssetDatabase.GetAssetPath(obj);

                        if (!string.IsNullOrEmpty(path))
                        {
                            path = Path.ChangeExtension(path, ".asset");

                            AudioAsset asset = CreateInstance <AudioAsset>();
                            asset.audioClip = obj as AudioClip;

                            AssetDatabase.CreateAsset(asset, path);
                        }
                    }
                }

                AssetDatabase.SaveAssets();
            }
        }
		public AudioChannel Play(AudioAsset audioAsset , bool loop = false , AudioMixerGroup audioMixerGroup = null)
		{
			if (audioAsset == null)
			{
				return null;
			}

			foreach (AudioChannel channel in channels)
			{
				if (claimedChannels.Contains(channel))
				{
					continue;
				}

				if (channel.Play(audioAsset , loop , audioMixerGroup))
				{
					return channel;
				}
			}

			Debug.LogWarning("[AudioManager] No available audio channels for audio asset: " + audioAsset);
			return null;
		}
        public AudioChannel Play(AudioAsset audioAsset, bool loop = false, AudioMixerGroup audioMixerGroup = null)
        {
            if (audioAsset == null)
            {
                return(null);
            }

            foreach (AudioChannel channel in channels)
            {
                if (claimedChannels.Contains(channel))
                {
                    continue;
                }

                if (channel.Play(audioAsset, loop, audioMixerGroup))
                {
                    return(channel);
                }
            }

            Debug.LogWarning("[AudioManager] No available audio channels for audio asset: " + audioAsset);
            return(null);
        }
Пример #6
0
 public bool Play(AudioAssetGroup audioAssetGroup, AudioAsset audioAsset, bool loop = false)
 {
     return(Play(audioAsset, loop, audioAssetGroup.AudioMixerGroup ?? audioAsset.AudioMixerGroup));
 }
		public bool Play(AudioAssetGroup audioAssetGroup , AudioAsset audioAsset , bool loop = false)
		{
			return Play(audioAsset , loop , audioAssetGroup.AudioMixerGroup ?? audioAsset.AudioMixerGroup);
		}
		public bool Play(AudioAsset audioAsset , bool loop = false , AudioMixerGroup audioMixerGroup = null)
		{
			if (IsPlaying)
			{
				return false;
			}

			if (audioAsset.AudioClip == null)
			{
				Debug.LogError("[AudioChannel] " + audioAsset + " has no AudioClip." , audioAsset);
				return false;
			}

			audioSource.clip = audioAsset.AudioClip;
			audioSource.outputAudioMixerGroup = audioMixerGroup ?? audioAsset.AudioMixerGroup;

			Volume = audioAsset.Volume;
			Pitch = audioAsset.Pitch;
			PanStereo = audioAsset.StereoPan;
			SpatialBlend = audioAsset.SpatialBlend;
			ReverbZoneMix = audioAsset.ReverbZoneMix;
			Loop = loop;

			AudioAsset = audioAsset;

			audioSource.Play();
			return true;
		}