parent
2ab045658b
commit
c395a7a750
|
@ -44,7 +44,7 @@ namespace YooAsset
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Dry run build failed, see the detail info on the console window.";
|
||||
Error = "Simulate build failed, see the detail info on the console window.";
|
||||
return;
|
||||
}
|
||||
if (File.Exists(manifestFilePath) == false)
|
||||
|
@ -55,9 +55,10 @@ namespace YooAsset
|
|||
return;
|
||||
}
|
||||
|
||||
YooLogger.Log($"Load manifest file in editor play mode : {manifestFilePath}");
|
||||
YooLogger.Log($"Load manifest file : {manifestFilePath}");
|
||||
string jsonContent = FileUtility.ReadFile(manifestFilePath);
|
||||
_impl.AppPatchManifest = PatchManifest.Deserialize(jsonContent);
|
||||
var simulatePatchManifest = PatchManifest.Deserialize(jsonContent);
|
||||
_impl.SetSimulatePatchManifest(simulatePatchManifest);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
@ -109,7 +110,7 @@ namespace YooAsset
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
_impl.AppPatchManifest = _appManifestLoader.Result;
|
||||
_impl.SetAppPatchManifest(_appManifestLoader.Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,8 +183,8 @@ namespace YooAsset
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
_impl.AppPatchManifest = _appManifestLoader.Result;
|
||||
_impl.LocalPatchManifest = _appManifestLoader.Result;
|
||||
_impl.SetAppPatchManifest(_appManifestLoader.Result);
|
||||
_impl.SetLocalPatchManifest(_appManifestLoader.Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,8 @@ namespace YooAsset
|
|||
{
|
||||
try
|
||||
{
|
||||
_impl.LocalPatchManifest = PatchManifest.Deserialize(content);
|
||||
var remotePatchManifest = PatchManifest.Deserialize(content);
|
||||
_impl.SetLocalPatchManifest(remotePatchManifest);
|
||||
|
||||
YooLogger.Log("Save remote patch manifest file.");
|
||||
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
|
@ -223,7 +224,8 @@ namespace YooAsset
|
|||
YooLogger.Log("Load sandbox patch manifest file.");
|
||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
string jsonData = File.ReadAllText(filePath);
|
||||
_impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData);
|
||||
var sandboxPatchManifest = PatchManifest.Deserialize(jsonData);
|
||||
_impl.SetLocalPatchManifest(sandboxPatchManifest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -56,6 +56,10 @@ namespace YooAsset
|
|||
[NonSerialized]
|
||||
public readonly Dictionary<string, string> AssetPathMapping = new Dictionary<string, string>();
|
||||
|
||||
// 资源路径映射相关
|
||||
private bool _isInitAssetPathMapping = false;
|
||||
private bool _locationToLower = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置资源标签列表
|
||||
|
@ -141,11 +145,65 @@ namespace YooAsset
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源路径映射
|
||||
/// </summary>
|
||||
public void InitAssetPathMapping(bool locationToLower)
|
||||
{
|
||||
if (_isInitAssetPathMapping)
|
||||
return;
|
||||
_isInitAssetPathMapping = true;
|
||||
|
||||
if (EnableAddressable)
|
||||
{
|
||||
if (locationToLower)
|
||||
YooLogger.Warning("Addressable not support location to lower !");
|
||||
|
||||
foreach (var patchAsset in AssetList)
|
||||
{
|
||||
string location = patchAsset.Address;
|
||||
if (AssetPathMapping.ContainsKey(location))
|
||||
throw new Exception($"Address have existed : {location}");
|
||||
else
|
||||
AssetPathMapping.Add(location, patchAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_locationToLower = locationToLower;
|
||||
foreach (var patchAsset in AssetList)
|
||||
{
|
||||
string location = patchAsset.AssetPath;
|
||||
if (locationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (AssetPathMapping.ContainsKey(location))
|
||||
throw new Exception($"AssetPath have existed : {location}");
|
||||
else
|
||||
AssetPathMapping.Add(location, patchAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (Path.HasExtension(location))
|
||||
{
|
||||
string locationWithoutExtension = StringUtility.RemoveExtension(location);
|
||||
if (AssetPathMapping.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}");
|
||||
else
|
||||
AssetPathMapping.Add(locationWithoutExtension, patchAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 映射为资源路径
|
||||
/// </summary>
|
||||
public string MappingToAssetPath(string location)
|
||||
{
|
||||
if (_locationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
if (AssetPathMapping.TryGetValue(location, out string assetPath))
|
||||
{
|
||||
return assetPath;
|
||||
|
@ -192,42 +250,6 @@ namespace YooAsset
|
|||
patchManifest.Assets.Add(assetPath, patchAsset);
|
||||
}
|
||||
|
||||
// AssetPathMapping
|
||||
if (patchManifest.EnableAddressable)
|
||||
{
|
||||
foreach (var patchAsset in patchManifest.AssetList)
|
||||
{
|
||||
string address = patchAsset.Address;
|
||||
if (patchManifest.AssetPathMapping.ContainsKey(address))
|
||||
throw new Exception($"Address have existed : {address}");
|
||||
else
|
||||
patchManifest.AssetPathMapping.Add(address, patchAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var patchAsset in patchManifest.AssetList)
|
||||
{
|
||||
string assetPath = patchAsset.AssetPath;
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (patchManifest.AssetPathMapping.ContainsKey(assetPath))
|
||||
throw new Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
patchManifest.AssetPathMapping.Add(assetPath, assetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (Path.HasExtension(assetPath))
|
||||
{
|
||||
string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath);
|
||||
if (patchManifest.AssetPathMapping.ContainsKey(assetPathWithoutExtension))
|
||||
YooLogger.Warning($"AssetPath have existed : {assetPathWithoutExtension}");
|
||||
else
|
||||
patchManifest.AssetPathMapping.Add(assetPathWithoutExtension, assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return patchManifest;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,15 @@ namespace YooAsset
|
|||
{
|
||||
internal class EditorSimulateModeImpl : IBundleServices
|
||||
{
|
||||
internal PatchManifest AppPatchManifest;
|
||||
private PatchManifest _simulatePatchManifest;
|
||||
private bool _locationToLower;
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync()
|
||||
public InitializationOperation InitializeAsync(bool locationToLower)
|
||||
{
|
||||
_locationToLower = locationToLower;
|
||||
var operation = new EditorSimulateModeInitializationOperation(this);
|
||||
OperationSystem.ProcessOperaiton(operation);
|
||||
return operation;
|
||||
|
@ -23,9 +25,16 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public int GetResourceVersion()
|
||||
{
|
||||
if (AppPatchManifest == null)
|
||||
if (_simulatePatchManifest == null)
|
||||
return 0;
|
||||
return AppPatchManifest.ResourceVersion;
|
||||
return _simulatePatchManifest.ResourceVersion;
|
||||
}
|
||||
|
||||
// 设置资源清单
|
||||
internal void SetSimulatePatchManifest(PatchManifest patchManifest)
|
||||
{
|
||||
_simulatePatchManifest = patchManifest;
|
||||
_simulatePatchManifest.InitAssetPathMapping(_locationToLower);
|
||||
}
|
||||
|
||||
#region IBundleServices接口
|
||||
|
@ -34,9 +43,9 @@ namespace YooAsset
|
|||
if (string.IsNullOrEmpty(bundleName))
|
||||
return new BundleInfo(string.Empty);
|
||||
|
||||
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
||||
if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
||||
{
|
||||
string mainAssetPath = AppPatchManifest.TryGetBundleMainAssetPath(bundleName);
|
||||
string mainAssetPath = _simulatePatchManifest.TryGetBundleMainAssetPath(bundleName);
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, mainAssetPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
@ -49,19 +58,19 @@ namespace YooAsset
|
|||
}
|
||||
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
||||
{
|
||||
return PatchHelper.GetAssetsInfoByTag(AppPatchManifest, tags);
|
||||
return PatchHelper.GetAssetsInfoByTag(_simulatePatchManifest, tags);
|
||||
}
|
||||
string IBundleServices.MappingToAssetPath(string location)
|
||||
{
|
||||
return AppPatchManifest.MappingToAssetPath(location);
|
||||
return _simulatePatchManifest.MappingToAssetPath(location);
|
||||
}
|
||||
string IBundleServices.GetBundleName(string assetPath)
|
||||
{
|
||||
return AppPatchManifest.GetBundleName(assetPath);
|
||||
return _simulatePatchManifest.GetBundleName(assetPath);
|
||||
}
|
||||
string[] IBundleServices.GetAllDependencies(string assetPath)
|
||||
{
|
||||
return AppPatchManifest.GetAllDependencies(assetPath);
|
||||
return _simulatePatchManifest.GetAllDependencies(assetPath);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -8,10 +8,11 @@ namespace YooAsset
|
|||
internal class HostPlayModeImpl : IBundleServices
|
||||
{
|
||||
// 补丁清单
|
||||
internal PatchManifest AppPatchManifest;
|
||||
internal PatchManifest LocalPatchManifest;
|
||||
internal PatchManifest AppPatchManifest { private set; get; }
|
||||
internal PatchManifest LocalPatchManifest { private set; get; }
|
||||
|
||||
// 参数相关
|
||||
internal bool LocationToLower { private set; get; }
|
||||
internal bool ClearCacheWhenDirty { private set; get; }
|
||||
private string _defaultHostServer;
|
||||
private string _fallbackHostServer;
|
||||
|
@ -19,8 +20,9 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
|
||||
public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
LocationToLower = locationToLower;
|
||||
ClearCacheWhenDirty = clearCacheWhenDirty;
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
|
@ -274,6 +276,17 @@ namespace YooAsset
|
|||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 设置资源清单
|
||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
||||
{
|
||||
AppPatchManifest = patchManifest;
|
||||
}
|
||||
internal void SetLocalPatchManifest(PatchManifest patchManifest)
|
||||
{
|
||||
LocalPatchManifest = patchManifest;
|
||||
LocalPatchManifest.InitAssetPathMapping(LocationToLower);
|
||||
}
|
||||
|
||||
#region IBundleServices接口
|
||||
BundleInfo IBundleServices.GetBundleInfo(string bundleName)
|
||||
{
|
||||
|
|
|
@ -6,13 +6,15 @@ namespace YooAsset
|
|||
{
|
||||
internal class OfflinePlayModeImpl : IBundleServices
|
||||
{
|
||||
internal PatchManifest AppPatchManifest;
|
||||
private PatchManifest _appPatchManifest;
|
||||
private bool _locationToLower;
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync()
|
||||
public InitializationOperation InitializeAsync(bool locationToLower)
|
||||
{
|
||||
_locationToLower = locationToLower;
|
||||
var operation = new OfflinePlayModeInitializationOperation(this);
|
||||
OperationSystem.ProcessOperaiton(operation);
|
||||
return operation;
|
||||
|
@ -23,9 +25,9 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public int GetResourceVersion()
|
||||
{
|
||||
if (AppPatchManifest == null)
|
||||
if (_appPatchManifest == null)
|
||||
return 0;
|
||||
return AppPatchManifest.ResourceVersion;
|
||||
return _appPatchManifest.ResourceVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -33,18 +35,25 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags);
|
||||
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(_appPatchManifest, tags);
|
||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 设置资源清单
|
||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
||||
{
|
||||
_appPatchManifest = patchManifest;
|
||||
_appPatchManifest.InitAssetPathMapping(_locationToLower);
|
||||
}
|
||||
|
||||
#region IBundleServices接口
|
||||
BundleInfo IBundleServices.GetBundleInfo(string bundleName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(bundleName))
|
||||
return new BundleInfo(string.Empty);
|
||||
|
||||
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
||||
if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||
return bundleInfo;
|
||||
|
@ -58,19 +67,19 @@ namespace YooAsset
|
|||
}
|
||||
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
||||
{
|
||||
return PatchHelper.GetAssetsInfoByTag(AppPatchManifest, tags);
|
||||
return PatchHelper.GetAssetsInfoByTag(_appPatchManifest, tags);
|
||||
}
|
||||
string IBundleServices.MappingToAssetPath(string location)
|
||||
{
|
||||
return AppPatchManifest.MappingToAssetPath(location);
|
||||
return _appPatchManifest.MappingToAssetPath(location);
|
||||
}
|
||||
string IBundleServices.GetBundleName(string assetPath)
|
||||
{
|
||||
return AppPatchManifest.GetBundleName(assetPath);
|
||||
return _appPatchManifest.GetBundleName(assetPath);
|
||||
}
|
||||
string[] IBundleServices.GetAllDependencies(string assetPath)
|
||||
{
|
||||
return AppPatchManifest.GetAllDependencies(assetPath);
|
||||
return _appPatchManifest.GetAllDependencies(assetPath);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -35,6 +35,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public abstract class CreateParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源定位地址为小写地址
|
||||
/// </summary>
|
||||
public bool LocationToLower = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位服务接口
|
||||
/// </summary>
|
||||
|
@ -123,7 +128,7 @@ namespace YooAsset
|
|||
|
||||
#if !UNITY_EDITOR
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
throw new Exception($"Editor play mode only support unity editor.");
|
||||
throw new Exception($"Editor simulate mode only support unity editor.");
|
||||
#endif
|
||||
|
||||
// 创建驱动器
|
||||
|
@ -182,14 +187,14 @@ namespace YooAsset
|
|||
_editorSimulateModeImpl = new EditorSimulateModeImpl();
|
||||
_bundleServices = _editorSimulateModeImpl;
|
||||
AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
initializeOperation = _editorSimulateModeImpl.InitializeAsync();
|
||||
initializeOperation = _editorSimulateModeImpl.InitializeAsync(parameters.LocationToLower);
|
||||
}
|
||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
_offlinePlayModeImpl = new OfflinePlayModeImpl();
|
||||
_bundleServices = _offlinePlayModeImpl;
|
||||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
initializeOperation = _offlinePlayModeImpl.InitializeAsync();
|
||||
initializeOperation = _offlinePlayModeImpl.InitializeAsync(parameters.LocationToLower);
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
|
@ -198,6 +203,7 @@ namespace YooAsset
|
|||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = _hostPlayModeImpl.InitializeAsync(
|
||||
hostPlayModeParameters.LocationToLower,
|
||||
hostPlayModeParameters.ClearCacheWhenDirty,
|
||||
hostPlayModeParameters.DefaultHostServer,
|
||||
hostPlayModeParameters.FallbackHostServer);
|
||||
|
@ -881,7 +887,7 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 资源定位地址转换为资源完整路径
|
||||
/// </summary>
|
||||
public static string MappingToAssetPath(string location)
|
||||
internal static string MappingToAssetPath(string location)
|
||||
{
|
||||
DebugCheckLocation(location);
|
||||
return _bundleServices.MappingToAssetPath(location);
|
||||
|
|
Loading…
Reference in New Issue