/// <summary> /// ///////////////// /// </summary> private void OnLoadDataTableSuccess(object sender, GameEventArgs e) { // 获取框架数据表组件 DataTableComponent DataTable = UnityGameFramework.Runtime.GameEntry.GetComponent <DataTableComponent>(); // 获得数据表 GameFramework.DataTable.IDataTable <ConfigHero> table = DataTable.GetDataTable <ConfigHero>(); // 获得所有行 ConfigHero[] rows = table.GetAllDataRows(); Log.Debug("ConfigHeros:" + rows.Length); if (table != null) { // 根据行号获得某一行 ConfigHero row = table.GetDataRow(1); // 或直接使用 dtScene[1] // 此行存在,可以获取内容了 string name = table.Name; int hp = row.Hp; Log.Debug("name:" + name + ", hp:" + hp); } else { // 此行不存在 } // 获得满足条件的所有行 ConfigHero[] drScenesWithCondition = table.GetAllDataRows(x => x.Id > 0); // 获得满足条件的第一行 ConfigHero drSceneWithCondition = table.GetDataRow(x => x.Name == "mutou"); }
public override void OnInspectorGUI() { serializedObject.Update(); DataTableComponent t = (DataTableComponent)target; EditorGUILayout.PropertyField(m_EnableLoadDataTableSuccessEvent); EditorGUILayout.PropertyField(m_EnableLoadDataTableFailureEvent); EditorGUILayout.PropertyField(m_EnableLoadDataTableUpdateEvent); EditorGUILayout.PropertyField(m_EnableLoadDataTableDependencyAssetEvent); if (EditorApplication.isPlaying && PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab) { EditorGUILayout.LabelField("Data Table Count", t.DataTablesCount.ToString()); IDataTable[] dataTables = t.GetAllDataTables(); foreach (IDataTable dataTable in dataTables) { DrawDataTable(dataTable); } } serializedObject.ApplyModifiedProperties(); Repaint(); }
public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName, object userData = null) { if (dataTableName.IsNullOrEmpty()) { Log.Warning("Data table name is invalid."); return; } var splitNames = dataTableName.Split('_'); if (splitNames.Length > 2) { Log.Warning("Data table name is invalid."); return; } var dataRowClassName = DataRowClassPrefixName + splitNames[0]; var dataRowType = Type.GetType(dataRowClassName); if (dataRowType == null) { Log.Warning("Can not get data row type with class name '{0}'.", dataRowClassName); return; } var dataTableNameInType = splitNames.Length > 1 ? splitNames[1] : null; dataTableComponent.LoadDataTable(dataRowType, dataTableName, dataTableNameInType, AssetUtility.GetDataTableAsset(dataTableName), Constant.AssetPriority.DataTableAsset, userData); //Log.Debug("<color=green> dataRowType = {0}, dataTableName = {1}, dataTableNameInType = {2}, AssetUitity.GetDataTableAsset(dataTableName) = {3}</color>", dataRowType, dataTableName, dataTableNameInType, AssetUitity.GetDataTableAsset(dataTableName)); }
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); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); DataTableComponent t = target as DataTableComponent; m_EnableLoadDataTableSuccessEvent.boolValue = EditorGUILayout.ToggleLeft("Enable Load Table Success Event", m_EnableLoadDataTableSuccessEvent.boolValue); m_EnableLoadDataTableFailureEvent.boolValue = EditorGUILayout.ToggleLeft("Enable Load Table Failure Event", m_EnableLoadDataTableFailureEvent.boolValue); m_EnableLoadDataTableUpdateEvent.boolValue = EditorGUILayout.ToggleLeft("Enable Load Table Update Event", m_EnableLoadDataTableUpdateEvent.boolValue); m_EnableLoadDataTableDependencyAssetEvent.boolValue = EditorGUILayout.ToggleLeft("Enable Load Table Dependency Asset Event", m_EnableLoadDataTableDependencyAssetEvent.boolValue); //运行模式不能绘制辅助器信息 EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { m_DataTableHelperInfo.Draw(); } EditorGUI.EndDisabledGroup(); //运行模式绘制数据表 if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) { EditorGUILayout.LabelField("Data Table Count", t.Count.ToString()); //数据表数量 DataTableBase[] dataTables = t.GetAllDataTables(); //获取所有的数据表 foreach (var dataTable in dataTables) { EditorGUILayout.LabelField(Utility.Text.GetFullName(dataTable.Type, dataTable.Name), Utility.Text.Format("{0} Rows", dataTable.Count.ToString())); } } serializedObject.ApplyModifiedProperties(); Repaint(); }
/// <summary> /// 加载数据表 /// </summary> /// <param name="dataTableComponent"></param> /// <param name="dataTableName"></param> /// <param name="userData"></param> public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName, object userData = null) { 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 = DataRowClassPrefixName + splitNames[0]; Type dataRowType = Type.GetType(dataRowClassName); 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, AssetUtility.GetDataTableAsset(dataTableName), userData); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); DataTableComponent t = (DataTableComponent)target; EditorGUILayout.PropertyField(m_EnableLoadDataTableSuccessEvent); EditorGUILayout.PropertyField(m_EnableLoadDataTableFailureEvent); EditorGUILayout.PropertyField(m_EnableLoadDataTableUpdateEvent); EditorGUILayout.PropertyField(m_EnableLoadDataTableDependencyAssetEvent); EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { m_DataTableHelperInfo.Draw(); } EditorGUI.EndDisabledGroup(); if (EditorApplication.isPlaying) { EditorGUILayout.LabelField("Data Table Count", t.Count.ToString()); DataTableBase[] dataTables = t.GetAllDataTables(); foreach (DataTableBase dataTable in dataTables) { DrawDataTable(dataTable); } } serializedObject.ApplyModifiedProperties(); Repaint(); }
/// <summary> /// 游戏框架组件初始化。 /// </summary> protected override void Awake() { base.Awake(); m_DataTableManager = CentorPivot.This.GetComponent <DataTableComponent>(); if (m_DataTableManager == null) { Log.Fatal("Data table manager is invalid."); return; } m_EventComponent = CentorPivot.This.GetComponent <EventComponent>(); if (m_EventComponent == null) { Log.Fatal("Event component is invalid."); return; } m_DataTableManager.SetResourceManager(CentorPivot.This.GetComponent <ResourceComponent>()); DataTableHelperBase dataTableHelper = (DataTableHelperBase)CreateHelper.Create(m_DataTableHelperTypeName); if (dataTableHelper == null) { Log.Error("Can not create data table helper."); return; } m_DataTableManager.SetDataProviderHelper(dataTableHelper); }
public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName, LoadType loadType, object userData = null) { 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 = DataRowClassPrefixName + splitNames[0]; Type dataRowType = Type.GetType(dataRowClassName); 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; string path = "Assets/GameMain/DataTables/" + dataTableName + (loadType == LoadType.Text ? ".txt" : ".bytes"); dataTableComponent.LoadDataTable(dataRowType, dataTableName, dataTableNameInType, path, loadType, 0, userData); }
private void OnLoadDataTableSuccess(object sender, GameEventArgs e) { //获取框架数据表组件 DataTableComponent DataTable = GameEntry.GetComponent <DataTableComponent>(); //获得数据表 IDataTable <DRHero> dtScene = DataTable.GetDataTable <DRHero>(); //获得所有行 DRHero[] drHeros = dtScene.GetAllDataRows(); Log.Debug("drHeros:" + drHeros.Length); //根据行号获取某一行 DRHero drScene = dtScene.GetDataRow(1); //DRHero drScene = drHeros[1]; if (drScene != null) { string name = drScene.Name; int atk = drScene.Atk; Log.Debug("name:" + name + ",atk:" + atk); } else { Log.Debug("index not exist"); } //获取满足条件的所有行 DRHero[] drScenesWithCondition = dtScene.GetAllDataRows(x => x.Id > 0); //获取满足条件的第一行 DRHero drFirstSceneWithCondition = dtScene.GetDataRow(x => x.Name == "mutou"); }
public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName, string dataTableAssetName, object userData) { if (string.IsNullOrEmpty(dataTableName)) { Log.Warning("Data table name is invalid."); return; } string[] splitedNames = dataTableName.Split('_'); if (splitedNames.Length > 2) { Log.Warning("Data table name is invalid."); return; } string dataRowClassName = DataRowClassPrefixName + splitedNames[0]; Type dataRowType = Type.GetType(dataRowClassName); if (dataRowType == null) { Log.Warning("Can not get data row type with class name '{0}'.", dataRowClassName); return; } string name = splitedNames.Length > 1 ? splitedNames[1] : null; DataTableBase dataTable = dataTableComponent.CreateDataTable(dataRowType, name); dataTable.ReadData(dataTableAssetName, Constant.AssetPriority.DataTableAsset, userData); }
private void OnLoadDataTableSuccess(object sender, GameEventArgs e) { // 获取框架数据表组件 DataTableComponent DataTable = UnityGameFramework.Runtime.GameEntry.GetComponent <DataTableComponent>(); // 获得数据表 IDataTable <DRheros> dtScene = DataTable.GetDataTable <DRheros>(); // 获得所有行 DRheros[] drHeros = dtScene.GetAllDataRows(); Log.Debug("drHeros:" + drHeros.Length); // 根据行号获得某一行 DRheros drScene = dtScene.GetDataRow(1); // 或直接使用 dtScene[1] if (drScene != null) { // 此行存在,可以获取内容了 string name = drScene.Name; int atk = drScene.Atk; Log.Debug("name:" + name + ", atk:" + atk); } else { // 此行不存在 } // 获得满足条件的所有行 DRheros[] drScenesWithCondition = dtScene.GetDataRows(x => x.Id > 0); // 获得满足条件的第一行 DRheros drSceneWithCondition = dtScene.GetDataRow(x => x.Name == "mutou"); }
public void OnRegistClick() { // 获取框架数据表组件 DataTableComponent DataTable = GameEntry.GetComponent <DataTableComponent>(); // 加载配置表 DataTable.LoadDataTable <ConfigHero>("Hero", mConfigName, this); }
protected override void OnEnter(IFsm <IProcedureManager> procedureOwner) { base.OnEnter(procedureOwner); Event = GameEntry.GetComponent <EventComponent>(); DataTable = GameEntry.GetComponent <DataTableComponent>(); Event.Subscribe(LoadDataTableSuccessEventArgs.EventId, OnLoadDataTableSuccess); Event.Subscribe(LoadDataTableFailureEventArgs.EventId, OnLoadDataTableFailure); PreloadResources(); }
public void LoadConfigs() { _event.Subscribe(UnityGameFramework.Runtime.LoadDataTableSuccessEventArgs.EventId, LoadDataSetSuccessAction); _event.Subscribe(UnityGameFramework.Runtime.LoadDataTableFailureEventArgs.EventId, (sender, e) => { Debug.Log(e.Id); }); _data = GameEntry.GetComponent <DataTableComponent>(); _data.LoadDataTable <ModelConfig>("ModelConfig.txt", _configPath + "ModelConfig.txt"); _data.LoadDataTable <FormConfig>("FormConfig.txt", _configPath + "FormConfig.txt"); _data.LoadDataTable <NameConfig>("NameConfig.txt", _configPath + "NameConfig.txt"); _data.LoadDataTable <BanedTextConfig>("BanedTextConfig.txt", _configPath + "BanedTextConfig.txt"); }
protected override void OnEnter(ProcedureOwner procedureOwner) { base.OnEnter(procedureOwner); //获取框架事件组件 EventComponent Event = GameEntry.GetComponent <EventComponent>(); //获取框架数据表组件 DataTableComponent DataTable = GameEntry.GetComponent <DataTableComponent>(); //订阅数据表加载成功事件 Event.Subscribe(UnityGameFramework.Runtime.LoadDataTableSuccessEventArgs.EventId, OnLoadDataTableSuccess); DataTable.LoadDataTable <DRHero>("Hero", "Assets/Demo4_DataTable/Hero2.txt"); }
public static T GetDataTableRow <T>(this DataTableComponent dataTableComponent, int id) where T : IDataRow { IDataTable <T> dt = GameEntry.DataTable.GetDataTable <T>(); T dr = dt.GetDataRow(id); if (dr == null) { Log.Warning("Can not load id '{0}' from data table '{1}'.", id.ToString(), typeof(T).Name); return(default(T)); } return(dr); }
/// <summary> /// 重新加载已加载的数据表 /// </summary> public static void ReloadDataTable(this DataTableComponent dataTableComponent) { DataTableBase[] allLoadedDataTables = dataTableComponent.GetAllDataTables(); for (int i = 0; i < allLoadedDataTables.Length; i++) { Type dataTableType = allLoadedDataTables[i].Type; if (dataTableComponent.DestroyDataTable(dataTableType)) { string reloadTableName = dataTableType.ToString().Replace(DataRowClassPrefixName, ""); dataTableComponent.LoadDataTable(reloadTableName); Log.Info("Reload DataTable:[{0}] success", reloadTableName); } } }
protected internal override void OnEnter(IFsm <IProcedureManager> procedureOwner) { base.OnEnter(procedureOwner); // 获取框架事件组件 EventComponent Event = UnityGameFramework.Runtime.GameEntry.GetComponent <EventComponent>(); // 获取框架数据表组件 DataTableComponent DataTable = UnityGameFramework.Runtime.GameEntry.GetComponent <DataTableComponent>(); // 订阅加载成功事件 Event.Subscribe(UnityGameFramework.Runtime.LoadDataTableSuccessEventArgs.EventId, OnLoadDataTableSuccess); // 加载配置表 DataTable.LoadDataTable <DRheros>("Hero", "Assets/Demo/DataTable/heros.txt", GameFramework.LoadType.Text); }
private void Start() { m_DataTableComponent = GameEntry.GetComponent <DataTableComponent>(); if (m_DataTableComponent == null) { Log.Fatal("Data table component is invalid."); return; } m_ResourceComponent = GameEntry.GetComponent <ResourceComponent>(); if (m_ResourceComponent == null) { Log.Fatal("Resource component is invalid."); return; } }
public void InitComponent(Transform componentRoot) { this.ComponentRoot = componentRoot; DataNodeComponent = FindAndRegisterComponent <DataNodeComponent>(); DataTableComponent = FindAndRegisterComponent <DataTableComponent>(); DownloadComponent = FindAndRegisterComponent <DownloadComponent>(); FsmComponent = FindAndRegisterComponent <FSMComponent>(); ResourceComponent = FindAndRegisterComponent <ResourceComponent>(); SettingComponent = FindAndRegisterComponent <SettingComponent>(); SoundComponent = FindAndRegisterComponent <SoundComponent>(); TimerComponent = FindAndRegisterComponent <TimerComponent>(); WebComponent = FindAndRegisterComponent <WebComponent>(); UpdateComponent = FindAndRegisterComponent <UpdateComponent>(); LocalizationComponent = FindAndRegisterComponent <LocalizationComponent>(); VideoComponent = FindAndRegisterComponent <VideoComponent>(); InputComponent = FindAndRegisterComponent <InputComponent>(); SceneComponent = FindAndRegisterComponent <SceneComponent>(); }
public int PlayUISound(int uiSoundId, object userData = null) { DataTableComponent dataTableComponent = UnityGameFramework.Runtime.GameEntry.GetComponent <DataTableComponent>(); IDataTable <DRUISound> dtUISound = dataTableComponent.GetDataTable <DRUISound>(); DRUISound drUISound = dtUISound.GetDataRow(uiSoundId); if (drUISound == null) { Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString()); return(-1); } PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Priority = drUISound.Priority; playSoundParams.Loop = false; playSoundParams.VolumeInSoundGroup = drUISound.Volume; playSoundParams.SpatialBlend = 0f; return(soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", Demo15.Constant.AssetPriority.UISoundAsset, playSoundParams, userData)); }
/// <summary> /// 获取一行数据 /// </summary> /// <param name="id">数据表行的编号</param> /// <typeparam name="T">数据表类型</typeparam> /// <returns></returns> public static T GetDataRow <T>(this DataTableComponent dataTableComponent, int id) where T : IDataRow { IDataTable <T> dt = dataTableComponent.GetDataTable <T> (); return(dt.GetDataRow(id)); }
public static T GetDataRow <T>(this DataTableComponent dataTableComponent, Predicate <T> condition) where T : IDataRow { IDataTable <T> dt = GameEntry.DataTable.GetDataTable <T>(); return(dt.GetDataRow(condition)); }
/// <summary> /// 获取数据表行 /// </summary> /// <param name="typeId">数据表行的编号</param> /// <typeparam name="T">数据表类型</typeparam> /// <returns></returns> public static T GetDataRow <T>(this DataTableComponent dataTableComponent, int typeId) where T : IDataRow { IDataTable <T> dt = GameEntry.DataTable.GetDataTable <T> (); return(dt.GetDataRow(typeId)); }