Support fast build mode.

支持快速构建模式,真实的实现EditorPlayMode的运行时环境。
This commit is contained in:
hevinci
2022-05-02 23:15:09 +08:00
parent 8d02406211
commit 665a16fe60
39 changed files with 492 additions and 383 deletions

View File

@@ -9,9 +9,9 @@ namespace YooAsset
BundleInfo GetBundleInfo(string bundleName);
/// <summary>
/// 可寻址地址转换为资源路径
/// 映射为资源路径
/// </summary>
string ConvertAddress(string address);
string MappingToAssetPath(string location);
/// <summary>
/// 获取资源所属的资源包名称

View File

@@ -6,6 +6,6 @@ namespace YooAsset
/// <summary>
/// 定位地址转换为资源路径
/// </summary>
string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location);
string ConvertLocationToAssetPath(string location);
}
}

View File

@@ -3,27 +3,9 @@ namespace YooAsset
{
public class AddressLocationServices : ILocationServices
{
public AddressLocationServices()
public string ConvertLocationToAssetPath(string location)
{
#if UNITY_EDITOR
LocationServicesHelper.InitEditorPlayMode(true);
#endif
}
public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
{
if (playMode == YooAssets.EPlayMode.EditorPlayMode)
{
#if UNITY_EDITOR
return LocationServicesHelper.ConvertLocationToAssetPath(location);
#else
throw new System.NotImplementedException();
#endif
}
else
{
return YooAssets.ConvertAddress(location);
}
return YooAssets.MappingToAssetPath(location);
}
}
}

View File

@@ -9,34 +9,19 @@ namespace YooAsset
{
if (string.IsNullOrEmpty(resourceRoot) == false)
_resourceRoot = PathHelper.GetRegularPath(resourceRoot);
}
#if UNITY_EDITOR
LocationServicesHelper.InitEditorPlayMode(false);
#endif
}
public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
public string ConvertLocationToAssetPath(string location)
{
location = CombineAssetPath(_resourceRoot, location);
if (playMode == YooAssets.EPlayMode.EditorPlayMode)
if (string.IsNullOrEmpty(_resourceRoot))
{
#if UNITY_EDITOR
return LocationServicesHelper.ConvertLocationToAssetPath(location);
#else
throw new System.NotImplementedException();
#endif
return YooAssets.MappingToAssetPath(location);
}
else
{
return location;
string tempLocation = $"{_resourceRoot}/{location}";
return YooAssets.MappingToAssetPath(tempLocation);
}
}
private string CombineAssetPath(string root, string location)
{
if (string.IsNullOrEmpty(root))
return location;
else
return $"{root}/{location}";
}
}
}

View File

@@ -1,31 +0,0 @@
#if UNITY_EDITOR
using System.Reflection;
namespace YooAsset
{
internal static class LocationServicesHelper
{
private static System.Type _classType;
public static void InitEditorPlayMode(bool enableAddressable)
{
_classType = Assembly.Load("YooAsset.Editor").GetType("YooAsset.Editor.AssetBundleGrouperRuntimeSupport");
InvokePublicStaticMethod(_classType, "InitEditorPlayMode", enableAddressable);
}
public static string ConvertLocationToAssetPath(string location)
{
return (string)InvokePublicStaticMethod(_classType, "ConvertLocationToAssetPath", location);
}
private static object InvokePublicStaticMethod(System.Type type, string method, params object[] parameters)
{
var methodInfo = type.GetMethod(method, BindingFlags.Public | BindingFlags.Static);
if (methodInfo == null)
{
UnityEngine.Debug.LogError($"{type.FullName} not found method : {method}");
return null;
}
return methodInfo.Invoke(null, parameters);
}
}
}
#endif

View File

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