/// <summary> /// 异步加载二进制资源。 /// </summary> /// <param name="binaryAssetName">要加载二进制资源的名称。</param> /// <param name="loadBinaryCallbacks">加载二进制资源回调函数集。</param> /// <param name="userData">用户自定义数据。</param> public void LoadBinary(string binaryAssetName, LoadBinaryCallbacks loadBinaryCallbacks, object userData) { ResourceInfo?resourceInfo = null; string[] dependencyAssetNames = null; if (!CheckAsset(binaryAssetName, out resourceInfo, out dependencyAssetNames)) { string errorMessage = Utility.Text.Format("Can not load binary '{0}'.", binaryAssetName); if (loadBinaryCallbacks.LoadBinaryFailureCallback != null) { loadBinaryCallbacks.LoadBinaryFailureCallback(binaryAssetName, LoadResourceStatus.NotReady, errorMessage, userData); return; } throw new GameFrameworkException(errorMessage); } if (!IsLoadFromBinary(resourceInfo.Value.LoadType)) { string errorMessage = Utility.Text.Format("Can not load binary asset '{0}' which is not a binary asset.", binaryAssetName); if (loadBinaryCallbacks.LoadBinaryFailureCallback != null) { loadBinaryCallbacks.LoadBinaryFailureCallback(binaryAssetName, LoadResourceStatus.TypeError, errorMessage, userData); return; } throw new GameFrameworkException(errorMessage); } string path = Utility.Path.GetRemotePath(Path.Combine(resourceInfo.Value.StorageInReadOnly ? m_ResourceManager.m_ReadOnlyPath : m_ResourceManager.m_ReadWritePath, resourceInfo.Value.ResourceName.FullName)); m_ResourceManager.m_ResourceHelper.LoadBytes(path, m_LoadBytesCallbacks, LoadBinaryInfo.Create(binaryAssetName, resourceInfo.Value, loadBinaryCallbacks, userData)); }
/// <summary> /// 异步加载二进制资源。 /// </summary> /// <param name="binaryAssetName">要加载二进制资源的名称。</param> /// <param name="loadBinaryCallbacks">加载二进制资源回调函数集。</param> /// <param name="userData">用户自定义数据。</param> public void LoadBinary(string binaryAssetName, LoadBinaryCallbacks loadBinaryCallbacks, object userData) { ResourceInfo resourceInfo = GetResourceInfo(binaryAssetName); if (resourceInfo == null) { string errorMessage = Utility.Text.Format("Can not load binary '{0}' which is not exist.", binaryAssetName); if (loadBinaryCallbacks.LoadBinaryFailureCallback != null) { loadBinaryCallbacks.LoadBinaryFailureCallback(binaryAssetName, LoadResourceStatus.NotExist, errorMessage, userData); return; } throw new GameFrameworkException(errorMessage); } if (!resourceInfo.Ready) { string errorMessage = Utility.Text.Format("Can not load binary '{0}' which is not ready.", binaryAssetName); if (loadBinaryCallbacks.LoadBinaryFailureCallback != null) { loadBinaryCallbacks.LoadBinaryFailureCallback(binaryAssetName, LoadResourceStatus.NotReady, errorMessage, userData); return; } throw new GameFrameworkException(errorMessage); } if (!resourceInfo.IsLoadFromBinary) { string errorMessage = Utility.Text.Format("Can not load binary '{0}' which is not a binary asset.", binaryAssetName); if (loadBinaryCallbacks.LoadBinaryFailureCallback != null) { loadBinaryCallbacks.LoadBinaryFailureCallback(binaryAssetName, LoadResourceStatus.TypeError, errorMessage, userData); return; } throw new GameFrameworkException(errorMessage); } if (resourceInfo.UseFileSystem) { loadBinaryCallbacks.LoadBinarySuccessCallback(binaryAssetName, LoadBinaryFromFileSystem(binaryAssetName), 0f, userData); } else { string path = Utility.Path.GetRemotePath(Path.Combine(resourceInfo.StorageInReadOnly ? m_ResourceManager.m_ReadOnlyPath : m_ResourceManager.m_ReadWritePath, resourceInfo.ResourceName.FullName)); m_ResourceManager.m_ResourceHelper.LoadBytes(path, m_LoadBytesCallbacks, LoadBinaryInfo.Create(binaryAssetName, resourceInfo, loadBinaryCallbacks, userData)); } }