Skip to content

Commit

Permalink
update runtime code
Browse files Browse the repository at this point in the history
  • Loading branch information
gmhevinci committed Dec 24, 2022
1 parent 16943d4 commit dd82425
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 170 deletions.
8 changes: 5 additions & 3 deletions Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class AssetSystemImpl
private readonly static Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
private static long _sceneCreateCount = 0;

private string _packageName;
private bool _simulationOnEditor;
private int _loadingMaxNumber;
public IDecryptionServices DecryptionServices { private set; get; }
Expand All @@ -23,8 +24,9 @@ internal class AssetSystemImpl
/// 初始化
/// 注意:在使用AssetSystem之前需要初始化
/// </summary>
public void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
public void Initialize(string packageName, bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
{
_packageName = packageName;
_simulationOnEditor = simulationOnEditor;
_loadingMaxNumber = loadingMaxNumber;
DecryptionServices = decryptionServices;
Expand Down Expand Up @@ -184,7 +186,7 @@ public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sc
}

var handle = provider.CreateHandle<SceneOperationHandle>();
handle.PackageName = BundleServices.GetPackageName();
handle.PackageName = _packageName;
_sceneHandles.Add(providerGUID, handle);
return handle;
}
Expand Down Expand Up @@ -300,7 +302,7 @@ internal void ClearSceneHandle()
// 释放资源包下的所有场景
if (BundleServices.IsServicesValid())
{
string packageName = BundleServices.GetPackageName();
string packageName = _packageName;
List<string> removeList = new List<string>();
foreach (var valuePair in _sceneHandles)
{
Expand Down
68 changes: 15 additions & 53 deletions Assets/YooAsset/Runtime/AssetsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public InitializationOperation InitializeAsync(InitializeParameters parameters)
var editorSimulateModeImpl = new EditorSimulateModeImpl();
_bundleServices = editorSimulateModeImpl;
_playModeServices = editorSimulateModeImpl;
_assetSystemImpl.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
_assetSystemImpl.Initialize(PackageName, true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);

var initializeParameters = parameters as EditorSimulateModeParameters;
initializeOperation = editorSimulateModeImpl.InitializeAsync(PackageName, initializeParameters.LocationToLower, initializeParameters.SimulatePatchManifestPath);
Expand All @@ -97,7 +97,7 @@ public InitializationOperation InitializeAsync(InitializeParameters parameters)
var offlinePlayModeImpl = new OfflinePlayModeImpl();
_bundleServices = offlinePlayModeImpl;
_playModeServices = offlinePlayModeImpl;
_assetSystemImpl.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
_assetSystemImpl.Initialize(PackageName, false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);

var initializeParameters = parameters as OfflinePlayModeParameters;
initializeOperation = offlinePlayModeImpl.InitializeAsync(PackageName, initializeParameters.LocationToLower);
Expand All @@ -107,7 +107,7 @@ public InitializationOperation InitializeAsync(InitializeParameters parameters)
var hostPlayModeImpl = new HostPlayModeImpl();
_bundleServices = hostPlayModeImpl;
_playModeServices = hostPlayModeImpl;
_assetSystemImpl.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
_assetSystemImpl.Initialize(PackageName, false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);

var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync(
Expand Down Expand Up @@ -319,7 +319,7 @@ public AssetInfo[] GetAssetInfos(string tag)
{
DebugCheckInitialize();
string[] tags = new string[] { tag };
return _bundleServices.GetAssetInfos(tags);
return _playModeServices.ActiveManifest.GetAssetsInfoByTags(tags);
}

/// <summary>
Expand All @@ -329,7 +329,7 @@ public AssetInfo[] GetAssetInfos(string tag)
public AssetInfo[] GetAssetInfos(string[] tags)
{
DebugCheckInitialize();
return _bundleServices.GetAssetInfos(tags);
return _playModeServices.ActiveManifest.GetAssetsInfoByTags(tags);
}

/// <summary>
Expand All @@ -350,7 +350,7 @@ public AssetInfo GetAssetInfo(string location)
public bool CheckLocationValid(string location)
{
DebugCheckInitialize();
string assetPath = _bundleServices.TryMappingToAssetPath(location);
string assetPath = _playModeServices.ActiveManifest.TryMappingToAssetPath(location);
return string.IsNullOrEmpty(assetPath) == false;
}
#endregion
Expand Down Expand Up @@ -725,7 +725,15 @@ internal bool IsIncludeBundleFile(string fileName)
// NOTE : 编辑器模拟模式下始终返回TRUE
if (_playMode == EPlayMode.EditorSimulateMode)
return true;
return _bundleServices.IsIncludeBundleFile(fileName);
return _playModeServices.ActiveManifest.IsIncludeBundleFile(fileName);
}

/// <summary>
/// 资源定位地址转换为资源信息类
/// </summary>
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
return _playModeServices.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
}
#endregion

Expand All @@ -739,24 +747,6 @@ private void DebugCheckInitialize()
throw new Exception($"Package initialize failed ! {_initializeError}");
}

[Conditional("DEBUG")]
private void DebugCheckLocation(string location)
{
if (string.IsNullOrEmpty(location) == false)
{
// 检查路径末尾是否有空格
int index = location.LastIndexOf(" ");
if (index != -1)
{
if (location.Length == index + 1)
YooLogger.Warning($"Found blank character in location : \"{location}\"");
}

if (location.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
YooLogger.Warning($"Found illegal character in location : \"{location}\"");
}
}

[Conditional("DEBUG")]
private void DebugCheckUpdateManifest()
{
Expand All @@ -777,33 +767,5 @@ internal DebugPackageData GetDebugPackageData()
return data;
}
#endregion

#region 私有方法
/// <summary>
/// 资源定位地址转换为资源信息类,失败时内部会发出错误日志。
/// </summary>
/// <returns>如果转换失败会返回一个无效的资源信息类</returns>
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
DebugCheckLocation(location);
string assetPath = _bundleServices.MappingToAssetPath(location);
PatchAsset patchAsset = _bundleServices.TryGetPatchAsset(assetPath);
if (patchAsset != null)
{
AssetInfo assetInfo = new AssetInfo(patchAsset, assetType);
return assetInfo;
}
else
{
string error;
if (string.IsNullOrEmpty(location))
error = $"The location is null or empty !";
else
error = $"The location is invalid : {location}";
AssetInfo assetInfo = new AssetInfo(error);
return assetInfo;
}
}
#endregion
}
}
Loading

0 comments on commit dd82425

Please sign in to comment.