Compare commits

..

11 Commits

Author SHA1 Message Date
ALEXTANG
8321e77421 Merge pull request #56 from AlanWeekend/main
fixed:looplistitem重复赋值问题
2023-11-13 13:09:25 +08:00
Weekend
1b6f80952e fixed:looplistitem重复赋值问题
fixed:looplistitem重复赋值问题
2023-11-12 19:49:02 +08:00
ALEXTANG
b52e655c30 更正错误注释
更正错误注释
2023-11-07 11:04:59 +08:00
ALEXTANG
8c0df95626 修正CancellationTokenSource重复Dispose问题
修正CancellationTokenSource重复Dispose问题
2023-11-03 16:58:42 +08:00
ALEXTANG
0d1e308f1c Update ResourceModule.cs 2023-11-03 10:07:25 +08:00
ALEXTANG
f8797538fd Update UIBase.cs 2023-11-03 09:55:36 +08:00
ALEXTANG
fe4e168041 Update ProcedurePreload.cs 2023-11-02 15:35:01 +08:00
ALEXTANG
8e9047d3a3 基于资源框架实现对标签WEBGL_PRELOAD、PRELOAD的预加载。 接口GameModule.Resource.GetPreLoadAsset<T>(location)
基于资源框架实现对标签WEBGL_PRELOAD、PRELOAD的预加载。 接口GameModule.Resource.GetPreLoadAsset<T>(location)
2023-11-02 13:16:05 +08:00
ALEXTANG
04bfaeccc8 示例CLI工作流
示例CLI工作流
2023-11-02 12:55:27 +08:00
ALEXTANG
d66c823c15 更新优化启用UpdateData时UILoadUpdate时序的问题
更新优化启用UpdateData时UILoadUpdate时序的问题
2023-11-02 11:48:47 +08:00
ALEXTANG
0ec1424f0a 升级HybridCLR 4.0.11=>4.0.12
升级HybridCLR 4.0.11=>4.0.12
2023-11-02 11:12:56 +08:00
20 changed files with 368 additions and 86 deletions

View 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
View 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

View File

@@ -42,8 +42,16 @@ public class ConfigSystem : Singleton<ConfigSystem>
/// <returns>ByteBuf</returns> /// <returns>ByteBuf</returns>
private ByteBuf LoadByteBuf(string file) private ByteBuf LoadByteBuf(string file)
{ {
var textAssets = GameModule.Resource.LoadAsset<TextAsset>(file); TextAsset textAsset = null;
byte[] ret = textAssets.bytes; textAsset = GameModule.Resource.GetPreLoadAsset<TextAsset>(file);
return new ByteBuf(ret); if (textAsset != null)
{
return new ByteBuf(textAsset.bytes);
}
else
{
textAsset = GameModule.Resource.LoadAsset<TextAsset>(file);
return new ByteBuf(textAsset.bytes);
}
} }
} }

View File

@@ -65,7 +65,7 @@ namespace GameLogic
base.AdjustItemNum(n, datas, funcItem); base.AdjustItemNum(n, datas, funcItem);
m_tpFuncItem = funcItem; m_tpFuncItem = funcItem;
LoopRectView.SetListItemCount(n); LoopRectView.SetListItemCount(n);
LoopRectView.RefreshAllShownItem(); // LoopRectView.RefreshAllShownItem();
m_tpFuncItem = null; m_tpFuncItem = null;
} }

View File

@@ -38,10 +38,15 @@ namespace GameMain
m_btnClear.gameObject.SetActive(true); m_btnClear.gameObject.SetActive(true);
} }
public override void RegisterEvent()
{
base.RegisterEvent();
AddUIEvent(RuntimeId.ToRuntimeId("RefreshVersion"),RefreshVersion);
}
public override void OnRefresh() public override void OnRefresh()
{ {
base.OnRefresh(); base.OnRefresh();
RefreshVersion();
} }
#region #region

View File

@@ -60,8 +60,8 @@ namespace GameMain
{ {
//热更新阶段文本初始化 //热更新阶段文本初始化
LoadText.Instance.InitConfigData(null); LoadText.Instance.InitConfigData(null);
//热更新UI初始化
UILoadMgr.Initialize(); GameEvent.Send(RuntimeId.ToRuntimeId("RefreshVersion"));
EPlayMode playMode = GameModule.Resource.PlayMode; EPlayMode playMode = GameModule.Resource.PlayMode;

View File

@@ -15,6 +15,9 @@ namespace GameMain
{ {
base.OnEnter(procedureOwner); base.OnEnter(procedureOwner);
//热更新UI初始化
UILoadMgr.Initialize();
// 语言配置:设置当前使用的语言,如果不设置,则默认使用操作系统语言 // 语言配置:设置当前使用的语言,如果不设置,则默认使用操作系统语言
InitLanguageSettings(); InitLanguageSettings();

View File

@@ -16,23 +16,23 @@ namespace GameMain
{ {
private float _progress = 0f; 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; 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) protected override void OnEnter(ProcedureOwner procedureOwner)
{ {
base.OnEnter(procedureOwner); base.OnEnter(procedureOwner);
m_LoadedFlag.Clear(); _loadedFlag.Clear();
if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode) 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)); 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); 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) 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)); UILoadMgr.Show(UIDefine.UILoadUpdate, Utility.Text.Format(LoadText.Instance.Label_Load_Load_Progress, (float)loadCount / totalCount * 100));
} }
@@ -87,7 +87,7 @@ namespace GameMain
return; return;
} }
if (m_InitConfigXml == false) if (_hadInitConfigXml == false)
{ {
return; return;
} }
@@ -116,13 +116,13 @@ namespace GameMain
await UniTask.Delay(TimeSpan.FromSeconds(2.5f)); await UniTask.Delay(TimeSpan.FromSeconds(2.5f));
if (m_needProLoadConfig) if (_needProLoadConfig)
{ {
LoadAllConfig(); LoadAllConfig();
} }
else else
{ {
m_InitConfigXml = true; _hadInitConfigXml = true;
} }
} }
@@ -130,14 +130,27 @@ namespace GameMain
{ {
if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode) if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode)
{ {
m_InitConfigXml = true; _hadInitConfigXml = true;
return; 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) private void LoadConfig(string configName)
{ {
m_LoadedFlag.Add(configName, false); _loadedFlag.Add(configName, false);
GameModule.Resource.LoadAssetAsync<TextAsset>(configName, OnLoadSuccess); GameModule.Resource.LoadAssetAsync<TextAsset>(configName, OnLoadSuccess);
} }
@@ -147,10 +160,11 @@ namespace GameMain
{ {
return; return;
} }
var location = assetOperationHandle.GetAssetInfo().Address;
var name = assetOperationHandle.GetAssetInfo().Address; _loadedFlag[location] = true;
m_LoadedFlag[name] = true; GameModule.Resource.PushPreLoadAsset(location, assetOperationHandle.AssetObject);
Log.Info("Load config '{0}' OK.", name); Log.Info("Load config '{0}' OK.", location);
assetOperationHandle.Dispose();
} }
} }
} }

View File

@@ -22,7 +22,7 @@ namespace GameMain
base.OnEnter(procedureOwner); base.OnEnter(procedureOwner);
UILoadMgr.Show(UIDefine.UILoadUpdate,$"更新静态版本文件..."); UILoadMgr.Show(UIDefine.UILoadUpdate, $"更新静态版本文件...");
//检查设备是否能够访问互联网 //检查设备是否能够访问互联网
if (Application.internetReachability == NetworkReachability.NotReachable) if (Application.internetReachability == NetworkReachability.NotReachable)
@@ -34,6 +34,7 @@ namespace GameMain
GetStaticVersion().Forget, GetStaticVersion().Forget,
() => { ChangeState<ProcedureInitResources>(procedureOwner); }); () => { ChangeState<ProcedureInitResources>(procedureOwner); });
} }
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng); UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng);
// 用户尝试更新静态版本。 // 用户尝试更新静态版本。
@@ -49,6 +50,8 @@ namespace GameMain
var operation = GameModule.Resource.UpdatePackageVersionAsync(); var operation = GameModule.Resource.UpdatePackageVersionAsync();
try
{
await operation.ToUniTask(); await operation.ToUniTask();
if (operation.Status == EOperationStatus.Succeed) if (operation.Status == EOperationStatus.Succeed)
@@ -60,12 +63,22 @@ namespace GameMain
} }
else else
{ {
Log.Error(operation.Error); OnGetStaticVersionError(operation.Error);
}
}
catch (Exception e)
{
OnGetStaticVersionError(e.Message);
}
}
UILoadTip.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{operation.Error}</color>", MessageShowType.TwoButton, private void OnGetStaticVersionError(string error)
{
Log.Error(error);
UILoadTip.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{error}</color>", MessageShowType.TwoButton,
LoadStyle.StyleEnum.Style_Retry LoadStyle.StyleEnum.Style_Retry
, () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit); , () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit);
} }
} }
}
} }

View File

@@ -14,6 +14,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
ShowPackageView: 0 ShowPackageView: 0
EnableAddressable: 1 EnableAddressable: 1
LocationToLower: 0
IncludeAssetGUID: 0
UniqueBundleName: 0 UniqueBundleName: 0
ShowEditorAlias: 0 ShowEditorAlias: 0
Packages: Packages:
@@ -78,7 +80,7 @@ MonoBehaviour:
AddressRuleName: AddressByFileName AddressRuleName: AddressByFileName
PackRuleName: PackDirectory PackRuleName: PackDirectory
FilterRuleName: CollectAll FilterRuleName: CollectAll
AssetTags: AssetTags: WEBGL_PRELOAD
UserData: UserData:
- GroupName: DLL - GroupName: DLL
GroupDesc: "\u4EE3\u7801" GroupDesc: "\u4EE3\u7801"

View File

@@ -4,7 +4,7 @@ using TEngine.Editor;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
public static class BuildAssetsCommand public static class BuildDLLCommand
{ {
private const string EnableHybridClrScriptingDefineSymbol = "ENABLE_HYBRIDCLR"; private const string EnableHybridClrScriptingDefineSymbol = "ENABLE_HYBRIDCLR";
@@ -35,6 +35,12 @@ public static class BuildAssetsCommand
CopyAOTHotUpdateDlls(target); CopyAOTHotUpdateDlls(target);
} }
public static void BuildAndCopyDlls(BuildTarget target)
{
CompileDllCommand.CompileDll(target);
CopyAOTHotUpdateDlls(target);
}
public static void CopyAOTHotUpdateDlls(BuildTarget target) public static void CopyAOTHotUpdateDlls(BuildTarget target)
{ {
CopyAOTAssembliesToAssetPath(); CopyAOTAssembliesToAssetPath();

View File

@@ -1,41 +1,118 @@
using UnityEditor; using System;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine; using UnityEngine;
using YooAsset.Editor; using YooAsset.Editor;
using BuildResult = UnityEditor.Build.Reporting.BuildResult;
namespace TEngine namespace TEngine
{ {
/// <summary> /// <summary>
/// 打包工具类。 /// 打包工具类。
/// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包详见CommandLineReader.cs example1</remarks> /// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包以及CLI工作流详见CommandLineReader.cs example1</remarks>
/// </summary> /// </summary>
public static class ReleaseTools 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 Errorplatform is null");
return;
}
BuildTarget target = GetBuildTarget(platform);
BuildDLLCommand.BuildAndCopyDlls(target);
}
public static void BuildAssetBundle()
{ {
string outputRoot = CommandLineReader.GetCustomArgument("outputRoot"); string outputRoot = CommandLineReader.GetCustomArgument("outputRoot");
BuildTarget target = BuildTarget.StandaloneWindows64; if (string.IsNullOrEmpty(outputRoot))
BuildInternal(target,outputRoot); {
Debug.LogError($"Build Asset Bundle ErroroutputRoot is null");
return;
}
string packageVersion = CommandLineReader.GetCustomArgument("packageVersion");
if (string.IsNullOrEmpty(packageVersion))
{
Debug.LogError($"Build Asset Bundle ErrorpackageVersion is null");
return;
}
string platform = CommandLineReader.GetCustomArgument("platform");
if (string.IsNullOrEmpty(platform))
{
Debug.LogError($"Build Asset Bundle Errorplatform is null");
return;
}
BuildTarget target = GetBuildTarget(platform);
BuildInternal(target, outputRoot);
Debug.LogWarning($"Start BuildPackage BuildTarget:{target} outputPath:{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}"); Debug.Log($"开始构建 : {buildTarget}");
BuildParameters.SBPBuildParameters sbpBuildParameters = new BuildParameters.SBPBuildParameters();
sbpBuildParameters.WriteLinkXML = true;
// 构建参数 // 构建参数
BuildParameters buildParameters = new BuildParameters(); BuildParameters buildParameters = new BuildParameters();
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot(); buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
buildParameters.BuildOutputRoot = outputRoot;//AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = outputRoot; //AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildTarget = buildTarget; buildParameters.BuildTarget = buildTarget;
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline; buildParameters.BuildPipeline = EBuildPipeline.ScriptableBuildPipeline;
buildParameters.BuildMode = EBuildMode.ForceRebuild; buildParameters.BuildMode = EBuildMode.IncrementalBuild;
buildParameters.PackageName = "DefaultPackage"; buildParameters.PackageName = "DefaultPackage";
buildParameters.PackageVersion = "1.0"; buildParameters.PackageVersion = packageVersion;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule(); buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule();
buildParameters.CompressOption = ECompressOption.LZ4; buildParameters.CompressOption = ECompressOption.LZMA;
buildParameters.OutputNameStyle = EOutputNameStyle.HashName; buildParameters.OutputNameStyle = EOutputNameStyle.HashName;
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.None; buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.ClearAndCopyAll;
buildParameters.SBPParameters = sbpBuildParameters;
// 执行构建 // 执行构建
AssetBundleBuilder builder = new AssetBundleBuilder(); AssetBundleBuilder builder = new AssetBundleBuilder();
@@ -50,15 +127,66 @@ namespace TEngine
} }
} }
// 从构建命令里获取参数示例 [MenuItem("TEngine/Build/一键打包Windows", false, 30)]
private static string GetBuildPackageName() public static void AutomationBuild()
{ {
foreach (string arg in System.Environment.GetCommandLineArgs()) BuildDLLCommand.BuildAndCopyDlls(BuildTarget.StandaloneWindows64);
{ AssetDatabase.Refresh();
if (arg.StartsWith("buildPackage")) BuildInternal(BuildTarget.StandaloneWindows64, Application.dataPath + "/../Builds/Windows", "1.0");
return arg.Split("="[0])[1]; 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
{
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;
} }
} }
} }

View File

@@ -92,7 +92,6 @@ namespace TEngine
{ {
Log.Warning($"HttpPost {unityWebRequest.url} be canceled!"); Log.Warning($"HttpPost {unityWebRequest.url} be canceled!");
unityWebRequest.Dispose(); unityWebRequest.Dispose();
cts.Dispose();
return string.Empty; return string.Empty;
} }
} }
@@ -102,14 +101,12 @@ namespace TEngine
{ {
Log.Warning("HttpPost Timeout"); Log.Warning("HttpPost Timeout");
unityWebRequest.Dispose(); unityWebRequest.Dispose();
cts.Dispose();
return string.Empty; return string.Empty;
} }
} }
string ret = unityWebRequest.downloadHandler.text; string ret = unityWebRequest.downloadHandler.text;
unityWebRequest.Dispose(); unityWebRequest.Dispose();
cts.Dispose();
return ret; return ret;
} }
} }

View File

@@ -232,20 +232,10 @@ namespace TEngine
return; return;
} }
_entity = new GameObject("[Unity.Utility]") _entity = new GameObject("[Unity.Utility]");
{
// hideFlags = HideFlags.HideAndDontSave
};
_entity.SetActive(true); _entity.SetActive(true);
_entity.transform.SetParent(GameModule.Base.transform); _entity.transform.SetParent(GameModule.Base.transform);
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
{
Object.DontDestroyOnLoad(_entity);
}
UnityEngine.Assertions.Assert.IsFalse(_behaviour); UnityEngine.Assertions.Assert.IsFalse(_behaviour);
_behaviour = _entity.AddComponent<MainBehaviour>(); _behaviour = _entity.AddComponent<MainBehaviour>();
} }

View File

@@ -304,5 +304,20 @@ namespace TEngine
/// <typeparam name="T">资源实例类型。</typeparam> /// <typeparam name="T">资源实例类型。</typeparam>
/// <returns>原生文件资源实例。</returns> /// <returns>原生文件资源实例。</returns>
UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object; UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object;
/// <summary>
/// 放入预加载对象。
/// </summary>
/// <param name="location">资源定位地址。</param>
/// <param name="assetObject">预加载对象。</param>
public void PushPreLoadAsset(string location, Object assetObject);
/// <summary>
/// 获取预加载的实例对象。
/// </summary>
/// <param name="location">资源定位地址。</param>
/// <typeparam name="T">资源实例类型。</typeparam>
/// <returns>预加载对象。</returns>
public T GetPreLoadAsset<T>(string location) where T : Object;
} }
} }

View File

@@ -101,6 +101,7 @@ namespace TEngine
internal override void Shutdown() internal override void Shutdown()
{ {
ReleasePreLoadAssets();
#if !UNITY_WEBGL #if !UNITY_WEBGL
YooAssets.Destroy(); YooAssets.Destroy();
#endif #endif
@@ -878,5 +879,53 @@ namespace TEngine
return cancelOrFailed ? null : handle.GetSubAssetObjects<T>(); return cancelOrFailed ? null : handle.GetSubAssetObjects<T>();
} }
#region
private readonly Dictionary<string, Object> _preLoadMaps = new Dictionary<string, Object>();
/// <summary>
/// 放入预加载对象。
/// </summary>
/// <param name="location">资源定位地址。</param>
/// <param name="assetObject">预加载对象。</param>
public void PushPreLoadAsset(string location, Object assetObject)
{
if (_preLoadMaps.ContainsKey(location))
{
return;
}
_preLoadMaps.Add(location, assetObject);
}
/// <summary>
/// 获取预加载的实例对象。
/// </summary>
/// <param name="location">资源定位地址。</param>
/// <typeparam name="T">资源实例类型。</typeparam>
/// <returns>预加载对象。</returns>
public T GetPreLoadAsset<T>(string location) where T : Object
{
if (_preLoadMaps.TryGetValue(location,out Object assetObject))
{
return assetObject as T;
}
return default;
}
private void ReleasePreLoadAssets()
{
using var iter = _preLoadMaps.GetEnumerator();
while (iter.MoveNext())
{
var assetObject = iter.Current.Value;
if (assetObject != null)
{
UnityEngine.Object.Destroy(assetObject);
}
}
_preLoadMaps.Clear();
}
#endregion
} }
} }

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement;
using YooAsset; using YooAsset;
namespace TEngine namespace TEngine
@@ -300,7 +299,8 @@ namespace TEngine
/// </summary> /// </summary>
public void ClearSandbox() public void ClearSandbox()
{ {
// YooAssets.ClearSandbox(); var package = YooAssets.GetPackage(packageName);
package.ClearPackageSandbox();
} }
/// <summary> /// <summary>
@@ -658,5 +658,28 @@ namespace TEngine
{ {
return await m_ResourceManager.LoadAllSubAssetAsync<T>(location, cancellationToken); return await m_ResourceManager.LoadAllSubAssetAsync<T>(location, cancellationToken);
} }
#region
/// <summary>
/// 放入预加载对象。
/// </summary>
/// <param name="location">资源定位地址。</param>
/// <param name="assetObject">预加载对象。</param>
public void PushPreLoadAsset(string location, UnityEngine.Object assetObject)
{
m_ResourceManager.PushPreLoadAsset(location, assetObject);
}
/// <summary>
/// 获取预加载的实例对象。
/// </summary>
/// <param name="location">资源定位地址。</param>
/// <typeparam name="T">资源实例类型。</typeparam>
/// <returns>预加载对象。</returns>
public T GetPreLoadAsset<T>(string location) where T : UnityEngine.Object
{
return m_ResourceManager.GetPreLoadAsset<T>(location);
}
#endregion
} }
} }

View File

@@ -44,7 +44,7 @@ namespace TEngine
public UIBase Parent => parent; public UIBase Parent => parent;
/// <summary> /// <summary>
/// 自动逸数据集。 /// 自定义数据集。
/// </summary> /// </summary>
protected System.Object[] userDatas; protected System.Object[] userDatas;
@@ -93,6 +93,20 @@ namespace TEngine
/// </summary> /// </summary>
protected bool m_updateListValid = false; 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>
/// 代码自动生成绑定。 /// 代码自动生成绑定。
/// </summary> /// </summary>
@@ -243,7 +257,7 @@ namespace TEngine
/// <summary> /// <summary>
/// 创建UIWidget通过父UI位置节点。 /// 创建UIWidget通过父UI位置节点。
/// <remarks>因为资源例已经存在父物体所以不需要异步。</remarks> /// <remarks>因为资源例已经存在父物体所以不需要异步。</remarks>
/// </summary> /// </summary>
/// <param name="goPath">父UI位置节点。</param> /// <param name="goPath">父UI位置节点。</param>
/// <param name="visible">是否可见。</param> /// <param name="visible">是否可见。</param>
@@ -264,7 +278,7 @@ namespace TEngine
/// <summary> /// <summary>
/// 创建UIWidget通过父UI位置节点。 /// 创建UIWidget通过父UI位置节点。
/// <remarks>因为资源例已经存在父物体所以不需要异步。</remarks> /// <remarks>因为资源例已经存在父物体所以不需要异步。</remarks>
/// </summary> /// </summary>
/// <param name="parentTrans"></param> /// <param name="parentTrans"></param>
/// <param name="goPath">父UI位置节点。</param> /// <param name="goPath">父UI位置节点。</param>
@@ -284,7 +298,7 @@ namespace TEngine
/// <summary> /// <summary>
/// 创建UIWidget通过游戏物体。 /// 创建UIWidget通过游戏物体。
/// <remarks>因为资源例已经存在父物体所以不需要异步。</remarks> /// <remarks>因为资源例已经存在父物体所以不需要异步。</remarks>
/// </summary> /// </summary>
/// <param name="goRoot">游戏物体。</param> /// <param name="goRoot">游戏物体。</param>
/// <param name="visible">是否可见。</param> /// <param name="visible">是否可见。</param>
@@ -456,7 +470,7 @@ namespace TEngine
{ {
if (prefab == null) if (prefab == null)
{ {
tmpT = CreateWidgetByPath<T>(parentTrans, assetPath); tmpT = await CreateWidgetByPathAsync<T>(parentTrans, assetPath);
} }
else else
{ {

View File

@@ -5,7 +5,7 @@
"depth": 0, "depth": 0,
"source": "git", "source": "git",
"dependencies": {}, "dependencies": {},
"hash": "84ed2e6b9d0e476b1da70ea1f4e4b1e7c33ae7f8" "hash": "febff1c658fa9d76726f3aa25f26ec6d35c1e2e6"
}, },
"com.cysharp.unitask": { "com.cysharp.unitask": {
"version": "file:UniTask", "version": "file:UniTask",