mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Merge pull request #58 from AlanWeekend/main
增加初始化指定资源包操作,单独下载指定地址的资源文件
This commit is contained in:
@@ -132,7 +132,9 @@ namespace TEngine
|
||||
/// <param name="spriteName">图片名称。</param>
|
||||
/// <param name="isSetNativeSize">是否使用原生分辨率。</param>
|
||||
/// <param name="isAsync">是否使用异步加载。</param>
|
||||
public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false, bool isAsync = false)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false,
|
||||
bool isAsync = false, string customPackageName = "")
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
@@ -147,7 +149,8 @@ namespace TEngine
|
||||
{
|
||||
if (!isAsync)
|
||||
{
|
||||
image.sprite = GameModule.Resource.LoadAsset<Sprite>(spriteName);
|
||||
image.sprite =
|
||||
GameModule.Resource.LoadAsset<Sprite>(spriteName, customPackageName: customPackageName);
|
||||
if (isSetNativeSize)
|
||||
{
|
||||
image.SetNativeSize();
|
||||
@@ -167,7 +170,7 @@ namespace TEngine
|
||||
{
|
||||
image.SetNativeSize();
|
||||
}
|
||||
});
|
||||
}, customPackageName: customPackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +181,9 @@ namespace TEngine
|
||||
/// <param name="spriteRenderer">Image组件。</param>
|
||||
/// <param name="spriteName">图片名称。</param>
|
||||
/// <param name="isAsync">是否使用异步加载。</param>
|
||||
public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false,
|
||||
string customPackageName = "")
|
||||
{
|
||||
if (spriteRenderer == null)
|
||||
{
|
||||
@@ -193,7 +198,8 @@ namespace TEngine
|
||||
{
|
||||
if (!isAsync)
|
||||
{
|
||||
spriteRenderer.sprite = GameModule.Resource.LoadAsset<Sprite>(spriteName);
|
||||
spriteRenderer.sprite =
|
||||
GameModule.Resource.LoadAsset<Sprite>(spriteName, customPackageName: customPackageName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,11 +211,11 @@ namespace TEngine
|
||||
}
|
||||
|
||||
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||
});
|
||||
}, customPackageName: customPackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查找子节点。
|
||||
/// </summary>
|
||||
@@ -221,7 +227,7 @@ namespace TEngine
|
||||
var findTrans = transform.Find(path);
|
||||
return findTrans != null ? findTrans : null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据名字找到子节点,主要用于dummy接口。
|
||||
/// </summary>
|
||||
@@ -252,7 +258,7 @@ namespace TEngine
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
|
||||
public static Component FindChildComponent(this Type type, Transform transform, string path)
|
||||
{
|
||||
@@ -264,7 +270,7 @@ namespace TEngine
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static T FindChildComponent<T>(this Transform transform, string path) where T : Component
|
||||
{
|
||||
var findTrans = transform.Find(path);
|
||||
|
@@ -86,8 +86,9 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 初始化操作。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
InitializationOperation InitPackage();
|
||||
InitializationOperation InitPackage(string customPackageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 卸载资源。
|
||||
|
@@ -15,7 +15,7 @@ namespace TEngine
|
||||
#region Propreties
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称。
|
||||
/// 默认资源包名称。
|
||||
/// </summary>
|
||||
public string PackageName { get; set; } = "DefaultPackage";
|
||||
|
||||
@@ -332,18 +332,24 @@ namespace TEngine
|
||||
/// 初始化资源包裹。
|
||||
/// </summary>
|
||||
/// <returns>初始化资源包裹操作句柄。</returns>
|
||||
public InitializationOperation InitPackage()
|
||||
public InitializationOperation InitPackage(string customPackageName = "")
|
||||
{
|
||||
// 创建默认的资源包
|
||||
string packageName = PackageName;
|
||||
var package = YooAssets.TryGetPackage(packageName);
|
||||
var targetPackageName = string.IsNullOrEmpty(customPackageName) || customPackageName.Equals(PackageName)
|
||||
? PackageName
|
||||
: customPackageName;
|
||||
var package = YooAssets.TryGetPackage(targetPackageName);
|
||||
if (package == null)
|
||||
{
|
||||
package = YooAssets.CreatePackage(packageName);
|
||||
YooAssets.SetDefaultPackage(package);
|
||||
package = YooAssets.CreatePackage(targetPackageName);
|
||||
}
|
||||
|
||||
DefaultPackage = package;
|
||||
// 设置默认资源包
|
||||
if (targetPackageName.Equals(PackageName))
|
||||
{
|
||||
YooAssets.SetDefaultPackage(package);
|
||||
DefaultPackage = package;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//编辑器模式使用。
|
||||
@@ -359,7 +365,7 @@ namespace TEngine
|
||||
if (playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var createParameters = new EditorSimulateModeParameters();
|
||||
createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(packageName);
|
||||
createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(targetPackageName);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
|
@@ -230,10 +230,11 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 初始化操作。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
public InitializationOperation InitPackage()
|
||||
public InitializationOperation InitPackage(string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.InitPackage();
|
||||
return m_ResourceManager.InitPackage(customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -306,6 +307,27 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载当前资源版本指定地址的资源文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源地址</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(string location, string packageName = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
var package = YooAssets.GetPackage(this.packageName);
|
||||
Downloader = package.CreateResourceDownloader(location, downloadingMaxNum, failedTryAgain);
|
||||
return Downloader;
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
Downloader = package.CreateResourceDownloader(location, downloadingMaxNum, failedTryAgain);
|
||||
return Downloader;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹未使用的缓存文件。
|
||||
/// </summary>
|
||||
@@ -507,7 +529,8 @@ namespace TEngine
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache, packageName: customPackageName);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -538,7 +561,8 @@ namespace TEngine
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle,
|
||||
bool needCache = false, string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache, packageName: customPackageName);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -652,7 +676,8 @@ namespace TEngine
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, bool needCache = false, string customPackageName = "") where T : UnityEngine.Object
|
||||
bool needInstance = true, bool needCache = false, string customPackageName = "")
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance, needCache,
|
||||
packageName: customPackageName);
|
||||
@@ -699,7 +724,8 @@ namespace TEngine
|
||||
public async UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location,
|
||||
CancellationToken cancellationToken = default, string customPackageName = "")
|
||||
{
|
||||
return await m_ResourceManager.LoadRawAssetAsync(location, cancellationToken, packageName: customPackageName);
|
||||
return await m_ResourceManager.LoadRawAssetAsync(location, cancellationToken,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user