Ejemplo n.º 1
0
        public static int?PlaySound(this SoundComponent soundComponent, int soundId, Entity bindingEntity = null, object userData = null)
        {
            IDataTable <DRSound> dtSound = GameEntry.DataTable.GetDataTable <DRSound>();
            DRSound drSound = dtSound.GetDataRow(soundId);

            if (drSound == null)
            {
                Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString());
                return(null);
            }

            PlaySoundParams playSoundParams = new PlaySoundParams
            {
                Priority           = drSound.Priority,
                Loop               = drSound.Loop,
                VolumeInSoundGroup = drSound.Volume,
                SpatialBlend       = drSound.SpatialBlend,
            };

            return(soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 返回音频长度
        /// </summary>
        /// <param name="soundComponent"></param>
        /// <param name="soundId"></param>
        /// <returns>返回音频长度</returns>
        public static int?PlaySoundAndLength(this SoundComponent soundComponent, int soundId, ref int length)
        {
            IDataTable <DRSound> dtSound = GameEntry.DataTable.GetDataTable <DRSound>();
            DRSound drSound = dtSound.GetDataRow(soundId);

            if (drSound == null)
            {
                Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString());
                return(0);
            }

            PlaySoundParams playSoundParams = new PlaySoundParams
            {
                Priority           = drSound.Priority,
                Loop               = drSound.Loop,
                VolumeInSoundGroup = drSound.Volume,
                SpatialBlend       = drSound.SpatialBlend,
            };

            length = drSound.Length;
            return(soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, null, null));
        }