private static int?s_MusicSerialId     = null;  //音乐序列编号

        //播放背景音乐
        public static int?PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null)
        {
            soundComponent.StopMusic();     //停止播放背景音乐
            //获取背景音乐数据
            IDataTable <DRMusic> dtMusic = GameEntry.DataTable.GetDataTable <DRMusic>();

            if (dtMusic == null)
            {
                return(null);
            }
            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 //2D音乐
            };

            s_MusicSerialId = soundComponent.PlaySound(RuntimeAssetUtility.GetMusicAsset(drMusic.AssetName), "Music", RuntimeConstant.AssetPriority.MusicAsset, playSoundParams, null, userData);
            return(s_MusicSerialId);
        }
Ejemplo n.º 2
0
        public static int?OpenRuntimeUIForm(this UIComponent uiComponent, int uiFormId, string hotFormTypeName, object userData = null)
        {
            //先获取UI配置表数据
            IDataTable <DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable <DRUIForm>();
            DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);

            if (drUIForm == null)
            {
                return(null);
            }

            //获取资源路径
            string assetName = RuntimeAssetUtility.GetUIFormAsset(drUIForm.AssetName);

            if (!drUIForm.AllowMultiInstance)               //不允许存在多个界面实例
            {
                if (uiComponent.IsLoadingUIForm(assetName)) //正在加载
                {
                    return(null);
                }

                UIForm uiForm = uiComponent.GetUIForm(assetName);   //获取已加载的界面
                if (uiForm != null)
                {
                    return(uiForm.SerialId); //TODO:这里返回已打开界面id?还是返回null?
                }
            }

            return(uiComponent.OpenUIForm(assetName, drUIForm.UIGroupName, RuntimeConstant.AssetPriority.UIFormAsset, drUIForm.PauseCoveredUIForm, userData));
        }
Ejemplo n.º 3
0
        //加载本地化配置
        public static void LoadDictionary(this LocalizationComponent localizationComponent, string dictionaryName, LoadType loadType, object userData = null)
        {
            if (string.IsNullOrEmpty(dictionaryName))
            {
                Log.Warning("Dictionary name is invalid.");
                return;
            }

            localizationComponent.LoadDictionary(dictionaryName, RuntimeAssetUtility.GetDictionaryAsset(dictionaryName, loadType), loadType, RuntimeConstant.AssetPriority.DictionaryAsset, userData);
        }
        //加载配置
        public static void LoadConfig(this ConfigComponent configComponent, string configName, LoadType loadType, object userData = null)
        {
            if (string.IsNullOrEmpty(configName))
            {
                Log.Warning("Config name is invalid.");
                return;
            }

            //加载配置
            configComponent.LoadConfig(configName, RuntimeAssetUtility.GetConfigAsset(configName, loadType), loadType, RuntimeConstant.AssetPriority.ConfigAsset, userData);
        }
Ejemplo n.º 5
0
        //显示实体
        private static void ShowRuntimeEntity(this EntityComponent entityComponent, Type logicType, string entityGroup, int priority, int entityId, int dataId, object userData)
        {
            if (entityId == 0 || dataId == 0)
            {
                Log.Warning("[EntityExtension.ShowRuntimeEntity] entityId or dataId is invalid.");
                return;
            }

            IDataTable <DREntity> dtEntity = GameEntry.DataTable.GetDataTable <DREntity>();
            DREntity drEntity = dtEntity.GetDataRow(dataId);

            if (drEntity == null)
            {
                Log.Warning("[EntityExtension.ShowRuntimeEntity] Can not load entity id '{0}' from data table.", dataId.ToString());
                return;
            }

            entityComponent.ShowEntity(entityId, logicType, RuntimeAssetUtility.GetEntityAsset(drEntity.AssetName), entityGroup, priority, userData);
        }
        //加载热更新脚本
        private void LoadHotfix(string hotfixName)
        {
            string name = Utility.Text.Format("Hotfix.{0}", hotfixName);

            m_LoadedFlag.Add(name, false);
            GameEntry.Resource.LoadAsset(RuntimeAssetUtility.GetHotfixAsset(hotfixName), RuntimeConstant.AssetPriority.FontAsset,
                                         new LoadAssetCallbacks(
                                             //加载成功的回调
                                             (assetName, asset, duration, userData) =>
            {
                m_LoadedFlag[name] = true;
                m_loadedHotifx.Add(name, ((TextAsset)asset).bytes);
                Log.Info("Load hotfix '{0}' OK.", hotfixName);
            },
                                             //加载失败的回调
                                             (assetName, status, errorMessage, userData) =>
            {
                Log.Error("Can not load hotfix '{0}' from '{1}' with error message '{2}'.", hotfixName, assetName, errorMessage);
            }
                                             ));
        }
        //加载字体
        private void LoadFont(string fontName)
        {
            string name = Utility.Text.Format("Font.{0}", fontName);

            m_LoadedFlag.Add(name, false);
            GameEntry.Resource.LoadAsset(RuntimeAssetUtility.GetFontAsset(fontName), RuntimeConstant.AssetPriority.FontAsset,
                                         new LoadAssetCallbacks(
                                             //加载成功的回调
                                             (assetName, asset, duration, userData) =>
            {
                m_LoadedFlag[name] = true;
                UGUIForm.SetMainFont((Font)asset);
                Log.Info("Load font '{0}' OK.", fontName);
            },
                                             //加载失败的回调
                                             (assetName, status, errorMessage, userData) =>
            {
                Log.Error("Can not load font '{0}' from '{1}' with error message '{2}'.", fontName, assetName, errorMessage);
            }
                                             ));
        }
        //播放UI声音
        public static int?PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null)
        {
            //获取声音数据
            IDataTable <DRUISound> dtUISound = GameEntry.DataTable.GetDataTable <DRUISound>();
            DRUISound drUISound = dtUISound.GetDataRow(uiSoundId);

            if (drUISound == null)
            {
                Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString());
                return(null);
            }
            //播放参数
            PlaySoundParams playSoundParams = new PlaySoundParams
            {
                Priority           = drUISound.Priority,
                Loop               = false,
                VolumeInSoundGroup = drUISound.Volume,
                SpatialBlend       = 0f
            };

            return(soundComponent.PlaySound(RuntimeAssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", RuntimeConstant.AssetPriority.UISoundAsset, playSoundParams, userData));
        }
        //播放声音
        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(RuntimeAssetUtility.GetSoundAsset(drSound.AssetName), "Sound", RuntimeConstant.AssetPriority.SoundAsset,
                                            playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData));
        }
Ejemplo n.º 10
0
        //显示实体
        public static void ShowHotEntity(this EntityComponent entityComponent, string hotLogicTypeName, string entityGroup, int priority, int entityId, int dataId, object userData)
        {
            if (entityId == 0 || dataId == 0)
            {
                Log.Warning("[EntityExtension.ShowRuntimeEntity] entityId or dataId is invalid.");
                return;
            }

            IDataTable <DREntity> dtEntity = GameEntry.DataTable.GetDataTable <DREntity>();
            DREntity drEntity = dtEntity.GetDataRow(dataId);

            if (drEntity == null)
            {
                Log.Warning("Can not load entity id '{0}' from data table.", dataId.ToString());
                return;
            }

            //实体传递的数据
            //UserEntityData uiData = ReferencePool.Acquire<UserEntityData>();
            //uiData.Fill(hotLogicTypeName, userData);
            UserEntityData entityData = new UserEntityData(hotLogicTypeName, userData);

            entityComponent.ShowEntity(entityId, typeof(HotEntity), RuntimeAssetUtility.GetEntityAsset(drEntity.AssetName), entityGroup, priority, entityData);
        }
        internal static readonly char[] DataTrimSeparators  = new char[] { '\"' }; //结尾排除字符

        //加载数据表
        public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName, LoadType loadType, object userData)
        {
            if (string.IsNullOrEmpty(dataTableName))
            {
                Log.Warning("Data table name is invalid.");
                return;
            }

            //只能有一个下划线
            string[] splitNames = dataTableName.Split('_');
            if (splitNames.Length > 2)
            {
                Log.Warning("Data table name is invalid.");
                return;
            }

            string dataRowClassName = Utility.Text.Format("Game.Runtime.{0}{1}", DataRowClassPrefixName, splitNames[0]);

            Type dataRowType = Type.GetType(dataRowClassName, true);  //获取数据类

            if (dataRowType == null)
            {
                Log.Warning("Can not get data row type with class name '{0}'.", dataRowClassName);
                return;
            }

            string dataTableNameInType = splitNames.Length > 1 ? splitNames[1] : null;

            dataTableComponent.LoadDataTable(dataRowType, dataTableName, dataTableNameInType, RuntimeAssetUtility.GetDataTableAsset(dataTableName, loadType), loadType, userData);
        }