private void UpdateUnityWebRequest() { if (m_UnityWebRequest != null) { if (m_UnityWebRequest.isDone) { if (string.IsNullOrEmpty(m_UnityWebRequest.error)) { InnerLoadResourceAgentHelperReadBytesCompleteEventArgs loadResourceAgentHelperReadBytesCompleteEventArgs = InnerLoadResourceAgentHelperReadBytesCompleteEventArgs.Create(m_UnityWebRequest.downloadHandler.data); m_LoadResourceAgentHelperReadBytesCompleteEventHandler(this, loadResourceAgentHelperReadBytesCompleteEventArgs); ReferencePool.Release(loadResourceAgentHelperReadBytesCompleteEventArgs); m_UnityWebRequest.Dispose(); m_UnityWebRequest = null; m_BytesFullPath = null; m_LastProgress = 0f; } else { bool isError = false; isError = m_UnityWebRequest.isNetworkError || m_UnityWebRequest.isHttpError; InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.NotExist, DBD.Utility.Text.Format("Can not load asset bundle '{0}' with error message '{1}'.", m_BytesFullPath, isError ? m_UnityWebRequest.error : null)); m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs); ReferencePool.Release(loadResourceAgentHelperErrorEventArgs); } } else if (m_UnityWebRequest.downloadProgress != m_LastProgress) { m_LastProgress = m_UnityWebRequest.downloadProgress; InnerLoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = InnerLoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.ReadResource, m_UnityWebRequest.downloadProgress); m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs); ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs); } } }
/// <summary> /// 通过加载资源代理辅助器开始异步读取资源二进制流。 /// </summary> /// <param name="fileSystem">要加载资源的文件系统。</param> /// <param name="name">要加载资源的名称。</param> public override void ReadBytes(IFileSystem fileSystem, string name) { if (m_LoadResourceAgentHelperReadBytesCompleteEventHandler == null || m_LoadResourceAgentHelperUpdateEventHandler == null || m_LoadResourceAgentHelperErrorEventHandler == null) { Log.Fatal("Load resource agent helper handler is invalid."); return; } byte[] bytes = fileSystem.ReadFile(name); InnerLoadResourceAgentHelperReadBytesCompleteEventArgs loadResourceAgentHelperReadBytesCompleteEventArgs = InnerLoadResourceAgentHelperReadBytesCompleteEventArgs.Create(bytes); m_LoadResourceAgentHelperReadBytesCompleteEventHandler(this, loadResourceAgentHelperReadBytesCompleteEventArgs); ReferencePool.Release(loadResourceAgentHelperReadBytesCompleteEventArgs); }