mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Compare commits
35 Commits
TEngine4.0
...
TEngine4.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ff613e4130 | ||
![]() |
fea1ae2278 | ||
![]() |
866c440479 | ||
![]() |
48ff839d64 | ||
![]() |
69be3cfa23 | ||
![]() |
5f2c27ecf0 | ||
![]() |
ef17cd851b | ||
![]() |
f186d6b058 | ||
![]() |
4385123976 | ||
![]() |
1334dc30f9 | ||
![]() |
af822add2c | ||
![]() |
ffb1f214ad | ||
![]() |
213aaed426 | ||
![]() |
623d301e41 | ||
![]() |
2870383afe | ||
![]() |
1ad435958a | ||
![]() |
386787c6ec | ||
![]() |
cd65dde4c3 | ||
![]() |
8321e77421 | ||
![]() |
1b6f80952e | ||
![]() |
b52e655c30 | ||
![]() |
8c0df95626 | ||
![]() |
0d1e308f1c | ||
![]() |
f8797538fd | ||
![]() |
fe4e168041 | ||
![]() |
8e9047d3a3 | ||
![]() |
04bfaeccc8 | ||
![]() |
d66c823c15 | ||
![]() |
0ec1424f0a | ||
![]() |
01f8eb9d57 | ||
![]() |
f5021a9688 | ||
![]() |
a632f7a5ad | ||
![]() |
5f968f4154 | ||
![]() |
c9fe83c2bd | ||
![]() |
2c00d103cb |
9
BuildCLI/build_android.bat
Normal file
9
BuildCLI/build_android.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
cd /d %~dp0
|
||||
|
||||
call path_define.bat
|
||||
|
||||
%UNITYEDITOR_PATH%/Unity.exe %WORKSPACE% -logFile %BUILD_LOGFILE% -executeMethod TEngine.ReleaseTools.AutomationBuildAndroid -quit -batchmode -CustomArgs:Language=en_US; %WORKSPACE%
|
||||
|
||||
@REM for /f "delims=[" %%i in (%BUILD_LOGFILE%) do echo %%i
|
||||
|
||||
pause
|
6
BuildCLI/path_define.bat
Normal file
6
BuildCLI/path_define.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
cd /d %~dp0
|
||||
|
||||
set WORKSPACE=G:/github/TEngine/UnityProject
|
||||
set UNITYEDITOR_PATH=G:/UnityEditor/2021.3.20f1c1/Editor
|
||||
set BUILD_DLL_LOGFILE=./build_dll.log
|
||||
set BUILD_LOGFILE=./build.log
|
@@ -42,8 +42,16 @@ public class ConfigSystem : Singleton<ConfigSystem>
|
||||
/// <returns>ByteBuf</returns>
|
||||
private ByteBuf LoadByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>(file);
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
TextAsset textAsset = null;
|
||||
textAsset = GameModule.Resource.GetPreLoadAsset<TextAsset>(file);
|
||||
if (textAsset != null)
|
||||
{
|
||||
return new ByteBuf(textAsset.bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
textAsset = GameModule.Resource.LoadAsset<TextAsset>(file);
|
||||
return new ByteBuf(textAsset.bytes);
|
||||
}
|
||||
}
|
||||
}
|
@@ -65,7 +65,7 @@ namespace GameLogic
|
||||
base.AdjustItemNum(n, datas, funcItem);
|
||||
m_tpFuncItem = funcItem;
|
||||
LoopRectView.SetListItemCount(n);
|
||||
LoopRectView.RefreshAllShownItem();
|
||||
// LoopRectView.RefreshAllShownItem();
|
||||
m_tpFuncItem = null;
|
||||
}
|
||||
|
||||
|
@@ -38,10 +38,15 @@ namespace GameMain
|
||||
m_btnClear.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public override void RegisterEvent()
|
||||
{
|
||||
base.RegisterEvent();
|
||||
AddUIEvent(RuntimeId.ToRuntimeId("RefreshVersion"),RefreshVersion);
|
||||
}
|
||||
|
||||
public override void OnRefresh()
|
||||
{
|
||||
base.OnRefresh();
|
||||
RefreshVersion();
|
||||
}
|
||||
|
||||
#region 事件
|
||||
|
@@ -13,10 +13,9 @@ namespace GameMain
|
||||
|
||||
private ProcedureOwner _procedureOwner;
|
||||
|
||||
private float _currentDownloadTime;
|
||||
private float CurrentSpeed =>
|
||||
(GameModule.Resource.Downloader.TotalDownloadBytes -
|
||||
GameModule.Resource.Downloader.CurrentDownloadBytes) / _currentDownloadTime;
|
||||
GameModule.Resource.Downloader.CurrentDownloadBytes) / GameTime.time;
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
|
@@ -29,7 +29,8 @@ namespace GameMain
|
||||
|
||||
private async UniTaskVoid InitPackage(ProcedureOwner procedureOwner)
|
||||
{
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode)
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode ||
|
||||
GameModule.Resource.PlayMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
if (SettingsUtils.EnableUpdateData())
|
||||
{
|
||||
@@ -44,7 +45,8 @@ namespace GameMain
|
||||
|
||||
if (!string.IsNullOrEmpty(updateData.FallbackHostServerURL))
|
||||
{
|
||||
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL = updateData.FallbackHostServerURL;
|
||||
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL =
|
||||
updateData.FallbackHostServerURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,9 +62,9 @@ namespace GameMain
|
||||
{
|
||||
//热更新阶段文本初始化
|
||||
LoadText.Instance.InitConfigData(null);
|
||||
//热更新UI初始化
|
||||
UILoadMgr.Initialize();
|
||||
|
||||
|
||||
GameEvent.Send(RuntimeId.ToRuntimeId("RefreshVersion"));
|
||||
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
|
||||
// 编辑器模式。
|
||||
@@ -107,7 +109,9 @@ namespace GameMain
|
||||
// 打开启动UI。
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"资源初始化失败!");
|
||||
|
||||
UILoadTip.ShowMessageBox($"资源初始化失败!点击确认重试 \n \n <color=#FF0000>原因{initializationOperation.Error}</color>", MessageShowType.TwoButton,
|
||||
UILoadTip.ShowMessageBox(
|
||||
$"资源初始化失败!点击确认重试 \n \n <color=#FF0000>原因{initializationOperation.Error}</color>",
|
||||
MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { Retry(procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
|
@@ -14,6 +14,9 @@ namespace GameMain
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
//热更新UI初始化
|
||||
UILoadMgr.Initialize();
|
||||
|
||||
// 语言配置:设置当前使用的语言,如果不设置,则默认使用操作系统语言
|
||||
InitLanguageSettings();
|
||||
|
@@ -16,23 +16,23 @@ namespace GameMain
|
||||
{
|
||||
private float _progress = 0f;
|
||||
|
||||
private Dictionary<string, bool> m_LoadedFlag = new Dictionary<string, bool>();
|
||||
private readonly Dictionary<string, bool> _loadedFlag = new Dictionary<string, bool>();
|
||||
|
||||
public override bool UseNativeDialog => true;
|
||||
|
||||
private bool m_needProLoadConfig = false;
|
||||
private readonly bool _needProLoadConfig = true;
|
||||
|
||||
private bool m_InitConfigXml = false;
|
||||
private bool _hadInitConfigXml = false;
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
m_LoadedFlag.Clear();
|
||||
_loadedFlag.Clear();
|
||||
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
m_InitConfigXml = true;
|
||||
_hadInitConfigXml = true;
|
||||
}
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, Utility.Text.Format(LoadText.Instance.Label_Load_Load_Progress, 0));
|
||||
@@ -46,11 +46,11 @@ namespace GameMain
|
||||
{
|
||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
|
||||
var totalCount = m_LoadedFlag.Count <= 0 ? 1 : m_LoadedFlag.Count;
|
||||
var totalCount = _loadedFlag.Count <= 0 ? 1 : _loadedFlag.Count;
|
||||
|
||||
var loadCount = m_LoadedFlag.Count <= 0 ? 1 : 0;
|
||||
var loadCount = _loadedFlag.Count <= 0 ? 1 : 0;
|
||||
|
||||
foreach (KeyValuePair<string, bool> loadedFlag in m_LoadedFlag)
|
||||
foreach (KeyValuePair<string, bool> loadedFlag in _loadedFlag)
|
||||
{
|
||||
if (!loadedFlag.Value)
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace GameMain
|
||||
}
|
||||
}
|
||||
|
||||
if (m_LoadedFlag.Count != 0)
|
||||
if (_loadedFlag.Count != 0)
|
||||
{
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, Utility.Text.Format(LoadText.Instance.Label_Load_Load_Progress, (float)loadCount / totalCount * 100));
|
||||
}
|
||||
@@ -87,7 +87,7 @@ namespace GameMain
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_InitConfigXml == false)
|
||||
if (_hadInitConfigXml == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -116,13 +116,13 @@ namespace GameMain
|
||||
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(2.5f));
|
||||
|
||||
if (m_needProLoadConfig)
|
||||
if (_needProLoadConfig)
|
||||
{
|
||||
LoadAllConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_InitConfigXml = true;
|
||||
_hadInitConfigXml = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,14 +130,27 @@ namespace GameMain
|
||||
{
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
m_InitConfigXml = true;
|
||||
_hadInitConfigXml = true;
|
||||
return;
|
||||
}
|
||||
AssetInfo[] assetInfos = GameModule.Resource.GetAssetInfos("PRELOAD");
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
LoadConfig(assetInfo.Address);
|
||||
}
|
||||
#if UNITY_WEBGL
|
||||
AssetInfo[] webAssetInfos = GameModule.Resource.GetAssetInfos("WEBGL_PRELOAD");
|
||||
foreach (var assetInfo in webAssetInfos)
|
||||
{
|
||||
LoadConfig(assetInfo.Address);
|
||||
}
|
||||
#endif
|
||||
_hadInitConfigXml = true;
|
||||
}
|
||||
|
||||
private void LoadConfig(string configName)
|
||||
{
|
||||
m_LoadedFlag.Add(configName, false);
|
||||
_loadedFlag.Add(configName, false);
|
||||
GameModule.Resource.LoadAssetAsync<TextAsset>(configName, OnLoadSuccess);
|
||||
}
|
||||
|
||||
@@ -147,10 +160,11 @@ namespace GameMain
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var name = assetOperationHandle.GetAssetInfo().Address;
|
||||
m_LoadedFlag[name] = true;
|
||||
Log.Info("Load config '{0}' OK.", name);
|
||||
var location = assetOperationHandle.GetAssetInfo().Address;
|
||||
_loadedFlag[location] = true;
|
||||
GameModule.Resource.PushPreLoadAsset(location, assetOperationHandle.AssetObject);
|
||||
Log.Info("Load config '{0}' OK.", location);
|
||||
assetOperationHandle.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,14 +15,14 @@ namespace GameMain
|
||||
public override bool UseNativeDialog => true;
|
||||
|
||||
private ProcedureOwner _procedureOwner;
|
||||
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate,$"更新静态版本文件...");
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"更新静态版本文件...");
|
||||
|
||||
//检查设备是否能够访问互联网
|
||||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||||
@@ -34,6 +34,7 @@ namespace GameMain
|
||||
GetStaticVersion().Forget,
|
||||
() => { ChangeState<ProcedureInitResources>(procedureOwner); });
|
||||
}
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng);
|
||||
|
||||
// 用户尝试更新静态版本。
|
||||
@@ -49,23 +50,35 @@ namespace GameMain
|
||||
|
||||
var operation = GameModule.Resource.UpdatePackageVersionAsync();
|
||||
|
||||
await operation.ToUniTask();
|
||||
try
|
||||
{
|
||||
await operation.ToUniTask();
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//线上最新版本operation.PackageVersion
|
||||
GameModule.Resource.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {GameModule.Resource.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//线上最新版本operation.PackageVersion
|
||||
GameModule.Resource.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {GameModule.Resource.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnGetStaticVersionError(operation.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(operation.Error);
|
||||
|
||||
UILoadTip.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{operation.Error}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
OnGetStaticVersionError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetStaticVersionError(string error)
|
||||
{
|
||||
Log.Error(error);
|
||||
|
||||
UILoadTip.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{error}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,6 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
ShowPackageView: 0
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
UniqueBundleName: 0
|
||||
ShowEditorAlias: 0
|
||||
Packages:
|
||||
@@ -78,7 +80,7 @@ MonoBehaviour:
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
AssetTags: WEBGL_PRELOAD
|
||||
UserData:
|
||||
- GroupName: DLL
|
||||
GroupDesc: "\u4EE3\u7801"
|
||||
|
@@ -4,7 +4,7 @@ using TEngine.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class BuildAssetsCommand
|
||||
public static class BuildDLLCommand
|
||||
{
|
||||
private const string EnableHybridClrScriptingDefineSymbol = "ENABLE_HYBRIDCLR";
|
||||
|
||||
@@ -35,6 +35,12 @@ public static class BuildAssetsCommand
|
||||
CopyAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
public static void BuildAndCopyDlls(BuildTarget target)
|
||||
{
|
||||
CompileDllCommand.CompileDll(target);
|
||||
CopyAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
public static void CopyAOTHotUpdateDlls(BuildTarget target)
|
||||
{
|
||||
CopyAOTAssembliesToAssetPath();
|
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.U2D;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
@@ -55,6 +56,33 @@ public static class EditorSpriteSaveInfo
|
||||
}
|
||||
|
||||
EditorApplication.update += CheckDirty;
|
||||
|
||||
//读取所有图集信息
|
||||
string[] findAssets = AssetDatabase.FindAssets("t:SpriteAtlas", new[] { NormalAtlasDir });
|
||||
foreach (var findAsset in findAssets)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(findAsset);
|
||||
SpriteAtlas sa = AssetDatabase.LoadAssetAtPath(path, typeof(SpriteAtlas)) as SpriteAtlas;
|
||||
if (sa == null)
|
||||
{
|
||||
Debug.LogError($"加载图集数据{path}失败");
|
||||
continue;
|
||||
}
|
||||
|
||||
string atlasName = Path.GetFileNameWithoutExtension(path);
|
||||
var objects = sa.GetPackables();
|
||||
foreach (var o in objects)
|
||||
{
|
||||
if (!m_allASprites.TryGetValue(atlasName, out var list))
|
||||
{
|
||||
list = new List<string>();
|
||||
m_allASprites.Add(atlasName, list);
|
||||
}
|
||||
list.Add(AssetDatabase.GetAssetPath(o));
|
||||
}
|
||||
}
|
||||
|
||||
m_inited = true;
|
||||
}
|
||||
|
||||
public static void CheckDirty()
|
||||
|
@@ -1,42 +1,119 @@
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
using BuildResult = UnityEditor.Build.Reporting.BuildResult;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 打包工具类。
|
||||
/// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包,详见CommandLineReader.cs example1</remarks>
|
||||
/// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包以及CLI工作流,详见CommandLineReader.cs example1</remarks>
|
||||
/// </summary>
|
||||
public static class ReleaseTools
|
||||
{
|
||||
public static void BuildPackage()
|
||||
public static void BuildDll()
|
||||
{
|
||||
string platform = CommandLineReader.GetCustomArgument("platform");
|
||||
if (string.IsNullOrEmpty(platform))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!platform is null");
|
||||
return;
|
||||
}
|
||||
|
||||
BuildTarget target = GetBuildTarget(platform);
|
||||
BuildDLLCommand.BuildAndCopyDlls(target);
|
||||
}
|
||||
|
||||
public static void BuildAssetBundle()
|
||||
{
|
||||
string outputRoot = CommandLineReader.GetCustomArgument("outputRoot");
|
||||
BuildTarget target = BuildTarget.StandaloneWindows64;
|
||||
BuildInternal(target,outputRoot);
|
||||
if (string.IsNullOrEmpty(outputRoot))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!outputRoot is null");
|
||||
return;
|
||||
}
|
||||
|
||||
string packageVersion = CommandLineReader.GetCustomArgument("packageVersion");
|
||||
if (string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!packageVersion is null");
|
||||
return;
|
||||
}
|
||||
|
||||
string platform = CommandLineReader.GetCustomArgument("platform");
|
||||
if (string.IsNullOrEmpty(platform))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!platform is null");
|
||||
return;
|
||||
}
|
||||
|
||||
BuildTarget target = GetBuildTarget(platform);
|
||||
BuildInternal(target, outputRoot);
|
||||
Debug.LogWarning($"Start BuildPackage BuildTarget:{target} outputPath:{outputRoot}");
|
||||
}
|
||||
|
||||
private static void BuildInternal(BuildTarget buildTarget,string outputRoot)
|
||||
|
||||
private static BuildTarget GetBuildTarget(string platform)
|
||||
{
|
||||
BuildTarget target = BuildTarget.NoTarget;
|
||||
switch (platform)
|
||||
{
|
||||
case "Android":
|
||||
target = BuildTarget.Android;
|
||||
break;
|
||||
case "IOS":
|
||||
target = BuildTarget.iOS;
|
||||
break;
|
||||
case "Windows":
|
||||
target = BuildTarget.StandaloneWindows64;
|
||||
break;
|
||||
case "MacOS":
|
||||
target = BuildTarget.StandaloneOSX;
|
||||
break;
|
||||
case "Linux":
|
||||
target = BuildTarget.StandaloneLinux64;
|
||||
break;
|
||||
case "WebGL":
|
||||
target = BuildTarget.WebGL;
|
||||
break;
|
||||
case "Switch":
|
||||
target = BuildTarget.Switch;
|
||||
break;
|
||||
case "PS4":
|
||||
target = BuildTarget.PS4;
|
||||
break;
|
||||
case "PS5":
|
||||
target = BuildTarget.PS5;
|
||||
break;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
private static void BuildInternal(BuildTarget buildTarget, string outputRoot, string packageVersion = "1.0")
|
||||
{
|
||||
Debug.Log($"开始构建 : {buildTarget}");
|
||||
|
||||
BuildParameters.SBPBuildParameters sbpBuildParameters = new BuildParameters.SBPBuildParameters();
|
||||
sbpBuildParameters.WriteLinkXML = true;
|
||||
|
||||
// 构建参数
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||
buildParameters.BuildOutputRoot = outputRoot;//AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildOutputRoot = outputRoot; //AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildTarget = buildTarget;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.ForceRebuild;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.ScriptableBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.IncrementalBuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = "1.0";
|
||||
buildParameters.PackageVersion = packageVersion;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule();
|
||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||
buildParameters.CompressOption = ECompressOption.LZMA;
|
||||
buildParameters.OutputNameStyle = EOutputNameStyle.HashName;
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.ClearAndCopyAll;
|
||||
buildParameters.SBPParameters = sbpBuildParameters;
|
||||
|
||||
// 执行构建
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
var buildResult = builder.Run(buildParameters);
|
||||
@@ -50,15 +127,66 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
// 从构建命令里获取参数示例
|
||||
private static string GetBuildPackageName()
|
||||
[MenuItem("TEngine/Build/一键打包Windows", false, 30)]
|
||||
public static void AutomationBuild()
|
||||
{
|
||||
foreach (string arg in System.Environment.GetCommandLineArgs())
|
||||
BuildDLLCommand.BuildAndCopyDlls(BuildTarget.StandaloneWindows64);
|
||||
AssetDatabase.Refresh();
|
||||
BuildInternal(BuildTarget.StandaloneWindows64, Application.dataPath + "/../Builds/Windows", "1.0");
|
||||
AssetDatabase.Refresh();
|
||||
BuildImp(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64, $"{Application.dataPath}/../Builds/Windows/{GetBuildPackageVersion()}Windows.exe");
|
||||
}
|
||||
|
||||
// 构建版本相关
|
||||
private static string GetBuildPackageVersion()
|
||||
{
|
||||
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
|
||||
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/Build/一键打包Android", false, 30)]
|
||||
public static void AutomationBuildAndroid()
|
||||
{
|
||||
BuildDLLCommand.BuildAndCopyDlls(BuildTarget.Android);
|
||||
AssetDatabase.Refresh();
|
||||
BuildInternal(BuildTarget.Android, outputRoot:Application.dataPath + "/../Bundles",packageVersion: GetBuildPackageVersion());
|
||||
AssetDatabase.Refresh();
|
||||
BuildImp(BuildTargetGroup.Android, BuildTarget.Android, $"{Application.dataPath}/../Build/Android/{GetBuildPackageVersion()}Android.apk");
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/Build/一键打包IOS", false, 30)]
|
||||
public static void AutomationBuildIOS()
|
||||
{
|
||||
BuildDLLCommand.BuildAndCopyDlls(BuildTarget.iOS);
|
||||
AssetDatabase.Refresh();
|
||||
BuildInternal(BuildTarget.iOS, outputRoot:Application.dataPath + "/../Bundles",packageVersion: GetBuildPackageVersion());
|
||||
AssetDatabase.Refresh();
|
||||
BuildImp(BuildTargetGroup.iOS, BuildTarget.iOS, $"{Application.dataPath}/../Build/IOS/XCode_Project");
|
||||
}
|
||||
|
||||
public static void BuildImp(BuildTargetGroup buildTargetGroup, BuildTarget buildTarget, string locationPathName)
|
||||
{
|
||||
EditorUserBuildSettings.SwitchActiveBuildTarget(buildTargetGroup, BuildTarget.StandaloneWindows64);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions
|
||||
{
|
||||
if (arg.StartsWith("buildPackage"))
|
||||
return arg.Split("="[0])[1];
|
||||
scenes = new[] { "Assets/Scenes/main.unity" },
|
||||
locationPathName = locationPathName,
|
||||
targetGroup = buildTargetGroup,
|
||||
target = buildTarget,
|
||||
options = BuildOptions.None
|
||||
};
|
||||
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
BuildSummary summary = report.summary;
|
||||
if (summary.result == BuildResult.Succeeded)
|
||||
{
|
||||
Debug.Log($"Build success: {summary.totalSize / 1024 / 1024} MB");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Build Failed" + summary.result);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@@ -92,7 +92,6 @@ namespace TEngine
|
||||
{
|
||||
Log.Warning($"HttpPost {unityWebRequest.url} be canceled!");
|
||||
unityWebRequest.Dispose();
|
||||
cts.Dispose();
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -102,14 +101,12 @@ namespace TEngine
|
||||
{
|
||||
Log.Warning("HttpPost Timeout");
|
||||
unityWebRequest.Dispose();
|
||||
cts.Dispose();
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
string ret = unityWebRequest.downloadHandler.text;
|
||||
unityWebRequest.Dispose();
|
||||
cts.Dispose();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -225,15 +225,6 @@ namespace TEngine
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 释放Behaviour生命周期。
|
||||
/// </summary>
|
||||
public static void Release()
|
||||
{
|
||||
_MakeEntity();
|
||||
_behaviour.Release();
|
||||
}
|
||||
|
||||
private static void _MakeEntity()
|
||||
{
|
||||
if (_entity != null)
|
||||
@@ -241,23 +232,30 @@ namespace TEngine
|
||||
return;
|
||||
}
|
||||
|
||||
_entity = new GameObject("__MonoUtility__")
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
_entity = new GameObject("[Unity.Utility]");
|
||||
_entity.SetActive(true);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying)
|
||||
#endif
|
||||
{
|
||||
Object.DontDestroyOnLoad(_entity);
|
||||
}
|
||||
_entity.transform.SetParent(GameModule.Base.transform);
|
||||
|
||||
UnityEngine.Assertions.Assert.IsFalse(_behaviour);
|
||||
_behaviour = _entity.AddComponent<MainBehaviour>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放Behaviour生命周期。
|
||||
/// </summary>
|
||||
public static void Shutdown()
|
||||
{
|
||||
if (_behaviour != null)
|
||||
{
|
||||
_behaviour.Release();
|
||||
}
|
||||
if (_entity != null)
|
||||
{
|
||||
Object.Destroy(_entity);
|
||||
}
|
||||
_entity = null;
|
||||
}
|
||||
|
||||
private class MainBehaviour : MonoBehaviour
|
||||
{
|
||||
private event UnityAction UpdateEvent;
|
||||
|
@@ -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);
|
||||
|
@@ -77,7 +77,7 @@ namespace TEngine
|
||||
public static void Shutdown(ShutdownType shutdownType)
|
||||
{
|
||||
Log.Info("Shutdown Game Framework ({0})...", shutdownType);
|
||||
Utility.Unity.Release();
|
||||
Utility.Unity.Shutdown();
|
||||
RootModule rootModule = GetModule<RootModule>();
|
||||
if (rootModule != null)
|
||||
{
|
||||
|
@@ -14,6 +14,7 @@ namespace TEngine
|
||||
{
|
||||
private int _instanceID = 0;
|
||||
private string _assetLocation;
|
||||
private string _packageName;
|
||||
private AssetGroup _assetGroup;
|
||||
private AssetOperationHandle _operationHandle;
|
||||
|
||||
@@ -32,6 +33,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public string AssetLocation => _assetLocation;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称。
|
||||
/// </summary>
|
||||
public string PackageName => _packageName;
|
||||
|
||||
/// <summary>
|
||||
/// 脏初始化资源分组。
|
||||
/// </summary>
|
||||
@@ -49,10 +55,13 @@ namespace TEngine
|
||||
/// <param name="operation">资源操作句柄。</param>
|
||||
/// <param name="assetLocation">资源定位地址。</param>
|
||||
/// <param name="parent">父级资源引用。(NullAble)</param>
|
||||
public void Bind(AssetOperationHandle operation, string assetLocation, AssetReference parent = null)
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public void Bind(AssetOperationHandle operation, string assetLocation, AssetReference parent = null,
|
||||
string packageName = "")
|
||||
{
|
||||
_operationHandle = operation;
|
||||
this._assetLocation = assetLocation;
|
||||
this._packageName = packageName;
|
||||
_instanceID = gameObject.GetInstanceID();
|
||||
if (parent != null)
|
||||
{
|
||||
@@ -183,7 +192,8 @@ namespace TEngine
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <returns>资源实例。</returns>
|
||||
// ReSharper disable once ParameterHidesMember
|
||||
public T LoadAsset<T>(string assetName, Transform parent, out AssetOperationHandle assetOperationHandle) where T : Object
|
||||
public T LoadAsset<T>(string assetName, Transform parent, out AssetOperationHandle assetOperationHandle)
|
||||
where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return _assetGroup.LoadAsset<T>(assetName, parent, out assetOperationHandle);
|
||||
@@ -195,7 +205,8 @@ namespace TEngine
|
||||
/// <param name="assetName">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken = default) where T : Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken = default)
|
||||
where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return await _assetGroup.LoadAssetAsync<T>(assetName, cancellationToken);
|
||||
@@ -207,7 +218,8 @@ namespace TEngine
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return await _assetGroup.LoadGameObjectAsync(assetName, cancellationToken);
|
||||
@@ -220,9 +232,11 @@ namespace TEngine
|
||||
/// <param name="handle">资源句柄。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父级引用。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源引用组件。</returns>
|
||||
/// <exception cref="GameFrameworkException">捕获异常。</exception>
|
||||
public static AssetReference BindAssetReference(GameObject go, AssetOperationHandle handle, string location = "", AssetReference parent = null)
|
||||
public static AssetReference BindAssetReference(GameObject go, AssetOperationHandle handle,
|
||||
string location = "", AssetReference parent = null, string packageName = "")
|
||||
{
|
||||
if (go == null)
|
||||
{
|
||||
@@ -236,7 +250,7 @@ namespace TEngine
|
||||
|
||||
var ret = go.GetOrAddComponent<AssetReference>();
|
||||
|
||||
ret.Bind(operation: handle, assetLocation: location, parent: parent);
|
||||
ret.Bind(operation: handle, assetLocation: location, parent: parent, packageName: packageName);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -247,9 +261,11 @@ namespace TEngine
|
||||
/// <param name="go">游戏物体实例。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父级引用。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源引用组件。</returns>
|
||||
/// <exception cref="GameFrameworkException">捕获异常。</exception>
|
||||
public static AssetReference BindAssetReference(GameObject go, string location = "", AssetReference parent = null)
|
||||
public static AssetReference BindAssetReference(GameObject go, string location = "",
|
||||
AssetReference parent = null, string packageName = "")
|
||||
{
|
||||
if (go == null)
|
||||
{
|
||||
@@ -258,7 +274,7 @@ namespace TEngine
|
||||
|
||||
var ret = go.GetOrAddComponent<AssetReference>();
|
||||
|
||||
ret.Bind(operation: null, assetLocation: location, parent: parent);
|
||||
ret.Bind(operation: null, assetLocation: location, parent: parent, packageName: packageName);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@@ -10,18 +10,6 @@ namespace TEngine
|
||||
public const string RootFolderName = "yoo";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类。
|
||||
/// </summary>
|
||||
public class BuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return BuiltinQueryMgr.FileExists(packageName, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 内置资源资源查询帮助类。
|
||||
|
@@ -2,7 +2,6 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
@@ -87,8 +86,9 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 初始化操作。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
InitializationOperation InitPackage();
|
||||
InitializationOperation InitPackage(string customPackageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 卸载资源。
|
||||
@@ -110,8 +110,9 @@ namespace TEngine
|
||||
/// 检查资源是否存在。
|
||||
/// </summary>
|
||||
/// <param name="location">要检查资源的名称。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>检查资源是否存在的结果。</returns>
|
||||
HasAssetResult HasAsset(string location);
|
||||
HasAssetResult HasAsset(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认资源包。
|
||||
@@ -123,42 +124,48 @@ namespace TEngine
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>是否需要从远端下载。</returns>
|
||||
bool IsNeedDownloadFromRemote(string location);
|
||||
bool IsNeedDownloadFromRemote(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>是否需要从远端下载。</returns>
|
||||
bool IsNeedDownloadFromRemote(AssetInfo assetInfo);
|
||||
bool IsNeedDownloadFromRemote(AssetInfo assetInfo, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tag">资源标签。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
AssetInfo[] GetAssetInfos(string tag);
|
||||
AssetInfo[] GetAssetInfos(string tag, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tags">资源标签列表。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
AssetInfo[] GetAssetInfos(string[] tags);
|
||||
AssetInfo[] GetAssetInfos(string[] tags, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息。</returns>
|
||||
AssetInfo GetAssetInfo(string location);
|
||||
AssetInfo GetAssetInfo(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 检查资源定位地址是否有效。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
bool CheckLocationValid(string location);
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
bool CheckLocationValid(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -166,9 +173,11 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false, string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -177,9 +186,11 @@ namespace TEngine
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false,
|
||||
string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -187,9 +198,11 @@ namespace TEngine
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false,
|
||||
string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -198,55 +211,68 @@ namespace TEngine
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false,
|
||||
string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object;
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false, string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object;
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false, string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型。</typeparam>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : Object;
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location, string packageName = "")
|
||||
where TObject : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子资源对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型。</typeparam>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : Object;
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location, string packageName = "")
|
||||
where TObject : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo);
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object;
|
||||
UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag, string packageName = "") where T : UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源。
|
||||
@@ -255,9 +281,11 @@ namespace TEngine
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object;
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, bool needCache = false, string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -265,8 +293,10 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default,
|
||||
bool needCache = false, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -275,16 +305,20 @@ namespace TEngine
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent,
|
||||
CancellationToken cancellationToken = default, bool needCache = false, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载原生文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location, CancellationToken cancellationToken = default);
|
||||
UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location,
|
||||
CancellationToken cancellationToken = default, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子文件。
|
||||
@@ -292,17 +326,38 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetName">子资源名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<T> LoadSubAssetAsync<T>(string location, string assetName, CancellationToken cancellationToken = default) where T : Object;
|
||||
UniTask<T> LoadSubAssetAsync<T>(string location, string assetName,
|
||||
CancellationToken cancellationToken = default, string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载所有子文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object;
|
||||
UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 放入预加载对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetObject">预加载对象。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public void PushPreLoadAsset(string location, Object assetObject, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取预加载的实例对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>预加载对象。</returns>
|
||||
public T GetPreLoadAsset<T>(string location, string packageName = "") where T : Object;
|
||||
}
|
||||
}
|
@@ -19,6 +19,7 @@ namespace TEngine
|
||||
}
|
||||
|
||||
private readonly string _tag;
|
||||
private readonly string _packageName; // 指定资源包的名称
|
||||
private ESteps _steps = ESteps.None;
|
||||
private List<AssetOperationHandle> _handles;
|
||||
|
||||
@@ -28,9 +29,10 @@ namespace TEngine
|
||||
public List<TObject> AssetObjects { private set; get; }
|
||||
|
||||
|
||||
public LoadAssetsByTagOperation(string tag)
|
||||
public LoadAssetsByTagOperation(string tag, string packageName)
|
||||
{
|
||||
_tag = tag;
|
||||
_packageName = packageName;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
@@ -45,11 +47,32 @@ namespace TEngine
|
||||
|
||||
if (_steps == ESteps.LoadAssets)
|
||||
{
|
||||
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(_tag);
|
||||
AssetInfo[] assetInfos;
|
||||
if (string.IsNullOrEmpty(_packageName))
|
||||
{
|
||||
assetInfos = YooAssets.GetAssetInfos(_tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(_packageName);
|
||||
assetInfos = package.GetAssetInfos(_tag);
|
||||
}
|
||||
|
||||
_handles = new List<AssetOperationHandle>(assetInfos.Length);
|
||||
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
var handle = YooAssets.LoadAssetAsync(assetInfo);
|
||||
AssetOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(_packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync(assetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(_packageName);
|
||||
handle = package.LoadAssetAsync(assetInfo);
|
||||
}
|
||||
|
||||
_handles.Add(handle);
|
||||
}
|
||||
|
||||
@@ -101,7 +124,7 @@ namespace TEngine
|
||||
SetFinish(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetFinish(bool succeed, string error = "")
|
||||
{
|
||||
Error = error;
|
||||
|
@@ -12,7 +12,7 @@ namespace TEngine
|
||||
private class GameDecryptionServices : IDecryptionServices
|
||||
{
|
||||
private const byte OffSet = 32;
|
||||
|
||||
|
||||
public ulong LoadFromFileOffset(DecryptFileInfo fileInfo)
|
||||
{
|
||||
return OffSet;
|
||||
@@ -25,7 +25,8 @@ namespace TEngine
|
||||
|
||||
public Stream LoadFromStream(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
BundleStream bundleStream =
|
||||
new BundleStream(fileInfo.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
return bundleStream;
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ namespace TEngine
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 默认的分发资源查询服务类
|
||||
/// </summary>
|
||||
@@ -44,40 +45,66 @@ namespace TEngine
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool QueryDeliveryFiles(string packageName, string fileName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 远程文件查询服务类。
|
||||
/// </summary>
|
||||
private class RemoteServices: IRemoteServices
|
||||
private class RemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _defaultHostServer;
|
||||
private readonly string _fallbackHostServer;
|
||||
private string _packageName;
|
||||
|
||||
public RemoteServices()
|
||||
public RemoteServices(string packageName)
|
||||
{
|
||||
_defaultHostServer = SettingsUtils.FrameworkGlobalSettings.HostServerURL;
|
||||
_fallbackHostServer = SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL;
|
||||
_packageName = packageName;
|
||||
}
|
||||
|
||||
|
||||
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
|
||||
|
||||
public string GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
return $"{_defaultHostServer}/{_packageName}/{fileName}";
|
||||
}
|
||||
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
return $"{_defaultHostServer}/{_packageName}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类。
|
||||
/// </summary>
|
||||
public class BuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return BuiltinQueryMgr.FileExists(packageName, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WebGL内置文件查询服务类。WebGL平台不需要内置查询,直接使用远程热更资源。
|
||||
/// </summary>
|
||||
public class WebGLBuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +113,8 @@ namespace TEngine
|
||||
{
|
||||
public const byte KEY = 128;
|
||||
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access,
|
||||
share)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ namespace TEngine
|
||||
#region Propreties
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称。
|
||||
/// 默认资源包名称。
|
||||
/// </summary>
|
||||
public string PackageName { get; set; } = "DefaultPackage";
|
||||
|
||||
@@ -101,8 +101,9 @@ namespace TEngine
|
||||
|
||||
internal override void Shutdown()
|
||||
{
|
||||
ReleasePreLoadAssets(isShutDown: true);
|
||||
#if !UNITY_WEBGL
|
||||
YooAssets.Destroy();
|
||||
YooAssets.Destroy();
|
||||
#endif
|
||||
ResourcePool.Destroy();
|
||||
}
|
||||
@@ -119,6 +120,7 @@ namespace TEngine
|
||||
handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
iter.Dispose();
|
||||
_releaseMaps.Clear();
|
||||
|
||||
@@ -132,10 +134,12 @@ namespace TEngine
|
||||
handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
iter.Dispose();
|
||||
_operationHandlesMaps.Clear();
|
||||
|
||||
_arcCacheTable = new ArcCacheTable<string, AssetOperationHandle>(ARCTableCapacity, OnAddAsset, OnRemoveAsset);
|
||||
|
||||
_arcCacheTable =
|
||||
new ArcCacheTable<string, AssetOperationHandle>(ARCTableCapacity, OnAddAsset, OnRemoveAsset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -204,25 +208,47 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleSync<T>(string location, bool needCache = false) where T : Object
|
||||
private AssetOperationHandle GetHandleSync<T>(string location, bool needCache = false, string packageName = "")
|
||||
where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetSync<T>(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.LoadAssetSync<T>(location);
|
||||
}
|
||||
|
||||
// 缓存key
|
||||
var cacheKey = string.IsNullOrEmpty(packageName) || packageName.Equals(PackageName)
|
||||
? location
|
||||
: $"{packageName}/{location}";
|
||||
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
handle = _arcCacheTable.GetCache(cacheKey);
|
||||
|
||||
if (handle == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadAssetSync<T>(location);
|
||||
}
|
||||
}
|
||||
|
||||
// 对象推入ARC缓存表。
|
||||
_arcCacheTable.PutCache(location, handle);
|
||||
_arcCacheTable.PutCache(cacheKey, handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -231,25 +257,47 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location, bool needCache = false) where T : Object
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location, bool needCache = false, string packageName = "")
|
||||
where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetAsync<T>(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.LoadAssetAsync<T>(location);
|
||||
}
|
||||
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.LoadAssetAsync<T>(location);
|
||||
}
|
||||
|
||||
// 缓存key
|
||||
var cacheKey = string.IsNullOrEmpty(packageName) || packageName.Equals(PackageName)
|
||||
? location
|
||||
: $"{packageName}/{location}";
|
||||
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
handle = _arcCacheTable.GetCache(cacheKey);
|
||||
|
||||
if (handle == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<T>(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<T>(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadAssetAsync<T>(location);
|
||||
}
|
||||
}
|
||||
|
||||
// 对象推入ARC缓存表。
|
||||
_arcCacheTable.PutCache(location, handle);
|
||||
_arcCacheTable.PutCache(cacheKey, handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -276,25 +324,32 @@ namespace TEngine
|
||||
|
||||
_releaseMaps ??= new Dictionary<string, AssetOperationHandle>(ARCTableCapacity);
|
||||
_operationHandlesMaps ??= new Dictionary<string, AssetOperationHandle>(ARCTableCapacity);
|
||||
_arcCacheTable ??= new ArcCacheTable<string, AssetOperationHandle>(ARCTableCapacity, OnAddAsset, OnRemoveAsset);
|
||||
_arcCacheTable ??=
|
||||
new ArcCacheTable<string, AssetOperationHandle>(ARCTableCapacity, OnAddAsset, OnRemoveAsset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源包裹。
|
||||
/// </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
|
||||
//编辑器模式使用。
|
||||
@@ -310,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);
|
||||
}
|
||||
|
||||
@@ -329,7 +384,7 @@ namespace TEngine
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.BuildinQueryServices = new BuiltinQueryServices();
|
||||
createParameters.DeliveryQueryServices = new DefaultDeliveryQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices();
|
||||
createParameters.RemoteServices = new RemoteServices(targetPackageName);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -339,8 +394,11 @@ namespace TEngine
|
||||
YooAssets.SetCacheSystemDisableCacheOnWebGL();
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.BuildinQueryServices = new BuiltinQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices();
|
||||
createParameters.BuildinQueryServices = new WebGLBuiltinQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(targetPackageName);
|
||||
// WebGL运行模式下,直接使用远程热更资源。
|
||||
createParameters.BuildinRootDirectory = SettingsUtils.FrameworkGlobalSettings.HostServerURL;
|
||||
createParameters.SandboxRootDirectory = SettingsUtils.FrameworkGlobalSettings.HostServerURL;
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -401,19 +459,29 @@ namespace TEngine
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查资源是否存在。
|
||||
/// </summary>
|
||||
/// <param name="location">要检查资源的名称。</param>
|
||||
/// <returns>检查资源是否存在的结果。</returns>
|
||||
public HasAssetResult HasAsset(string location)
|
||||
/// <inheritdoc />
|
||||
public HasAssetResult HasAsset(string location, string packageName = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
throw new GameFrameworkException("Asset name is invalid.");
|
||||
}
|
||||
|
||||
AssetInfo assetInfo = YooAssets.GetAssetInfo(location);
|
||||
AssetInfo assetInfo;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
assetInfo = YooAssets.GetAssetInfo(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
if (package == null)
|
||||
{
|
||||
throw new GameFrameworkException($"The package does not exist. Package Name :{packageName}");
|
||||
}
|
||||
|
||||
assetInfo = package.GetAssetInfo(location);
|
||||
}
|
||||
|
||||
if (!CheckLocationValid(location))
|
||||
{
|
||||
@@ -444,74 +512,95 @@ namespace TEngine
|
||||
|
||||
#region 资源信息
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public bool IsNeedDownloadFromRemote(string location)
|
||||
/// <inheritdoc />
|
||||
public bool IsNeedDownloadFromRemote(string location, string packageName = "")
|
||||
{
|
||||
return YooAssets.IsNeedDownloadFromRemote(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.IsNeedDownloadFromRemote(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.IsNeedDownloadFromRemote(location);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
|
||||
/// <inheritdoc />
|
||||
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo, string packageName = "")
|
||||
{
|
||||
return YooAssets.IsNeedDownloadFromRemote(assetInfo);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.IsNeedDownloadFromRemote(assetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.IsNeedDownloadFromRemote(assetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tag">资源标签。</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
public AssetInfo[] GetAssetInfos(string tag)
|
||||
/// <inheritdoc />
|
||||
public AssetInfo[] GetAssetInfos(string tag, string packageName = "")
|
||||
{
|
||||
return YooAssets.GetAssetInfos(tag);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.GetAssetInfos(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.GetAssetInfos(tag);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tags">资源标签列表。</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
public AssetInfo[] GetAssetInfos(string[] tags)
|
||||
/// <inheritdoc />
|
||||
public AssetInfo[] GetAssetInfos(string[] tags, string packageName = "")
|
||||
{
|
||||
return YooAssets.GetAssetInfos(tags);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.GetAssetInfos(tags);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.GetAssetInfos(tags);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <returns>资源信息。</returns>
|
||||
public AssetInfo GetAssetInfo(string location)
|
||||
/// <inheritdoc />
|
||||
public AssetInfo GetAssetInfo(string location, string packageName = "")
|
||||
{
|
||||
return YooAssets.GetAssetInfo(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.GetAssetInfo(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.GetAssetInfo(location);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查资源定位地址是否有效。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public bool CheckLocationValid(string location)
|
||||
/// <inheritdoc />
|
||||
public bool CheckLocationValid(string location, string packageName = "")
|
||||
{
|
||||
return YooAssets.CheckLocationValid(location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.CheckLocationValid(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.CheckLocationValid(location);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false,
|
||||
string packageName = "") where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -519,7 +608,7 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache, packageName);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
@@ -528,30 +617,26 @@ namespace TEngine
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
AssetReference.BindAssetReference(gameObject, handle, location, packageName: packageName);
|
||||
}
|
||||
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false,
|
||||
string packageName = "")
|
||||
where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -559,7 +644,7 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache, packageName: packageName);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
@@ -568,31 +653,27 @@ namespace TEngine
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
AssetReference.BindAssetReference(gameObject, handle, location, packageName: packageName);
|
||||
}
|
||||
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false,
|
||||
string packageName = "") where T : Object
|
||||
{
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
handle = GetHandleSync<T>(location, needCache, packageName: packageName);
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
@@ -604,31 +685,26 @@ namespace TEngine
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
AssetReference.BindAssetReference(gameObject, handle, location, packageName: packageName);
|
||||
}
|
||||
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle,
|
||||
bool needCache = false, string packageName = "") where T : Object
|
||||
{
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
handle = GetHandleSync<T>(location, needCache, packageName: packageName);
|
||||
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -641,81 +717,78 @@ namespace TEngine
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
AssetReference.BindAssetReference(gameObject, handle, location, packageName: packageName);
|
||||
}
|
||||
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false,
|
||||
string packageName = "") where T : Object
|
||||
{
|
||||
return GetHandleSync<T>(location, needCache);
|
||||
return GetHandleSync<T>(location, needCache, packageName: packageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false,
|
||||
string packageName = "") where T : Object
|
||||
{
|
||||
return GetHandleAsync<T>(location, needCache);
|
||||
return GetHandleAsync<T>(location, needCache, packageName: packageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型。</typeparam>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : Object
|
||||
/// <inheritdoc />
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location, string packageName = "")
|
||||
where TObject : Object
|
||||
{
|
||||
return YooAssets.LoadSubAssetsSync<TObject>(location: location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.LoadSubAssetsSync<TObject>(location: location);
|
||||
}
|
||||
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.LoadSubAssetsSync<TObject>(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子资源对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型。</typeparam>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : Object
|
||||
/// <inheritdoc />
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location, string packageName = "")
|
||||
where TObject : Object
|
||||
{
|
||||
return YooAssets.LoadSubAssetsAsync<TObject>(location: location);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.LoadSubAssetsAsync<TObject>(location: location);
|
||||
}
|
||||
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.LoadSubAssetsAsync<TObject>(location: location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo)
|
||||
/// <inheritdoc />
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo, string packageName = "")
|
||||
{
|
||||
return YooAssets.LoadSubAssetsSync(assetInfo);
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
return YooAssets.LoadSubAssetsSync(assetInfo);
|
||||
}
|
||||
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
return package.LoadSubAssetsSync(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
public async UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object
|
||||
/// <inheritdoc />
|
||||
public async UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag, string packageName = "")
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
LoadAssetsByTagOperation<T> operation = new LoadAssetsByTagOperation<T>(assetTag);
|
||||
LoadAssetsByTagOperation<T> operation = new LoadAssetsByTagOperation<T>(assetTag, packageName);
|
||||
YooAssets.StartOperation(operation);
|
||||
await operation.ToUniTask();
|
||||
List<T> assetObjects = operation.AssetObjects;
|
||||
@@ -723,19 +796,14 @@ namespace TEngine
|
||||
return assetObjects;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源实例。
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object
|
||||
/// <inheritdoc />
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, bool needCache = false, string packageName = "") where T : Object
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location, needCache);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location, needCache, packageName: packageName);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken)
|
||||
.SuppressCancellationThrow();
|
||||
|
||||
if (cancelOrFailed)
|
||||
{
|
||||
@@ -749,32 +817,31 @@ namespace TEngine
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
AssetReference.BindAssetReference(gameObject, handle, location, packageName: packageName);
|
||||
}
|
||||
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
/// <inheritdoc />
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location,
|
||||
CancellationToken cancellationToken = default, bool needCache = false, string packageName = "")
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location, needCache);
|
||||
AssetOperationHandle handle =
|
||||
LoadAssetAsyncHandle<GameObject>(location, needCache, packageName: packageName);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken)
|
||||
.SuppressCancellationThrow();
|
||||
|
||||
if (cancelOrFailed)
|
||||
{
|
||||
@@ -784,22 +851,18 @@ namespace TEngine
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
AssetReference.BindAssetReference(gameObject, handle, location, packageName: packageName);
|
||||
}
|
||||
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
/// <inheritdoc />
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent,
|
||||
CancellationToken cancellationToken = default, bool needCache = false, string packageName = "")
|
||||
{
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
GameObject gameObject =
|
||||
await LoadGameObjectAsync(location, cancellationToken, needCache, packageName: packageName);
|
||||
if (parent != null)
|
||||
{
|
||||
gameObject.transform.SetParent(parent);
|
||||
@@ -812,71 +875,137 @@ namespace TEngine
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载原生文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>原生文件资源实例操作句柄。</returns>
|
||||
/// <remarks>需要自行释放资源句柄(RawFileOperationHandle)。</remarks>
|
||||
public async UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location, CancellationToken cancellationToken = default)
|
||||
/// <inheritdoc />
|
||||
public async UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location,
|
||||
CancellationToken cancellationToken = default, string packageName = "")
|
||||
{
|
||||
RawFileOperationHandle handle = YooAssets.LoadRawFileAsync(location);
|
||||
RawFileOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadRawFileAsync(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadRawFileAsync(location);
|
||||
}
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken)
|
||||
.SuppressCancellationThrow();
|
||||
|
||||
return cancelOrFailed ? null : handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetName">子资源名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
public async UniTask<T> LoadSubAssetAsync<T>(string location, string assetName, CancellationToken cancellationToken = default) where T : Object
|
||||
/// <inheritdoc />
|
||||
public async UniTask<T> LoadSubAssetAsync<T>(string location, string assetName,
|
||||
CancellationToken cancellationToken = default, string packageName = "") where T : Object
|
||||
{
|
||||
var assetInfo = GetAssetInfo(location);
|
||||
var assetInfo = GetAssetInfo(location, packageName: packageName);
|
||||
if (assetInfo == null)
|
||||
{
|
||||
Log.Fatal($"AssetsInfo is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
SubAssetsOperationHandle handle = YooAssets.LoadSubAssetsAsync(assetInfo);
|
||||
SubAssetsOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadSubAssetsAsync(assetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadSubAssetsAsync(assetInfo);
|
||||
}
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken)
|
||||
.SuppressCancellationThrow();
|
||||
|
||||
handle.Dispose();
|
||||
|
||||
return cancelOrFailed ? null : handle.GetSubAssetObject<T>(assetName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
public async UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object
|
||||
/// <inheritdoc />
|
||||
public async UniTask<T[]> LoadAllSubAssetAsync<T>(string location,
|
||||
CancellationToken cancellationToken = default, string packageName = "") where T : Object
|
||||
{
|
||||
var assetInfo = GetAssetInfo(location);
|
||||
var assetInfo = GetAssetInfo(location, packageName: packageName);
|
||||
if (assetInfo == null)
|
||||
{
|
||||
Log.Fatal($"AssetsInfo is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
SubAssetsOperationHandle handle = YooAssets.LoadSubAssetsAsync(assetInfo);
|
||||
SubAssetsOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadSubAssetsAsync(assetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadSubAssetsAsync(assetInfo);
|
||||
}
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken)
|
||||
.SuppressCancellationThrow();
|
||||
|
||||
handle.Dispose();
|
||||
|
||||
return cancelOrFailed ? null : handle.GetSubAssetObjects<T>();
|
||||
}
|
||||
|
||||
#region 预加载
|
||||
|
||||
private readonly Dictionary<string, Object> _preLoadMaps = new Dictionary<string, Object>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void PushPreLoadAsset(string location, Object assetObject, string packageName = "")
|
||||
{
|
||||
var cacheKey = string.IsNullOrEmpty(packageName) || packageName.Equals(PackageName)
|
||||
? location
|
||||
: $"{packageName}/{location}";
|
||||
if (_preLoadMaps.ContainsKey(cacheKey))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_preLoadMaps.Add(cacheKey, assetObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public T GetPreLoadAsset<T>(string location, string packageName = "") where T : Object
|
||||
{
|
||||
var cacheKey = string.IsNullOrEmpty(packageName) || packageName.Equals(PackageName)
|
||||
? location
|
||||
: $"{packageName}/{location}";
|
||||
if (_preLoadMaps.TryGetValue(cacheKey, out Object assetObject))
|
||||
{
|
||||
return assetObject as T;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
private void ReleasePreLoadAssets(bool isShutDown = false)
|
||||
{
|
||||
if (!isShutDown)
|
||||
{
|
||||
using var iter = _preLoadMaps.GetEnumerator();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
var assetObject = iter.Current.Value;
|
||||
if (assetObject != null)
|
||||
{
|
||||
Object.Destroy(assetObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_preLoadMaps.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
@@ -231,19 +230,23 @@ 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>
|
||||
/// 获取当前资源包版本。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源包版本。</returns>
|
||||
public string GetPackageVersion()
|
||||
public string GetPackageVersion(string customPackageName = "")
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(this.packageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
if (package == null)
|
||||
{
|
||||
return string.Empty;
|
||||
@@ -257,10 +260,14 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="appendTimeTicks">请求URL是否需要带时间戳。</param>
|
||||
/// <param name="timeout">超时时间。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>请求远端包裹的最新版本操作句柄。</returns>
|
||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = false, int timeout = 60)
|
||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = false, int timeout = 60,
|
||||
string customPackageName = "")
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(this.packageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.UpdatePackageVersionAsync(appendTimeTicks, timeout);
|
||||
}
|
||||
|
||||
@@ -270,37 +277,79 @@ namespace TEngine
|
||||
/// <param name="packageVersion">更新的包裹版本</param>
|
||||
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion,
|
||||
bool autoSaveVersion = true, int timeout = 60, string customPackageName = "")
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(this.packageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件。
|
||||
/// </summary>
|
||||
public ResourceDownloaderOperation CreateResourceDownloader()
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(string customPackageName = "")
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
Downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||
return Downloader;
|
||||
if (string.IsNullOrEmpty(customPackageName))
|
||||
{
|
||||
var package = YooAssets.GetPackage(this.packageName);
|
||||
Downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||
return Downloader;
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(customPackageName);
|
||||
Downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||
return Downloader;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync(string customPackageName = "")
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(this.packageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.ClearUnusedCacheFilesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理沙盒路径。
|
||||
/// </summary>
|
||||
public void ClearSandbox()
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public void ClearSandbox(string customPackageName = "")
|
||||
{
|
||||
// YooAssets.ClearSandbox();
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(this.packageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
package.ClearPackageSandbox();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -341,10 +390,11 @@ namespace TEngine
|
||||
private void Update()
|
||||
{
|
||||
m_LastUnloadUnusedAssetsOperationElapseSeconds += GameTime.unscaledDeltaTime;
|
||||
if (m_AsyncOperation == null &&
|
||||
(m_ForceUnloadUnusedAssets ||
|
||||
m_LastUnloadUnusedAssetsOperationElapseSeconds >= maxUnloadUnusedAssetsInterval ||
|
||||
m_PreorderUnloadUnusedAssets && m_LastUnloadUnusedAssetsOperationElapseSeconds >= minUnloadUnusedAssetsInterval))
|
||||
if (m_AsyncOperation == null &&
|
||||
(m_ForceUnloadUnusedAssets ||
|
||||
m_LastUnloadUnusedAssetsOperationElapseSeconds >= maxUnloadUnusedAssetsInterval ||
|
||||
m_PreorderUnloadUnusedAssets &&
|
||||
m_LastUnloadUnusedAssetsOperationElapseSeconds >= minUnloadUnusedAssetsInterval))
|
||||
{
|
||||
Log.Info("Unload unused assets...");
|
||||
m_ForceUnloadUnusedAssets = false;
|
||||
@@ -370,10 +420,11 @@ namespace TEngine
|
||||
/// 检查资源是否存在。
|
||||
/// </summary>
|
||||
/// <param name="location">要检查资源的名称。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>检查资源是否存在的结果。</returns>
|
||||
public HasAssetResult HasAsset(string location)
|
||||
public HasAssetResult HasAsset(string location, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.HasAsset(location);
|
||||
return m_ResourceManager.HasAsset(location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -389,59 +440,65 @@ namespace TEngine
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
public bool IsNeedDownloadFromRemote(string location)
|
||||
public bool IsNeedDownloadFromRemote(string location, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.IsNeedDownloadFromRemote(location);
|
||||
return m_ResourceManager.IsNeedDownloadFromRemote(location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
|
||||
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.IsNeedDownloadFromRemote(assetInfo);
|
||||
return m_ResourceManager.IsNeedDownloadFromRemote(assetInfo, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="resTag">资源标签。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
public AssetInfo[] GetAssetInfos(string resTag)
|
||||
public AssetInfo[] GetAssetInfos(string resTag, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.GetAssetInfos(resTag);
|
||||
return m_ResourceManager.GetAssetInfos(resTag, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tags">资源标签列表。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
public AssetInfo[] GetAssetInfos(string[] tags)
|
||||
public AssetInfo[] GetAssetInfos(string[] tags, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.GetAssetInfos(tags);
|
||||
return m_ResourceManager.GetAssetInfos(tags, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息。</returns>
|
||||
public AssetInfo GetAssetInfo(string location)
|
||||
public AssetInfo GetAssetInfo(string location, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.GetAssetInfo(location);
|
||||
return m_ResourceManager.GetAssetInfo(location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查资源定位地址是否有效。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public bool CheckLocationValid(string location)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public bool CheckLocationValid(string location, string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.CheckLocationValid(location);
|
||||
return m_ResourceManager.CheckLocationValid(location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -450,11 +507,13 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance, needCache);
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance, needCache, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -464,11 +523,14 @@ namespace TEngine
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
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);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -477,11 +539,13 @@ namespace TEngine
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle, needCache);
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle, needCache, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -491,11 +555,14 @@ namespace TEngine
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
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);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -504,10 +571,13 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="callback">回调函数。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null, bool needCache = false) where T : UnityEngine.Object
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null,
|
||||
bool needCache = false, string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
AssetOperationHandle handle =
|
||||
m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache, packageName: customPackageName);
|
||||
|
||||
handle.Completed += callback;
|
||||
}
|
||||
@@ -517,11 +587,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location, needCache);
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location, needCache, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -529,11 +601,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache, packageName: customPackageName);
|
||||
}
|
||||
|
||||
|
||||
@@ -542,9 +616,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型</typeparam>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location, string customPackageName = "")
|
||||
where TObject : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadSubAssetsSync<TObject>(location: location);
|
||||
return m_ResourceManager.LoadSubAssetsSync<TObject>(location: location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -552,36 +628,41 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型</typeparam>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location, string customPackageName = "")
|
||||
where TObject : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadSubAssetsAsync<TObject>(location: location);
|
||||
return m_ResourceManager.LoadSubAssetsAsync<TObject>(location: location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(string location)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(string location, string customPackageName = "")
|
||||
{
|
||||
var assetInfo = GetAssetInfo(location);
|
||||
var assetInfo = GetAssetInfo(location, customPackageName: customPackageName);
|
||||
if (assetInfo == null)
|
||||
{
|
||||
Log.Fatal($"AssetsInfo is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
return m_ResourceManager.LoadSubAssetsSync(assetInfo);
|
||||
return m_ResourceManager.LoadSubAssetsSync(assetInfo, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
public async UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object
|
||||
public async UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag, string customPackageName = "")
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetsByTagAsync<T>(assetTag);
|
||||
return await m_ResourceManager.LoadAssetsByTagAsync<T>(assetTag, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -591,11 +672,15 @@ namespace TEngine
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, bool needCache = false, string customPackageName = "")
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance, needCache);
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -604,10 +689,13 @@ namespace TEngine
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location,
|
||||
CancellationToken cancellationToken = default, bool needCache = false, string customPackageName = "")
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -617,10 +705,13 @@ namespace TEngine
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent,
|
||||
CancellationToken cancellationToken = default, bool needCache = false, string customPackageName = "")
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken, needCache);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -628,10 +719,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
public async UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location,
|
||||
CancellationToken cancellationToken = default, string customPackageName = "")
|
||||
{
|
||||
return await m_ResourceManager.LoadRawAssetAsync(location, cancellationToken);
|
||||
return await m_ResourceManager.LoadRawAssetAsync(location, cancellationToken,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -640,11 +734,14 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetName">子资源名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
public async UniTask<T> LoadSubAssetAsync<T>(string location, string assetName, CancellationToken cancellationToken = default) where T : UnityEngine.Object
|
||||
public async UniTask<T> LoadSubAssetAsync<T>(string location, string assetName,
|
||||
CancellationToken cancellationToken = default, string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadSubAssetAsync<T>(location, assetName, cancellationToken);
|
||||
return await m_ResourceManager.LoadSubAssetAsync<T>(location, assetName, cancellationToken,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -652,11 +749,41 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
public async UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : UnityEngine.Object
|
||||
public async UniTask<T[]> LoadAllSubAssetAsync<T>(string location,
|
||||
CancellationToken cancellationToken = default, string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAllSubAssetAsync<T>(location, cancellationToken);
|
||||
return await m_ResourceManager.LoadAllSubAssetAsync<T>(location, cancellationToken,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
#region 预加载
|
||||
|
||||
/// <summary>
|
||||
/// 放入预加载对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetObject">预加载对象。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public void PushPreLoadAsset(string location, UnityEngine.Object assetObject, string customPackageName = "")
|
||||
{
|
||||
m_ResourceManager.PushPreLoadAsset(location, assetObject, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取预加载的实例对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>预加载对象。</returns>
|
||||
public T GetPreLoadAsset<T>(string location, string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.GetPreLoadAsset<T>(location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -44,7 +44,7 @@ namespace TEngine
|
||||
public UIBase Parent => parent;
|
||||
|
||||
/// <summary>
|
||||
/// 自动逸数据集。
|
||||
/// 自定义数据集。
|
||||
/// </summary>
|
||||
protected System.Object[] userDatas;
|
||||
|
||||
@@ -93,6 +93,20 @@ namespace TEngine
|
||||
/// </summary>
|
||||
protected bool m_updateListValid = false;
|
||||
|
||||
private ComponentAutoBindTool _autoBindTool;
|
||||
|
||||
protected ComponentAutoBindTool AutoBindTool
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_autoBindTool == null && gameObject != null)
|
||||
{
|
||||
_autoBindTool = gameObject.GetComponent<ComponentAutoBindTool>();
|
||||
}
|
||||
return _autoBindTool;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码自动生成绑定。
|
||||
/// </summary>
|
||||
@@ -243,7 +257,7 @@ namespace TEngine
|
||||
|
||||
/// <summary>
|
||||
/// 创建UIWidget通过父UI位置节点。
|
||||
/// <remarks>因为资源示例已经存在父物体所以不需要异步。</remarks>
|
||||
/// <remarks>因为资源实例已经存在父物体所以不需要异步。</remarks>
|
||||
/// </summary>
|
||||
/// <param name="goPath">父UI位置节点。</param>
|
||||
/// <param name="visible">是否可见。</param>
|
||||
@@ -264,7 +278,7 @@ namespace TEngine
|
||||
|
||||
/// <summary>
|
||||
/// 创建UIWidget通过父UI位置节点。
|
||||
/// <remarks>因为资源示例已经存在父物体所以不需要异步。</remarks>
|
||||
/// <remarks>因为资源实例已经存在父物体所以不需要异步。</remarks>
|
||||
/// </summary>
|
||||
/// <param name="parentTrans"></param>
|
||||
/// <param name="goPath">父UI位置节点。</param>
|
||||
@@ -284,7 +298,7 @@ namespace TEngine
|
||||
|
||||
/// <summary>
|
||||
/// 创建UIWidget通过游戏物体。
|
||||
/// <remarks>因为资源示例已经存在父物体所以不需要异步。</remarks>
|
||||
/// <remarks>因为资源实例已经存在父物体所以不需要异步。</remarks>
|
||||
/// </summary>
|
||||
/// <param name="goRoot">游戏物体。</param>
|
||||
/// <param name="visible">是否可见。</param>
|
||||
@@ -326,7 +340,7 @@ namespace TEngine
|
||||
public async UniTask<T> CreateWidgetByPathAsync<T>(Transform parentTrans, string assetLocation, bool visible = true) where T : UIWidget, new()
|
||||
{
|
||||
GameObject goInst = await GameModule.Resource.LoadAssetAsync<GameObject>(assetLocation, gameObject.GetCancellationTokenOnDestroy());
|
||||
goInst.transform.SetParent(parentTrans);
|
||||
goInst.transform.SetParent(parentTrans, false);
|
||||
return CreateWidget<T>(goInst, visible);
|
||||
}
|
||||
|
||||
@@ -456,7 +470,7 @@ namespace TEngine
|
||||
{
|
||||
if (prefab == null)
|
||||
{
|
||||
tmpT = CreateWidgetByPath<T>(parentTrans, assetPath);
|
||||
tmpT = await CreateWidgetByPathAsync<T>(parentTrans, assetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "216d09f7b65fadc5d8fcd0bba82e5ac50ca58f06"
|
||||
"hash": "febff1c658fa9d76726f3aa25f26ec6d35c1e2e6"
|
||||
},
|
||||
"com.cysharp.unitask": {
|
||||
"version": "file:UniTask",
|
||||
|
Reference in New Issue
Block a user