update runtime code

移除了ILocationServices接口类。
增加了bool CheckLocationValid(string location)方法。
pull/51/head
hevinci 2022-10-21 18:36:03 +08:00
parent d7760cd34d
commit bb64ff7278
16 changed files with 70 additions and 148 deletions

View File

@ -142,6 +142,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load scene. {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SceneOperationHandle>();
@ -190,6 +191,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load asset. {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<AssetOperationHandle>();
@ -216,6 +218,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load sub assets. {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();

View File

@ -13,7 +13,6 @@ namespace YooAsset
private EOperationStatus _initializeStatus = EOperationStatus.None;
private EPlayMode _playMode;
private IBundleServices _bundleServices;
private ILocationServices _locationServices;
private AssetSystemImpl _assetSystemImpl;
private EditorSimulateModeImpl _editorSimulateModeImpl;
private OfflinePlayModeImpl _offlinePlayModeImpl;
@ -33,7 +32,7 @@ namespace YooAsset
}
internal AssetsPackage()
private AssetsPackage()
{
}
internal AssetsPackage(string packageName)
@ -62,7 +61,6 @@ namespace YooAsset
_initializeStatus = EOperationStatus.None;
_bundleServices = null;
_locationServices = null;
_editorSimulateModeImpl = null;
_offlinePlayModeImpl = null;
_hostPlayModeImpl = null;
@ -72,8 +70,6 @@ namespace YooAsset
_assetSystemImpl.DestroyAll();
_assetSystemImpl = null;
}
YooLogger.Log("YooAssets destroy all !");
}
}
@ -87,7 +83,6 @@ namespace YooAsset
// 初始化资源系统
InitializationOperation initializeOperation;
_locationServices = parameters.LocationServices;
_assetSystemImpl = new AssetSystemImpl();
if (_playMode == EPlayMode.EditorSimulateMode)
{
@ -143,9 +138,6 @@ namespace YooAsset
throw new Exception($"Editor simulate mode only support unity editor.");
#endif
if (parameters.LocationServices == null)
throw new Exception($"{nameof(ILocationServices)} is null.");
if (parameters is EditorSimulateModeParameters)
{
var editorSimulateModeParameters = parameters as EditorSimulateModeParameters;
@ -335,7 +327,10 @@ namespace YooAsset
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
@ -397,14 +392,14 @@ namespace YooAsset
}
/// <summary>
/// 获取资源路径
/// 检查资源定位地址是否有效
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <returns>如果location地址无效则返回空字符串</returns>
public string GetAssetPath(string location)
public bool CheckLocationValid(string location)
{
DebugCheckInitialize();
return _locationServices.ConvertLocationToAssetPath(this, location);
string assetPath = _bundleServices.TryMappingToAssetPath(location);
return string.IsNullOrEmpty(assetPath) == false;
}
#endregion
@ -429,8 +424,6 @@ namespace YooAsset
public RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
YooLogger.Warning(assetInfo.Error);
return GetRawFileInternal(assetInfo, copyPath);
}
@ -439,6 +432,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to get raw file. {assetInfo.Error}");
RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath);
OperationSystem.StartOperation(operation);
return operation;
@ -508,8 +502,6 @@ namespace YooAsset
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
YooLogger.Warning(assetInfo.Error);
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
return handle;
}
@ -523,8 +515,6 @@ namespace YooAsset
public AssetOperationHandle LoadAssetSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
YooLogger.Warning(assetInfo.Error);
return LoadAssetInternal(assetInfo, true);
}
@ -560,8 +550,6 @@ namespace YooAsset
public AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
YooLogger.Warning(assetInfo.Error);
return LoadAssetInternal(assetInfo, false);
}
@ -593,14 +581,17 @@ namespace YooAsset
private AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{
#if UNITY_EDITOR
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
if (assetInfo.IsInvalid == false)
{
string error = $"Cannot load raw file using LoadAsset method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<AssetOperationHandle>();
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
{
string error = $"Cannot load raw file using LoadAsset method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<AssetOperationHandle>();
}
}
#endif
@ -619,8 +610,6 @@ namespace YooAsset
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
YooLogger.Warning(assetInfo.Error);
return LoadSubAssetsInternal(assetInfo, true);
}
@ -656,8 +645,6 @@ namespace YooAsset
public SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
YooLogger.Warning(assetInfo.Error);
return LoadSubAssetsInternal(assetInfo, false);
}
@ -689,14 +676,17 @@ namespace YooAsset
private SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{
#if UNITY_EDITOR
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
if (assetInfo.IsInvalid == false)
{
string error = $"Cannot load raw file using LoadSubAssets method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
{
string error = $"Cannot load raw file using LoadSubAssets method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
}
}
#endif
@ -940,14 +930,6 @@ namespace YooAsset
#endregion
#region 内部方法
/// <summary>
/// 资源定位地址转换为资源完整路径
/// </summary>
internal string MappingToAssetPath(string location)
{
return _bundleServices.MappingToAssetPath(location);
}
/// <summary>
/// 是否包含资源文件
/// </summary>
@ -1014,7 +996,7 @@ namespace YooAsset
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
DebugCheckLocation(location);
string assetPath = _locationServices.ConvertLocationToAssetPath(this, location);
string assetPath = _bundleServices.MappingToAssetPath(location);
PatchAsset patchAsset = _bundleServices.TryGetPatchAsset(assetPath);
if (patchAsset != null)
{
@ -1028,7 +1010,6 @@ namespace YooAsset
error = $"The location is null or empty !";
else
error = $"The location is invalid : {location}";
YooLogger.Error(error);
AssetInfo assetInfo = new AssetInfo(error);
return assetInfo;
}

View File

@ -33,11 +33,6 @@ namespace YooAsset
/// </summary>
public bool LocationToLower = false;
/// <summary>
/// 资源定位服务接口
/// </summary>
public ILocationServices LocationServices = null;
/// <summary>
/// 文件解密服务接口
/// </summary>

View File

@ -147,6 +147,23 @@ namespace YooAsset
}
}
/// <summary>
/// 尝试映射为资源路径
/// </summary>
public string TryMappingToAssetPath(string location)
{
if (string.IsNullOrEmpty(location))
return string.Empty;
if (_locationToLower)
location = location.ToLower();
if (AssetPathMapping.TryGetValue(location, out string assetPath))
return assetPath;
else
return string.Empty;
}
/// <summary>
/// 获取主资源包
/// 注意:传入的资源路径一定合法有效!

View File

@ -66,6 +66,10 @@ namespace YooAsset
{
return _simulatePatchManifest.MappingToAssetPath(location);
}
string IBundleServices.TryMappingToAssetPath(string location)
{
return _simulatePatchManifest.TryMappingToAssetPath(location);
}
string IBundleServices.GetPackageName()
{
return _simulatePatchManifest.PackageName;

View File

@ -392,6 +392,10 @@ namespace YooAsset
{
return LocalPatchManifest.MappingToAssetPath(location);
}
string IBundleServices.TryMappingToAssetPath(string location)
{
return LocalPatchManifest.TryMappingToAssetPath(location);
}
string IBundleServices.GetPackageName()
{
return LocalPatchManifest.PackageName;

View File

@ -117,6 +117,10 @@ namespace YooAsset
{
return _appPatchManifest.MappingToAssetPath(location);
}
string IBundleServices.TryMappingToAssetPath(string location)
{
return _appPatchManifest.TryMappingToAssetPath(location);
}
string IBundleServices.GetPackageName()
{
return _appPatchManifest.PackageName;

View File

@ -28,6 +28,11 @@ namespace YooAsset
/// </summary>
string MappingToAssetPath(string location);
/// <summary>
/// 尝试映射为资源路径
/// </summary>
string TryMappingToAssetPath(string location);
/// <summary>
/// 获取所属的包裹名
/// </summary>

View File

@ -1,11 +0,0 @@

namespace YooAsset
{
public interface ILocationServices
{
/// <summary>
/// 定位地址转换为资源路径
/// </summary>
string ConvertLocationToAssetPath(AssetsPackage package, string location);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: cfc81e18e5b5f6f4b821c7427b34d349
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 6e400ee1e8b3556479bfa493ff7fe778
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,11 +0,0 @@

namespace YooAsset
{
public class AddressLocationServices : ILocationServices
{
string ILocationServices.ConvertLocationToAssetPath(AssetsPackage package, string location)
{
return package.MappingToAssetPath(location);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a8d6592eded144142afcf85c79cf1ce4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,27 +0,0 @@

namespace YooAsset
{
public class DefaultLocationServices : ILocationServices
{
private readonly string _resourceRoot;
public DefaultLocationServices(string resourceRoot)
{
if (string.IsNullOrEmpty(resourceRoot) == false)
_resourceRoot = PathHelper.GetRegularPath(resourceRoot);
}
string ILocationServices.ConvertLocationToAssetPath(AssetsPackage package, string location)
{
if (string.IsNullOrEmpty(_resourceRoot))
{
return package.MappingToAssetPath(location);
}
else
{
string tempLocation = $"{_resourceRoot}/{location}";
return package.MappingToAssetPath(tempLocation);
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8d996937ba73c9b4bb942b8ba6f43398
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -70,14 +70,13 @@ namespace YooAsset
}
/// <summary>
/// 获取资源路径
/// 检查资源定位地址是否有效
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <returns>如果location地址无效则返回空字符串</returns>
public static string GetAssetPath(string location)
public static bool CheckLocationValid(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetPath(location);
return _defaultPackage.CheckLocationValid(location);
}
#endregion