private void LoadBinarySuccessCallback(string configAssetName, byte[] configBytes, float duration, object userData) { try { if (!m_ConfigHelper.LoadConfig(configAssetName, configBytes, 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, duration, 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; } }
private void LoadConfigSuccessCallback(string configAssetName, object configAsset, float duration, object userData) { LoadConfigInfo loadConfigInfo = (LoadConfigInfo)userData; if (loadConfigInfo == null) { throw new GameFrameworkException("Load config info is invalid."); } try { if (!m_ConfigHelper.LoadConfig(configAsset, loadConfigInfo.LoadType, loadConfigInfo.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, loadConfigInfo.LoadType, duration, loadConfigInfo.UserData); m_LoadConfigSuccessEventHandler(this, loadConfigSuccessEventArgs); ReferencePool.Release(loadConfigSuccessEventArgs); } } catch (Exception exception) { if (m_LoadConfigFailureEventHandler != null) { LoadConfigFailureEventArgs loadConfigFailureEventArgs = LoadConfigFailureEventArgs.Create(configAssetName, loadConfigInfo.LoadType, exception.ToString(), loadConfigInfo.UserData); m_LoadConfigFailureEventHandler(this, loadConfigFailureEventArgs); ReferencePool.Release(loadConfigFailureEventArgs); return; } throw; } finally { ReferencePool.Release(loadConfigInfo); m_ConfigHelper.ReleaseConfigAsset(configAsset); } }
/// <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())); } }