Exemplo n.º 1
0
        /// <summary>
        /// 播放音乐
        /// </summary>
        /// <param name="musicId">音乐编号</param>
        /// <param name="userData">用户自定义数据</param>
        public static int?PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null)
        {
            soundComponent.StopMusic();

            //获取音乐数据表,然后根据音乐编号获取到对应的数据表行对象
            IDataTable <DRMusic> dtMusic = GameEntry.DataTable.GetDataTable <DRMusic>();
            DRMusic drMusic = dtMusic.GetDataRow(musicId);

            if (drMusic == null)
            {
                Log.Warning("Can not load music '{0}' from data table.", musicId.ToString());
                return(null);
            }

            //创建播放声音参数对象
            PlaySoundParams playSoundParams = new PlaySoundParams
            {
                Priority           = 64,
                Loop               = true,
                VolumeInSoundGroup = 1f,
                FadeInSeconds      = FadeVolumeDuration,
                SpatialBlend       = 0f,
            };

            s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", playSoundParams.Priority, playSoundParams, userData);
            return(s_MusicSerialId);
        }
Exemplo n.º 2
0
        public static int?PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null)
        {
            soundComponent.StopMusic();

            IDataTable <DRMusic> dtMusic = GameEntry.DataTable.GetDataTable <DRMusic>();
            DRMusic drMusic = dtMusic.GetDataRow(musicId);

            if (drMusic == null)
            {
                Log.Warning("Can not load music '{0}' from data table.", musicId.ToString());
                return(null);
            }

            PlaySoundParams playSoundParams = PlaySoundParams.Create();

            playSoundParams.Priority           = 64;
            playSoundParams.Loop               = true;
            playSoundParams.VolumeInSoundGroup = 1f;
            playSoundParams.FadeInSeconds      = FadeVolumeDuration;
            playSoundParams.SpatialBlend       = 0f;
            s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
            return(s_MusicSerialId);
        }