예제 #1
0
        AudioSource AttachAudioSource(GameObject target, AudioEventArgs arg)
        {
            AudioSource audio = target.AddComponent <AudioSource>();

            SetAudioProperties(ref audio, arg);
            return(audio);
        }
예제 #2
0
 void SetAudioProperties(ref AudioSource audio, AudioEventArgs arg)
 {
     audio.playOnAwake  = arg.AudioDataSet.PlayOnAwake;
     audio.volume       = arg.AudioDataSet.Volume;
     audio.pitch        = arg.AudioDataSet.Speed;
     audio.spatialBlend = arg.AudioDataSet.SpatialBlend;
     audio.mute         = arg.AudioDataSet.Mute;
     audio.loop         = arg.AudioDataSet.Loop;
 }
예제 #3
0
        AudioSource CreateAudioSource(AudioEventArgs arg)
        {
            GameObject go = new GameObject(arg.AudioDataSet.ObjectName);

            go.transform.SetParent(ModuleMountObject.transform);
            go.transform.ResetLocalTransform();
            AudioSource audio = go.AddComponent <AudioSource>();

            SetAudioProperties(ref audio, arg);
            return(audio);
        }
예제 #4
0
 /// <summary>
 /// 播放背景音乐,唯一的
 /// </summary>
 /// <param name="clip"></param>
 /// <param name="arg"></param>
 public void PlayBackgroundAudio(AudioEventArgs arg)
 {
     if (backgroundAduio == null)
     {
         backgroundAduio      = CreateAudioSource(arg);
         backgroundAduio.clip = arg.AudioDataSet.AudioClip;
         backgroundAduio.Play();
     }
     else
     {
         if (backgroundAduio.isPlaying)
         {
             backgroundAduio.Stop();
         }
         backgroundAduio.clip = arg.AudioDataSet.AudioClip;
         SetAudioProperties(ref backgroundAduio, arg);
         backgroundAduio.Play();
     }
 }
예제 #5
0
 /// <summary>
 /// 播放背景音乐,唯一的
 /// </summary>
 /// <param name="clip"></param>
 /// <param name="arg"></param>
 public void PlayBackgroundAudio(AudioEventArgs arg)
 {
     if (backgroundAduio == null)
     {
         backgroundAduio      = CreateAudioSource(arg);
         backgroundAduio.clip = arg.AudioEventObject.AudioClip;
         backgroundAduio.Play();
     }
     else
     {
         if (backgroundAduio.isPlaying)
         {
             backgroundAduio.Stop();
         }
         backgroundAduio.clip = arg.AudioEventObject.AudioClip;
         SetAudioProperties(ref backgroundAduio, arg);
         backgroundAduio.Play();
     }
     Utility.DebugLog("audioPlaying");
 }
예제 #6
0
 /// <summary>
 /// 播放世界音效
 /// 可用在3D环境声音以及特效爆炸等上
 /// </summary>
 /// <param name="attachTarget">audioSource挂载的对象</param>
 /// <param name="clip">音频</param>
 /// <param name="arg">具体参数</param>
 public void PlayWorldAudio(GameObject attachTarget, AudioEventArgs args)
 {
     if (worldAudios.ContainsKey(attachTarget))
     {
         AudioSource audio = worldAudios[attachTarget];
         if (audio.isPlaying)
         {
             audio.Stop();
         }
         SetAudioProperties(ref audio, args);
         audio.clip = args.AudioDataSet.AudioClip;
         audio.Play();
     }
     else
     {
         AudioSource audio = AttachAudioSource(attachTarget, args);
         worldAudios.Add(attachTarget, audio);
         audio.clip = args.AudioDataSet.AudioClip;
         audio.Play();
     }
 }