/// <summary> /// 加载全局配置。 /// </summary> /// <param name="configAssetName">全局配置资源名称。</param> /// <param name="priority">加载全局配置资源的优先级。</param> /// <param name="userData">用户自定义数据。</param> public void LoadConfig(string configAssetName, int priority, object userData) { if (m_ResourceManager == null) { throw new GameFrameworkException("You must set resource manager first."); } if (m_ConfigHelper == null) { throw new GameFrameworkException("You must set config helper first."); } HasAssetResult result = m_ResourceManager.HasAsset(configAssetName); switch (result) { case HasAssetResult.AssetOnDisk: case HasAssetResult.AssetOnFileSystem: m_ResourceManager.LoadAsset(configAssetName, priority, m_LoadAssetCallbacks, userData); break; case HasAssetResult.BinaryOnDisk: m_ResourceManager.LoadBinary(configAssetName, m_LoadBinaryCallbacks, userData); break; case HasAssetResult.BinaryOnFileSystem: int configLength = m_ResourceManager.GetBinaryLength(configAssetName); byte[] configBytes = GlobalBytes.Get(configLength); if (configLength != m_ResourceManager.LoadBinaryFromFileSystem(configAssetName, configBytes)) { throw new GameFrameworkException(Utility.Text.Format("Load binary '{0}' from file system internal error.", configAssetName)); } try { if (!m_ConfigHelper.LoadConfig(configAssetName, configBytes, 0, configLength, userData)) { throw new GameFrameworkException(Utility.Text.Format("Load config failure in helper, asset name '{0}'.", configAssetName)); } if (m_LoadConfigSuccessEventHandler != null) { LoadConfigSuccessEventArgs loadConfigSuccessEventArgs = LoadConfigSuccessEventArgs.Create(configAssetName, 0f, userData); m_LoadConfigSuccessEventHandler(this, loadConfigSuccessEventArgs); ReferencePool.Release(loadConfigSuccessEventArgs); } } catch (Exception exception) { if (m_LoadConfigFailureEventHandler != null) { LoadConfigFailureEventArgs loadConfigFailureEventArgs = LoadConfigFailureEventArgs.Create(configAssetName, exception.ToString(), userData); m_LoadConfigFailureEventHandler(this, loadConfigFailureEventArgs); ReferencePool.Release(loadConfigFailureEventArgs); return; } throw; } break; default: throw new GameFrameworkException(Utility.Text.Format("Config asset '{0}' is '{1}'.", configAssetName, result.ToString())); } }
/// <summary> /// 加载数据表。 /// </summary> /// <param name="dataTableAssetName">数据表资源名称。</param> /// <param name="priority">加载数据表资源的优先级。</param> /// <param name="userData">用户自定义数据。</param> public void LoadDataTable(string dataTableAssetName, int priority, object userData) { if (m_ResourceManager == null) { throw new GameFrameworkException("You must set resource manager first."); } if (m_DataTableHelper == null) { throw new GameFrameworkException("You must set data table helper first."); } HasAssetResult result = m_ResourceManager.HasAsset(dataTableAssetName); switch (result) { case HasAssetResult.Asset: m_ResourceManager.LoadAsset(dataTableAssetName, priority, m_LoadAssetCallbacks, userData); break; case HasAssetResult.Binary: m_ResourceManager.LoadBinary(dataTableAssetName, m_LoadBinaryCallbacks, userData); break; default: throw new GameFrameworkException(Utility.Text.Format("Data table asset '{0}' is '{1}'.", dataTableAssetName, result.ToString())); } }
/// <summary> /// 读取数据。 /// </summary> /// <param name="dataAssetName">内容资源名称。</param> /// <param name="priority">加载数据资源的优先级。</param> /// <param name="userData">用户自定义数据。</param> public void ReadData(string dataAssetName, int priority, object userData, AssetCategory assetCategory) { if (m_ResourceManager == null) { throw new Exception("You must set resource manager first."); } if (m_DataProviderHelper == null) { throw new Exception("You must set data provider helper first."); } HasAssetResult result = m_ResourceManager.HasAsset(dataAssetName, assetCategory); switch (result) { case HasAssetResult.AssetOnDisk: case HasAssetResult.AssetOnFileSystem: m_ResourceManager.LoadAsset(dataAssetName, assetCategory, m_LoadAssetCallbacks, null, priority, userData); break; case HasAssetResult.BinaryOnDisk: m_ResourceManager.LoadBinary(dataAssetName, m_LoadBinaryCallbacks, userData); break; case HasAssetResult.BinaryOnFileSystem: int dataLength = m_ResourceManager.GetBinaryLength(dataAssetName); EnsureCachedBytesSize(dataLength); if (dataLength != m_ResourceManager.LoadBinaryFromFileSystem(dataAssetName, s_CachedBytes)) { throw new Exception(Utility.Text.Format("Load binary '{0}' from file system with internal error.", dataAssetName)); } try { if (!m_DataProviderHelper.ReadData(m_Owner, dataAssetName, s_CachedBytes, 0, dataLength, userData)) { throw new Exception(Utility.Text.Format("Load data failure in data provider helper, data asset name '{0}'.", dataAssetName)); } //if (m_ReadDataSuccessEventHandler != null) //{ // ReadDataSuccessEventArgs loadDataSuccessEventArgs = ReadDataSuccessEventArgs.Create(dataAssetName, 0f, userData); // m_ReadDataSuccessEventHandler(this, loadDataSuccessEventArgs); // ReferencePool.Release(loadDataSuccessEventArgs); //} } catch (Exception exception) { Log.Error(dataAssetName, exception.ToString()); throw; } break; default: throw new Exception(Utility.Text.Format("Data asset '{0}' is '{1}'.", dataAssetName, result.ToString())); } }