Support addressable location

支持可寻址资源定位
This commit is contained in:
hevinci
2022-04-28 17:23:31 +08:00
parent 775c724840
commit 2cb006f3d9
40 changed files with 799 additions and 235 deletions
@@ -0,0 +1,29 @@
namespace YooAsset
{
public class AddressLocationServices : ILocationServices
{
public AddressLocationServices()
{
#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);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a8d6592eded144142afcf85c79cf1ce4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,42 @@
namespace YooAsset
{
public class DefaultLocationServices : ILocationServices
{
private readonly string _resourceRoot;
public DefaultLocationServices(string resourceRoot)
{
if (string.IsNullOrEmpty(resourceRoot) == false)
_resourceRoot = PathHelper.GetRegularPath(resourceRoot);
#if UNITY_EDITOR
LocationServicesHelper.InitEditorPlayMode(false);
#endif
}
public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
{
location = CombineAssetPath(_resourceRoot, location);
if (playMode == YooAssets.EPlayMode.EditorPlayMode)
{
#if UNITY_EDITOR
return LocationServicesHelper.ConvertLocationToAssetPath(location);
#else
throw new System.NotImplementedException();
#endif
}
else
{
return location;
}
}
private string CombineAssetPath(string root, string location)
{
if (string.IsNullOrEmpty(root))
return location;
else
return $"{root}/{location}";
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d996937ba73c9b4bb942b8ba6f43398
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
#if UNITY_EDITOR
using System.Reflection;
namespace YooAsset
{
internal static class LocationServicesHelper
{
private static System.Type AssetBundleGrouperSettingHelperClassType;
public static void InitEditorPlayMode(bool enableAddressable)
{
AssetBundleGrouperSettingHelperClassType = Assembly.Load("YooAsset.Editor").GetType("YooAsset.Editor.AssetBundleGrouperSettingHelper");
InvokePublicStaticMethod(AssetBundleGrouperSettingHelperClassType, "InitEditorPlayMode", enableAddressable);
}
public static string ConvertLocationToAssetPath(string location)
{
return (string)InvokePublicStaticMethod(AssetBundleGrouperSettingHelperClassType, "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
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b39dcdab07554ca4ab4ace5ca97aee78
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: