mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Compare commits
51 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 | ||
![]() |
1d56437d9f | ||
![]() |
69db1ff977 | ||
![]() |
48887b1aee | ||
![]() |
381ea8bb8d | ||
![]() |
7401edac15 | ||
![]() |
b1c7f30be9 | ||
![]() |
cfaf82a623 | ||
![]() |
6992d12c6c | ||
![]() |
119d9683ad | ||
![]() |
9478868513 | ||
![]() |
6ed32082e1 | ||
![]() |
6ee515e8c5 | ||
![]() |
b839afa76a | ||
![]() |
d9605b348a | ||
![]() |
dfef83919c | ||
![]() |
f5f983f220 |
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
@@ -17,7 +18,7 @@ namespace GameLogic
|
||||
/// <summary>
|
||||
/// Item字典
|
||||
/// </summary>
|
||||
private Dictionary<int, TItem> m_itemCache = new Dictionary<int, TItem>();
|
||||
private GameFrameworkDictionary<int, TItem> m_itemCache = new GameFrameworkDictionary<int, TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算偏差后的ItemList
|
||||
@@ -163,9 +164,19 @@ namespace GameLogic
|
||||
m_items.Clear();
|
||||
for (int i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
m_items.Add(m_itemCache[i]);
|
||||
m_items.Add(m_itemCache.GetValueByIndex(i));
|
||||
}
|
||||
return m_items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Item。
|
||||
/// </summary>
|
||||
/// <param name="index">索引。</param>
|
||||
/// <returns>TItem。</returns>
|
||||
public TItem GetItemByIndex(int index)
|
||||
{
|
||||
return m_itemCache.GetValueByIndex(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ namespace GameLogic
|
||||
{
|
||||
public LoopListView LoopRectView { private set; get; }
|
||||
|
||||
private Dictionary<int, T> m_itemCache = new Dictionary<int, T>();
|
||||
private GameFrameworkDictionary<int, T> m_itemCache = new GameFrameworkDictionary<int, T>();
|
||||
|
||||
public override void BindMemberProperty()
|
||||
{
|
||||
@@ -71,9 +71,8 @@ namespace GameLogic
|
||||
List<T> list = new List<T>();
|
||||
for (int i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
list.Add(m_itemCache[i]);
|
||||
list.Add(m_itemCache.GetValueByIndex(i));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -85,11 +84,11 @@ namespace GameLogic
|
||||
/// <summary>
|
||||
/// 获取Item。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="index">索引。</param>
|
||||
/// <returns>TItem。</returns>
|
||||
public T GetItemByIndex(int index)
|
||||
{
|
||||
return m_itemCache[index];
|
||||
return m_itemCache.GetValueByIndex(index);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
@@ -16,8 +17,9 @@ namespace GameLogic
|
||||
|
||||
/// <summary>
|
||||
/// Item字典
|
||||
/// <remarks>Key => GameObjectHashCode | Value => TItem.</remarks>
|
||||
/// </summary>
|
||||
private Dictionary<int, TItem> m_itemCache = new Dictionary<int, TItem>();
|
||||
private GameFrameworkDictionary<int, TItem> m_itemCache = new GameFrameworkDictionary<int, TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算偏差后的ItemList
|
||||
@@ -63,7 +65,7 @@ namespace GameLogic
|
||||
base.AdjustItemNum(n, datas, funcItem);
|
||||
m_tpFuncItem = funcItem;
|
||||
LoopRectView.SetListItemCount(n);
|
||||
LoopRectView.RefreshAllShownItem();
|
||||
// LoopRectView.RefreshAllShownItem();
|
||||
m_tpFuncItem = null;
|
||||
}
|
||||
|
||||
@@ -161,7 +163,7 @@ namespace GameLogic
|
||||
m_items.Clear();
|
||||
for (int i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
m_items.Add(m_itemCache[i]);
|
||||
m_items.Add(m_itemCache.GetValueByIndex(i));
|
||||
}
|
||||
return m_items;
|
||||
}
|
||||
@@ -174,5 +176,15 @@ namespace GameLogic
|
||||
{
|
||||
return LoopRectView.GetItemStartIndex();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Item。
|
||||
/// </summary>
|
||||
/// <param name="index">索引。</param>
|
||||
/// <returns>TItem。</returns>
|
||||
public TItem GetItemByIndex(int index)
|
||||
{
|
||||
return m_itemCache.GetValueByIndex(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -812,7 +812,6 @@ GameObject:
|
||||
- component: {fileID: 4070374929253206932}
|
||||
- component: {fileID: 4872533144352319846}
|
||||
- component: {fileID: 3352775805385032060}
|
||||
- component: {fileID: 3859027068210555860}
|
||||
m_Layer: 5
|
||||
m_Name: UILoadTip
|
||||
m_TagString: Untagged
|
||||
@@ -880,31 +879,6 @@ MonoBehaviour:
|
||||
m_BlockingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 55
|
||||
--- !u!114 &3859027068210555860
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7666412045263395013}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bcd11033283847ee8f7c71eedd9a4771, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
elements:
|
||||
m_keys:
|
||||
- m_btnUpdate
|
||||
- m_btnIgnore
|
||||
- m_textInfo
|
||||
- m_textTittle
|
||||
- m_btnPackage
|
||||
m_values:
|
||||
- {fileID: 2745714441875214452}
|
||||
- {fileID: 467775921333773033}
|
||||
- {fileID: 3862717357071106210}
|
||||
- {fileID: 9127528276671758327}
|
||||
- {fileID: 1387175525974173601}
|
||||
--- !u!1 &8012535748721374403
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@@ -773,7 +773,6 @@ GameObject:
|
||||
- component: {fileID: 1633508802563447727}
|
||||
- component: {fileID: 5827342734203288403}
|
||||
- component: {fileID: 4835021223508371640}
|
||||
- component: {fileID: 903919243524269039}
|
||||
m_Layer: 5
|
||||
m_Name: UILoadUpdate
|
||||
m_TagString: Untagged
|
||||
@@ -843,33 +842,6 @@ MonoBehaviour:
|
||||
m_BlockingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 55
|
||||
--- !u!114 &903919243524269039
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 9130266365217219149}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bcd11033283847ee8f7c71eedd9a4771, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
elements:
|
||||
m_keys:
|
||||
- m_imgBackGround
|
||||
- m_scrollbarProgress
|
||||
- m_textDesc
|
||||
- m_btnClear
|
||||
- m_textAppid
|
||||
- m_textResid
|
||||
m_values:
|
||||
- {fileID: 4652061626151979521}
|
||||
- {fileID: 2347891492826839465}
|
||||
- {fileID: 8666815445422661327}
|
||||
- {fileID: 4232232858152633415}
|
||||
- {fileID: 3038352660368000718}
|
||||
- {fileID: 8143980099109665604}
|
||||
--- !u!1 &9157096376857424144
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@@ -20,26 +20,22 @@ namespace GameMain
|
||||
public MessageShowType ShowType = MessageShowType.None;
|
||||
|
||||
#region 脚本工具生成的代码
|
||||
|
||||
private Button m_btnPackage;
|
||||
private Text m_textTittle;
|
||||
private Text m_textInfo;
|
||||
private Button m_btnIgnore;
|
||||
private Button m_btnUpdate;
|
||||
|
||||
public override void ScriptGenerator()
|
||||
{
|
||||
CheckUIElement();
|
||||
m_btnPackage = FChild<Button>("m_btnPackage");
|
||||
m_textTittle = FChild<Text>("m_textTittle");
|
||||
m_textInfo = FChild<Text>("m_textInfo");
|
||||
m_btnIgnore = FChild<Button>("m_btnIgnore");
|
||||
m_btnUpdate = FChild<Button>("m_btnUpdate");
|
||||
m_btnPackage = FindChildComponent<Button>("BgImage/m_btnPackage");
|
||||
m_textTittle = FindChildComponent<Text>("BgImage/m_textTittle");
|
||||
m_textInfo = FindChildComponent<Text>("BgImage/m_textInfo");
|
||||
m_btnIgnore = FindChildComponent<Button>("BgImage/Group/m_btnIgnore");
|
||||
m_btnUpdate = FindChildComponent<Button>("BgImage/Group/m_btnUpdate");
|
||||
m_btnPackage.onClick.AddListener(OnClickPackageBtn);
|
||||
m_btnIgnore.onClick.AddListener(OnClickIgnoreBtn);
|
||||
m_btnUpdate.onClick.AddListener(OnClickUpdateBtn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
|
@@ -8,22 +8,22 @@ namespace GameMain
|
||||
[Window(UILayer.UI, fromResources: true, location: "AssetLoad/UILoadUpdate",fullScreen:true)]
|
||||
public class UILoadUpdate : UIWindow
|
||||
{
|
||||
private Scrollbar m_scrollbarProgress;
|
||||
|
||||
#region 脚本工具生成的代码
|
||||
private Image m_imgBackGround;
|
||||
private Scrollbar m_scrollbarProgress;
|
||||
private Text m_textDesc;
|
||||
private Button m_btnClear;
|
||||
private Text m_textAppid;
|
||||
private Text m_textResid;
|
||||
public override void ScriptGenerator()
|
||||
{
|
||||
CheckUIElement();
|
||||
m_imgBackGround = FChild<Image>("m_imgBackGround");
|
||||
m_scrollbarProgress = FChild<Scrollbar>("m_scrollbarProgress");
|
||||
m_textDesc = FChild<Text>("m_textDesc");
|
||||
m_btnClear = FChild<Button>("m_btnClear");
|
||||
m_textAppid = FChild<Text>("m_textAppid");
|
||||
m_textResid = FChild<Text>("m_textResid");
|
||||
m_imgBackGround = FindChildComponent<Image>("m_imgBackGround");
|
||||
m_textDesc = FindChildComponent<Text>("m_textDesc");
|
||||
m_btnClear = FindChildComponent<Button>("TopNode/m_btnClear");
|
||||
m_textAppid = FindChildComponent<Text>("TopNode/m_textAppid");
|
||||
m_textResid = FindChildComponent<Text>("TopNode/m_textResid");
|
||||
m_scrollbarProgress = FindChildComponent<Scrollbar>("m_scrollbarProgress");
|
||||
m_btnClear.onClick.AddListener(OnClickClearBtn);
|
||||
}
|
||||
#endregion
|
||||
@@ -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 事件
|
||||
@@ -118,12 +123,12 @@ namespace GameMain
|
||||
m_scrollbarProgress.size = progress;
|
||||
}
|
||||
|
||||
protected override void Close()
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
OnStop(null);
|
||||
LoadUpdateLogic.Instance.DownloadCompleteAction -= DownLoad_Complete_Action;
|
||||
LoadUpdateLogic.Instance.DownProgressAction -= DownLoad_Progress_Action;
|
||||
base.Close();
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf1e53a3963b4dbf8c5f139ee8d80c3d
|
||||
timeCreated: 1698301726
|
@@ -0,0 +1,45 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
/// <summary>
|
||||
/// 自动绑定全局设置
|
||||
/// </summary>
|
||||
public class AutoBindGlobalSetting : ScriptableObject
|
||||
{
|
||||
[FolderPath]
|
||||
[LabelText("默认组件代码保存路径")]
|
||||
[SerializeField]
|
||||
private string m_CodePath;
|
||||
|
||||
[LabelText("绑定代码命名空间")]
|
||||
[SerializeField]
|
||||
private string m_Namespace;
|
||||
|
||||
[LabelText("子组件名称(不会往下继续遍历)")]
|
||||
[SerializeField]
|
||||
private string m_WidgetName = "m_item";
|
||||
|
||||
public string CodePath => m_CodePath;
|
||||
|
||||
public string Namespace => m_Namespace;
|
||||
|
||||
public string WidgetName => m_WidgetName;
|
||||
|
||||
[MenuItem("TEngine/CreateAutoBindGlobalSetting")]
|
||||
private static void CreateAutoBindGlobalSetting()
|
||||
{
|
||||
string[] paths = AssetDatabase.FindAssets("t:AutoBindGlobalSetting");
|
||||
if (paths.Length >= 1)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(paths[0]);
|
||||
EditorUtility.DisplayDialog("警告", $"已存在AutoBindGlobalSetting,路径:{path}", "确认");
|
||||
return;
|
||||
}
|
||||
|
||||
AutoBindGlobalSetting setting = CreateInstance<AutoBindGlobalSetting>();
|
||||
AssetDatabase.CreateAsset(setting, "Assets/TEngine/ResRaw/AutoBindGlobalSetting.asset");
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dac541dae7b4c4d8b5497057739cfb0
|
||||
timeCreated: 1698304721
|
@@ -0,0 +1,12 @@
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(AutoBindGlobalSetting))]
|
||||
public class AutoBindGlobalSettingInspector : OdinEditor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 020e5781e8c44c90bfbdf2cb12441e79
|
||||
timeCreated: 1698304745
|
@@ -0,0 +1,534 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using BindData = ComponentAutoBindTool.BindData;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
|
||||
[CustomEditor(typeof(ComponentAutoBindTool))]
|
||||
public class ComponentAutoBindToolInspector : Editor
|
||||
{
|
||||
private ComponentAutoBindTool m_Target;
|
||||
|
||||
private SerializedProperty m_BindDatas;
|
||||
private SerializedProperty m_BindComs;
|
||||
private List<BindData> m_TempList = new List<BindData>();
|
||||
private List<string> m_TempFiledNames = new List<string>();
|
||||
private List<string> m_TempComponentTypeNames = new List<string>();
|
||||
|
||||
private string[] s_AssemblyNames = { "Assembly-CSharp", "TEngine.Runtime" };
|
||||
private string[] m_HelperTypeNames;
|
||||
private string m_HelperTypeName;
|
||||
private int m_HelperTypeNameIndex;
|
||||
|
||||
private AutoBindGlobalSetting m_Setting;
|
||||
|
||||
private SerializedProperty m_Namespace;
|
||||
private SerializedProperty m_ClassName;
|
||||
private SerializedProperty m_CodePath;
|
||||
private SerializedProperty m_IsWidget;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_Target = (ComponentAutoBindTool)target;
|
||||
m_BindDatas = serializedObject.FindProperty("BindDatas");
|
||||
m_BindComs = serializedObject.FindProperty("bindComponents");
|
||||
|
||||
m_HelperTypeNames = GetTypeNames(typeof(IAutoBindRuleHelper), s_AssemblyNames);
|
||||
|
||||
string[] paths = AssetDatabase.FindAssets("t:AutoBindGlobalSetting");
|
||||
if (paths.Length == 0)
|
||||
{
|
||||
Debug.LogError("不存在AutoBindGlobalSetting");
|
||||
return;
|
||||
}
|
||||
|
||||
if (paths.Length > 1)
|
||||
{
|
||||
Debug.LogError("AutoBindGlobalSetting数量大于1");
|
||||
return;
|
||||
}
|
||||
|
||||
string path = AssetDatabase.GUIDToAssetPath(paths[0]);
|
||||
m_Setting = AssetDatabase.LoadAssetAtPath<AutoBindGlobalSetting>(path);
|
||||
|
||||
|
||||
m_Namespace = serializedObject.FindProperty("m_Namespace");
|
||||
m_ClassName = serializedObject.FindProperty("m_ClassName");
|
||||
m_CodePath = serializedObject.FindProperty("m_CodePath");
|
||||
m_IsWidget = serializedObject.FindProperty("m_IsWidget");
|
||||
|
||||
m_Namespace.stringValue = string.IsNullOrEmpty(m_Namespace.stringValue) ? m_Setting.Namespace : m_Namespace.stringValue;
|
||||
m_ClassName.stringValue = string.IsNullOrEmpty(m_ClassName.stringValue) ? m_Target.gameObject.name : m_ClassName.stringValue;
|
||||
m_CodePath.stringValue = string.IsNullOrEmpty(m_CodePath.stringValue) ? m_Setting.CodePath : m_CodePath.stringValue;
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
DrawTopButton();
|
||||
|
||||
DrawHelperSelect();
|
||||
|
||||
DrawSetting();
|
||||
|
||||
DrawKvData();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制顶部按钮
|
||||
/// </summary>
|
||||
private void DrawTopButton()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button("排序"))
|
||||
{
|
||||
Sort();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("全部删除"))
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("删除空引用"))
|
||||
{
|
||||
RemoveNull();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("自动绑定组件"))
|
||||
{
|
||||
AutoBindComponent();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("生成绑定代码"))
|
||||
{
|
||||
GenAutoBindCode();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
private void Sort()
|
||||
{
|
||||
m_TempList.Clear();
|
||||
foreach (BindData data in m_Target.BindDatas)
|
||||
{
|
||||
m_TempList.Add(new BindData(data.Name, data.BindCom, data.IsGameObject));
|
||||
}
|
||||
|
||||
m_TempList.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));
|
||||
|
||||
m_BindDatas.ClearArray();
|
||||
foreach (BindData data in m_TempList)
|
||||
{
|
||||
AddBindData(data.Name, data.BindCom, data.IsGameObject);
|
||||
}
|
||||
|
||||
SyncBindComs();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部删除
|
||||
/// </summary>
|
||||
private void RemoveAll()
|
||||
{
|
||||
m_BindDatas.ClearArray();
|
||||
|
||||
SyncBindComs();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除空引用
|
||||
/// </summary>
|
||||
private void RemoveNull()
|
||||
{
|
||||
for (int i = m_BindDatas.arraySize - 1; i >= 0; i--)
|
||||
{
|
||||
SerializedProperty element = m_BindDatas.GetArrayElementAtIndex(i).FindPropertyRelative("BindCom");
|
||||
if (element.objectReferenceValue == null)
|
||||
{
|
||||
m_BindDatas.DeleteArrayElementAtIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
SyncBindComs();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动绑定组件
|
||||
/// </summary>
|
||||
private void AutoBindComponent()
|
||||
{
|
||||
m_BindDatas.ClearArray();
|
||||
|
||||
var transform = m_Target.transform;
|
||||
Ergodic(transform, transform);
|
||||
|
||||
SyncBindComs();
|
||||
}
|
||||
|
||||
private void Ergodic(Transform rootTransform, Transform currentTransform)
|
||||
{
|
||||
for (int i = 0; i < currentTransform.childCount; ++i)
|
||||
{
|
||||
Transform child = currentTransform.GetChild(i);
|
||||
|
||||
m_TempFiledNames.Clear();
|
||||
m_TempComponentTypeNames.Clear();
|
||||
|
||||
if (m_Target.RuleHelper.IsValidBind(child, m_TempFiledNames, m_TempComponentTypeNames))
|
||||
{
|
||||
for (int index = 0; index < m_TempFiledNames.Count; index++)
|
||||
{
|
||||
string componentName = m_TempComponentTypeNames[index];
|
||||
bool isGameObject = componentName.Equals("GameObject");
|
||||
componentName = isGameObject ? "Transform" : componentName;
|
||||
Component com = child.GetComponent(componentName);
|
||||
if (com == null)
|
||||
{
|
||||
Debug.LogError($"{child.name}上不存在{componentName}的组件");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddBindData(m_TempFiledNames[index], child.GetComponent(componentName), isGameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!child.name.StartsWith(m_Setting.WidgetName))
|
||||
{
|
||||
Ergodic(rootTransform, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制辅助器选择框
|
||||
/// </summary>
|
||||
private void DrawHelperSelect()
|
||||
{
|
||||
m_HelperTypeName = m_HelperTypeNames[0];
|
||||
|
||||
if (m_Target.RuleHelper != null)
|
||||
{
|
||||
m_HelperTypeName = m_Target.RuleHelper.GetType().Name;
|
||||
|
||||
for (int i = 0; i < m_HelperTypeNames.Length; i++)
|
||||
{
|
||||
if (m_HelperTypeName == m_HelperTypeNames[i])
|
||||
{
|
||||
m_HelperTypeNameIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IAutoBindRuleHelper helper = (IAutoBindRuleHelper)CreateHelperInstance(m_HelperTypeName, s_AssemblyNames);
|
||||
m_Target.RuleHelper = helper;
|
||||
}
|
||||
|
||||
foreach (GameObject go in Selection.gameObjects)
|
||||
{
|
||||
ComponentAutoBindTool autoBindTool = go.GetComponent<ComponentAutoBindTool>();
|
||||
if (autoBindTool.RuleHelper == null)
|
||||
{
|
||||
IAutoBindRuleHelper helper = (IAutoBindRuleHelper)CreateHelperInstance(m_HelperTypeName, s_AssemblyNames);
|
||||
autoBindTool.RuleHelper = helper;
|
||||
}
|
||||
}
|
||||
|
||||
int selectedIndex = EditorGUILayout.Popup("AutoBindRuleHelper", m_HelperTypeNameIndex, m_HelperTypeNames);
|
||||
if (selectedIndex != m_HelperTypeNameIndex)
|
||||
{
|
||||
m_HelperTypeNameIndex = selectedIndex;
|
||||
m_HelperTypeName = m_HelperTypeNames[selectedIndex];
|
||||
IAutoBindRuleHelper helper = (IAutoBindRuleHelper)CreateHelperInstance(m_HelperTypeName, s_AssemblyNames);
|
||||
m_Target.RuleHelper = helper;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制设置项
|
||||
/// </summary>
|
||||
private void DrawSetting()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_Namespace.stringValue = EditorGUILayout.TextField(new GUIContent("命名空间:"), m_Namespace.stringValue);
|
||||
if (GUILayout.Button("默认设置"))
|
||||
{
|
||||
m_Namespace.stringValue = m_Setting.Namespace;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_ClassName.stringValue = EditorGUILayout.TextField(new GUIContent("类名:"), m_ClassName.stringValue);
|
||||
if (GUILayout.Button("物体名"))
|
||||
{
|
||||
m_ClassName.stringValue = m_Target.gameObject.name;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
bool isWidget = EditorGUILayout.Toggle("是否是组件", m_IsWidget.boolValue);
|
||||
if (isWidget != m_IsWidget.boolValue)
|
||||
{
|
||||
m_IsWidget.boolValue = isWidget;
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField("代码保存路径:");
|
||||
EditorGUILayout.LabelField(m_CodePath.stringValue);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("选择路径"))
|
||||
{
|
||||
string temp = m_CodePath.stringValue;
|
||||
m_CodePath.stringValue = EditorUtility.OpenFolderPanel("选择代码保存路径", Application.dataPath, "");
|
||||
if (string.IsNullOrEmpty(m_CodePath.stringValue))
|
||||
{
|
||||
m_CodePath.stringValue = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("默认设置"))
|
||||
{
|
||||
m_CodePath.stringValue = m_Setting.CodePath;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制键值对数据
|
||||
/// </summary>
|
||||
private void DrawKvData()
|
||||
{
|
||||
//绘制key value数据
|
||||
|
||||
int needDeleteIndex = -1;
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
SerializedProperty property;
|
||||
|
||||
for (int i = 0; i < m_BindDatas.arraySize; i++)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField($"[{i}]", GUILayout.Width(25));
|
||||
property = m_BindDatas.GetArrayElementAtIndex(i).FindPropertyRelative("Name");
|
||||
property.stringValue = EditorGUILayout.TextField(property.stringValue, GUILayout.Width(150));
|
||||
property = m_BindDatas.GetArrayElementAtIndex(i).FindPropertyRelative("BindCom");
|
||||
property.objectReferenceValue = EditorGUILayout.ObjectField(property.objectReferenceValue, typeof(Component), true);
|
||||
|
||||
if (GUILayout.Button("X"))
|
||||
{
|
||||
//将元素下标添加进删除list
|
||||
needDeleteIndex = i;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
//删除data
|
||||
if (needDeleteIndex != -1)
|
||||
{
|
||||
m_BindDatas.DeleteArrayElementAtIndex(needDeleteIndex);
|
||||
SyncBindComs();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加绑定数据
|
||||
/// </summary>
|
||||
private void AddBindData(string name, Component bindCom, bool isGameObject = false)
|
||||
{
|
||||
int index = m_BindDatas.arraySize;
|
||||
m_BindDatas.InsertArrayElementAtIndex(index);
|
||||
SerializedProperty element = m_BindDatas.GetArrayElementAtIndex(index);
|
||||
element.FindPropertyRelative("Name").stringValue = name;
|
||||
element.FindPropertyRelative("BindCom").objectReferenceValue = bindCom;
|
||||
element.FindPropertyRelative("IsGameObject").boolValue = isGameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步绑定数据
|
||||
/// </summary>
|
||||
private void SyncBindComs()
|
||||
{
|
||||
m_BindComs.ClearArray();
|
||||
|
||||
for (int i = 0; i < m_BindDatas.arraySize; i++)
|
||||
{
|
||||
SerializedProperty property = m_BindDatas.GetArrayElementAtIndex(i).FindPropertyRelative("BindCom");
|
||||
m_BindComs.InsertArrayElementAtIndex(i);
|
||||
m_BindComs.GetArrayElementAtIndex(i).objectReferenceValue = property.objectReferenceValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定基类在指定程序集中的所有子类名称
|
||||
/// </summary>
|
||||
private string[] GetTypeNames(Type typeBase, string[] assemblyNames)
|
||||
{
|
||||
List<string> typeNames = new List<string>();
|
||||
foreach (string assemblyName in assemblyNames)
|
||||
{
|
||||
Assembly assembly = null;
|
||||
try
|
||||
{
|
||||
assembly = Assembly.Load(assemblyName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assembly == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Type[] types = assembly.GetTypes();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (type.IsClass && !type.IsAbstract && typeBase.IsAssignableFrom(type))
|
||||
{
|
||||
typeNames.Add(type.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typeNames.Sort();
|
||||
return typeNames.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建辅助器实例
|
||||
/// </summary>
|
||||
private object CreateHelperInstance(string helperTypeName, string[] assemblyNames)
|
||||
{
|
||||
foreach (string assemblyName in assemblyNames)
|
||||
{
|
||||
Assembly assembly = Assembly.Load(assemblyName);
|
||||
|
||||
object instance = assembly.CreateInstance(helperTypeName);
|
||||
if (instance != null)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成自动绑定代码
|
||||
/// </summary>
|
||||
private void GenAutoBindCode()
|
||||
{
|
||||
GameObject go = m_Target.gameObject;
|
||||
|
||||
string className = !string.IsNullOrEmpty(m_Target.ClassName) ? m_Target.ClassName : go.name;
|
||||
string codePath = !string.IsNullOrEmpty(m_Target.CodePath) ? m_Target.CodePath : m_Setting.CodePath;
|
||||
|
||||
if (!Directory.Exists(codePath))
|
||||
{
|
||||
Debug.LogError($"{go.name}的代码保存路径{codePath}无效");
|
||||
}
|
||||
|
||||
using (StreamWriter sw = new StreamWriter($"{codePath}/{className}.BindComponents.cs"))
|
||||
{
|
||||
sw.WriteLine(
|
||||
"//------------------------------------------------------------------------------\n//\t<auto-generated>\n//\t\tTime:[" + DateTime.Now +
|
||||
"].\n//\t\tThis code was generated by autoBindTool.\n//\t\tChanges to this file may cause incorrect behavior and will be lost if\n//\t\tthe code is regenerated.\n//\t</auto-generated>\n//------------------------------------------------------------------------------");
|
||||
sw.WriteLine("using UnityEngine;");
|
||||
sw.WriteLine("using UnityEngine.UI;");
|
||||
sw.WriteLine("using TEngine;");
|
||||
sw.WriteLine("");
|
||||
|
||||
if (!string.IsNullOrEmpty(m_Target.Namespace))
|
||||
{
|
||||
//命名空间
|
||||
sw.WriteLine("namespace " + m_Target.Namespace);
|
||||
sw.WriteLine("{");
|
||||
}
|
||||
|
||||
//类名
|
||||
// if (!m_Target.IsWidget)
|
||||
// {
|
||||
// sw.WriteLine($"\tpublic partial class {className} : UIWindow");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sw.WriteLine($"\tpublic partial class {className} : UIWidget");
|
||||
// }
|
||||
sw.WriteLine($"\tpublic partial class {className}");
|
||||
sw.WriteLine("\t{");
|
||||
|
||||
//组件字段
|
||||
foreach (BindData data in m_Target.BindDatas)
|
||||
{
|
||||
if (data.IsGameObject)
|
||||
{
|
||||
sw.WriteLine($"\t\tprivate GameObject m_{data.Name};");
|
||||
}
|
||||
else
|
||||
{
|
||||
sw.WriteLine($"\t\tprivate {data.BindCom.GetType().Name} m_{data.Name};");
|
||||
}
|
||||
}
|
||||
|
||||
sw.WriteLine("");
|
||||
|
||||
// sw.WriteLine(
|
||||
// "\t\tpublic override void ScriptGenerator()\n\t\t{\n\t\t\tbase.ScriptGenerator();\n\t\t\tGetBindComponents(transform.gameObject);\n\t\t}");
|
||||
|
||||
sw.WriteLine("\t\tprivate void GetBindComponents(GameObject go)");
|
||||
sw.WriteLine("\t\t{");
|
||||
|
||||
//获取autoBindTool上的Component
|
||||
sw.WriteLine($"\t\t\tComponentAutoBindTool autoBindTool = go.GetComponent<ComponentAutoBindTool>();");
|
||||
sw.WriteLine("");
|
||||
|
||||
//根据索引获取
|
||||
|
||||
for (int i = 0; i < m_Target.BindDatas.Count; i++)
|
||||
{
|
||||
BindData data = m_Target.BindDatas[i];
|
||||
string filedName = $"m_{data.Name}";
|
||||
if (data.IsGameObject)
|
||||
{
|
||||
sw.WriteLine($"\t\t\t{filedName} = autoBindTool.GetBindComponent<{data.BindCom.GetType().Name}>({i}).gameObject;");
|
||||
}
|
||||
else
|
||||
{
|
||||
sw.WriteLine($"\t\t\t{filedName} = autoBindTool.GetBindComponent<{data.BindCom.GetType().Name}>({i});");
|
||||
}
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
|
||||
sw.WriteLine("\t}");
|
||||
|
||||
if (!string.IsNullOrEmpty(m_Target.Namespace))
|
||||
{
|
||||
sw.WriteLine("}");
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.DisplayDialog("提示", "代码生成完毕", "OK");
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77f2df681a094ff5a14e92e380ba90e7
|
||||
timeCreated: 1698304775
|
@@ -1,179 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using TEngine.Editor.UI;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace TEngine
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(UIElement), true)]
|
||||
public class UIElementEditor : OdinEditor
|
||||
{
|
||||
protected UIElement Element;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
Element = target as UIElement;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
if (GUILayout.Button("Generate", GUILayout.Width(130)))
|
||||
{
|
||||
CheckUiItems();
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorUtility.SetDirty(Element);
|
||||
}
|
||||
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
|
||||
protected void CheckUiItems()
|
||||
{
|
||||
if (Element == null) return;
|
||||
ClearUnusedItems();
|
||||
var root = Element.transform;
|
||||
StringBuilder strVar = new StringBuilder();
|
||||
StringBuilder strBind = new StringBuilder();
|
||||
StringBuilder strOnCreate = new StringBuilder();
|
||||
StringBuilder strOnCreateRedNote = new StringBuilder();
|
||||
StringBuilder strCallback = new StringBuilder();
|
||||
Ergodic(root, root, ref strVar, ref strBind, ref strOnCreate, ref strOnCreateRedNote, ref strCallback);
|
||||
StringBuilder strFile = new StringBuilder();
|
||||
|
||||
// 脚本工具生成的代码
|
||||
strFile.Append("\t\t#region 脚本工具生成的代码\n");
|
||||
strFile.Append(strVar);
|
||||
strFile.Append("\t\tpublic override void ScriptGenerator()\n");
|
||||
strFile.Append("\t\t{\n");
|
||||
strFile.Append("\t\t\tCheckUIElement();\n");
|
||||
strFile.Append(strBind);
|
||||
strFile.Append(strOnCreate);
|
||||
strFile.Append(strOnCreateRedNote);
|
||||
strFile.Append("\t\t}\n");
|
||||
strFile.Append("\t\t#endregion");
|
||||
|
||||
TextEditor te = new TextEditor();
|
||||
te.text = strFile.ToString();
|
||||
te.SelectAll();
|
||||
te.Copy();
|
||||
}
|
||||
|
||||
private void ClearUnusedItems()
|
||||
{
|
||||
if (Element == null || Element.Elements == null) return;
|
||||
List<string> ids = new List<string>();
|
||||
foreach (var kv in Element.Elements)
|
||||
{
|
||||
if (kv.Value == null || !string.IsNullOrEmpty(GetVerType(kv.Key)))
|
||||
{
|
||||
ids.Add(kv.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
Element.Elements.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void Ergodic(Transform root, Transform transform, ref StringBuilder strVar, ref StringBuilder strBind, ref StringBuilder strOnCreate,
|
||||
ref StringBuilder strOnCreateRedNote, ref StringBuilder strCallback)
|
||||
{
|
||||
for (int i = 0; i < transform.childCount; ++i)
|
||||
{
|
||||
Transform child = transform.GetChild(i);
|
||||
WriteScript(root, child, ref strVar, ref strBind, ref strOnCreate, ref strOnCreateRedNote, ref strCallback);
|
||||
if (child.name.StartsWith("m_item"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Ergodic(root, child, ref strVar, ref strBind, ref strOnCreate, ref strOnCreateRedNote, ref strCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteScript(Transform root, Transform child, ref StringBuilder strVar, ref StringBuilder strBind, ref StringBuilder strOnCreate,
|
||||
ref StringBuilder strOnCreateRedNote, ref StringBuilder strCallback)
|
||||
{
|
||||
var varName = child.name;
|
||||
var varType = GetVerType(varName);
|
||||
if (varType == string.Empty) return;
|
||||
if (Element.Elements.Contains(varName))
|
||||
{
|
||||
Debug.LogError("有重复的key:" + varName);
|
||||
return;
|
||||
}
|
||||
|
||||
Element.Elements[varName] = child;
|
||||
if (!string.IsNullOrEmpty(varName))
|
||||
{
|
||||
strVar.Append("\t\tprivate " + varType + " " + varName + ";\n");
|
||||
switch (varType)
|
||||
{
|
||||
case "Transform":
|
||||
strBind.Append($"\t\t\t{varName} = FChild(\"{varName}\");\n");
|
||||
break;
|
||||
case "GameObject":
|
||||
strBind.Append($"\t\t\t{varName} = FChild(\"{varName}\").gameObject;\n");
|
||||
break;
|
||||
case "RichItemIcon":
|
||||
strBind.Append($"\t\t\t{varName} = CreateWidgetByType<{varType}>(FChild(\"{varName}\"));\n");
|
||||
break;
|
||||
case "RedNoteWidget":
|
||||
break;
|
||||
case "TextButtonItem":
|
||||
case "SwitchTabItem":
|
||||
case "UIActorWidget":
|
||||
case "UIEffectWidget":
|
||||
case "UISpineWidget":
|
||||
case "UIMainPlayerWidget":
|
||||
strBind.Append($"\t\t\t{varName} = CreateWidget<{varType}>(FChild(\"{varName}\").gameObject);\n");
|
||||
break;
|
||||
default:
|
||||
strBind.Append($"\t\t\t{varName} = FChild<{varType}>(\"{varName}\");\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (varType == "Button")
|
||||
{
|
||||
string varFuncName = ScriptGenerator.GetBtnFuncName(varName);
|
||||
strOnCreate.Append($"\t\t\t{varName}.onClick.AddListener({varFuncName});\n");
|
||||
strCallback.Append($"\t\tprivate void {varFuncName}()\n");
|
||||
strCallback.Append("\t\t{\n\t\t}\n");
|
||||
}
|
||||
else if (varType == "Toggle")
|
||||
{
|
||||
string varFuncName = ScriptGenerator.GetToggleFuncName(varName);
|
||||
strOnCreate.Append($"\t\t\t{varName}.onValueChanged.AddListener({varFuncName});\n");
|
||||
strCallback.Append($"\t\tprivate void {varFuncName}(bool isOn)\n");
|
||||
strCallback.Append("\t\t{\n\t\t}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected string GetVerType(string uiName)
|
||||
{
|
||||
foreach (var pair in SettingsUtils.GetScriptGenerateRule())
|
||||
{
|
||||
if (uiName.StartsWith(pair.uiElementRegex))
|
||||
{
|
||||
return pair.componentName;
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02ba9976b78c4a079e16aa9302c1b43e
|
||||
timeCreated: 1696659319
|
@@ -0,0 +1,17 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3dac541dae7b4c4d8b5497057739cfb0, type: 3}
|
||||
m_Name: AutoBindGlobalSetting
|
||||
m_EditorClassIdentifier:
|
||||
m_CodePath: Assets/GameScripts
|
||||
m_Namespace: GameLogic
|
||||
m_WidgetName: m_item
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb33bb9d9cdf9484997cc91b0517ba4d
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,120 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架字典类。
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">指定字典Key的元素类型。</typeparam>
|
||||
/// <typeparam name="TValue">指定字典Value的元素类型。</typeparam>
|
||||
public class GameFrameworkDictionary<TKey, TValue>
|
||||
{
|
||||
protected readonly List<TKey> KeyList = new List<TKey>();
|
||||
protected readonly Dictionary<TKey, TValue> Dictionary = new Dictionary<TKey, TValue>();
|
||||
|
||||
/// <summary>
|
||||
/// 存储键的列表。
|
||||
/// </summary>
|
||||
public List<TKey> Keys => KeyList;
|
||||
|
||||
/// <summary>
|
||||
/// 存储字典实例。
|
||||
/// </summary>
|
||||
public int Count => KeyList.Count;
|
||||
|
||||
/// <summary>
|
||||
/// 通过KEY的数组下标获取元素。
|
||||
/// </summary>
|
||||
/// <param name="index">下标。</param>
|
||||
/// <returns>TValue。</returns>
|
||||
public TValue GetValueByIndex(int index)
|
||||
{
|
||||
return Dictionary[KeyList[index]];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过KEY的数组下标设置元素。
|
||||
/// </summary>
|
||||
/// <param name="index">下标。</param>
|
||||
/// <param name="item">TValue。</param>
|
||||
public void SetValue(int index, TValue item)
|
||||
{
|
||||
Dictionary[KeyList[index]] = item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典索引器。
|
||||
/// </summary>
|
||||
/// <param name="key">TKey。</param>
|
||||
public TValue this[TKey key]
|
||||
{
|
||||
get => Dictionary[key];
|
||||
set
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
{
|
||||
Add(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Removes all keys and values from the <see cref="T:TEngine.GameFrameworkDictionary`2" />.</summary>
|
||||
public void Clear()
|
||||
{
|
||||
KeyList.Clear();
|
||||
Dictionary.Clear();
|
||||
}
|
||||
|
||||
/// <summary>Adds the specified key and value to the dictionary.</summary>
|
||||
/// <param name="key">The key of the element to add.</param>
|
||||
/// <param name="item">The value of the element to add. The value can be <see langword="null" /> for reference types.</param>
|
||||
public virtual void Add(TKey key, TValue item)
|
||||
{
|
||||
KeyList.Add(key);
|
||||
Dictionary.Add(key, item);
|
||||
}
|
||||
|
||||
/// <summary>Gets the value associated with the specified key.</summary>
|
||||
/// <param name="key">The key of the value to get.</param>
|
||||
/// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value" /> parameter. This parameter is passed uninitialized.</param>
|
||||
public bool TryGetValue(TKey key, out TValue value)
|
||||
{
|
||||
return Dictionary.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
/// <summary>Determines whether the <see cref="T:System.Collections.Generic.Dictionary`2" /> contains the specified key.</summary>
|
||||
/// <param name="key">The key to locate in the </param>
|
||||
public bool ContainsKey(TKey key)
|
||||
{
|
||||
return Dictionary.ContainsKey(key);
|
||||
}
|
||||
|
||||
public TKey GetKey(int index)
|
||||
{
|
||||
return KeyList[index];
|
||||
}
|
||||
|
||||
public bool Remove(TKey key)
|
||||
{
|
||||
return KeyList.Remove(key) && Dictionary.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架顺序字典类。
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">指定字典Key的元素类型。</typeparam>
|
||||
/// <typeparam name="TValue">指定字典Value的元素类型。</typeparam>
|
||||
public class GameFrameworkSortedDictionary<TKey, TValue> : GameFrameworkDictionary<TKey, TValue>
|
||||
{
|
||||
public override void Add(TKey key, TValue item)
|
||||
{
|
||||
base.Add(key, item);
|
||||
KeyList.Sort();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3df785fede30420dbfa6acb2ff48c166
|
||||
timeCreated: 1698296076
|
@@ -0,0 +1,614 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#region Class Documentation
|
||||
/************************************************************************************************************
|
||||
Class Name: ActorEventDispatcher.cs 局部单位事件分发器。
|
||||
Type: Actor, Event
|
||||
Example:
|
||||
private ActorEventDispatcher _event;
|
||||
|
||||
/// <summary>
|
||||
/// 局部事件管理器。
|
||||
/// <remark>只分发和监听这个Event内部的事件</remark>
|
||||
/// </summary>
|
||||
public ActorEventDispatcher Event => _event ??= MemoryPool.Acquire<ActorEventDispatcher>();
|
||||
|
||||
// owner局部发送事件。
|
||||
owner.Event.Send(eventId,xxx);
|
||||
|
||||
// owner监听自身事件并绑定持有对象为owner。 比如是组件的情况下。移除时调用RemoveAllListenerByOwner(owner)会根据持有对象(组件)移除。
|
||||
owner.Event.AddEventListener(eventId,xxx,owner);
|
||||
************************************************************************************************************/
|
||||
#endregion
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 局部单位事件分发器。
|
||||
/// </summary>
|
||||
public class ActorEventDispatcher : IMemory
|
||||
{
|
||||
/// <summary>
|
||||
/// 所有事件。
|
||||
/// </summary>
|
||||
private readonly Dictionary<int, List<EventRegInfo>> _allEventListenerMap;
|
||||
|
||||
/// <summary>
|
||||
/// 用于标记一个事件是不是正在处理。
|
||||
/// </summary>
|
||||
private readonly List<int> _processEventList;
|
||||
|
||||
/// <summary>
|
||||
/// 用于标记一个事件是不是被移除。
|
||||
/// </summary>
|
||||
private readonly List<int> _delayDeleteEventList;
|
||||
|
||||
public ActorEventDispatcher()
|
||||
{
|
||||
_processEventList = new List<int>();
|
||||
_delayDeleteEventList = new List<int>();
|
||||
_allEventListenerMap = new Dictionary<int, List<EventRegInfo>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除所有事件监听。
|
||||
/// </summary>
|
||||
public void DestroyAllEventListener()
|
||||
{
|
||||
var itr = _allEventListenerMap.GetEnumerator();
|
||||
while (itr.MoveNext())
|
||||
{
|
||||
var kv = itr.Current;
|
||||
kv.Value.Clear();
|
||||
}
|
||||
|
||||
_processEventList.Clear();
|
||||
_delayDeleteEventList.Clear();
|
||||
itr.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 延迟移除事件。
|
||||
/// </summary>
|
||||
/// <param name="eventId"></param>
|
||||
private void AddDelayDelete(int eventId)
|
||||
{
|
||||
if (!_delayDeleteEventList.Contains(eventId))
|
||||
{
|
||||
_delayDeleteEventList.Add(eventId);
|
||||
Log.Info("delay delete eventId[{0}]", eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果找到eventId对应的监听,删除所有标记为delete的监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
private void CheckDelayDelete(int eventId)
|
||||
{
|
||||
if (_delayDeleteEventList.Contains(eventId))
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
for (int i = 0; i < listListener.Count; i++)
|
||||
{
|
||||
if (listListener[i].IsDeleted)
|
||||
{
|
||||
Log.Info("remove delay delete eventId[{0}]", eventId);
|
||||
listListener[i] = listListener[^1];
|
||||
listListener.RemoveAt(listListener.Count - 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_delayDeleteEventList.Remove(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
public void SendEvent(int eventId)
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
_processEventList.Add(eventId);
|
||||
#if UNITY_EDITOR
|
||||
int iEventCnt = _processEventList.Count;
|
||||
#endif
|
||||
|
||||
var count = listListener.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var node = listListener[i];
|
||||
if (node.IsDeleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listListener[i].Callback is Action callBack)
|
||||
{
|
||||
callBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Fatal("Invalid event data type: {0}", eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Log.Assert(iEventCnt == _processEventList.Count);
|
||||
Log.Assert(eventId == _processEventList[^1]);
|
||||
#endif
|
||||
_processEventList.RemoveAt(_processEventList.Count - 1);
|
||||
|
||||
CheckDelayDelete(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="arg1">事件参数。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
public void SendEvent<TArg1>(int eventId, TArg1 arg1)
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
_processEventList.Add(eventId);
|
||||
#if UNITY_EDITOR
|
||||
int iEventCnt = _processEventList.Count;
|
||||
#endif
|
||||
|
||||
var count = listListener.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var node = listListener[i];
|
||||
if (node.IsDeleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listListener[i].Callback is Action<TArg1> callBack)
|
||||
{
|
||||
callBack(arg1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Fatal("Invalid event data type: {0}", eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Log.Assert(iEventCnt == _processEventList.Count);
|
||||
Log.Assert(eventId == _processEventList[^1]);
|
||||
#endif
|
||||
|
||||
_processEventList.RemoveAt(_processEventList.Count - 1);
|
||||
|
||||
CheckDelayDelete(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="arg1">事件参数1。</param>
|
||||
/// <param name="arg2">事件参数2。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数类型2。</typeparam>
|
||||
public void SendEvent<TArg1, TArg2>(int eventId, TArg1 arg1, TArg2 arg2)
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
_processEventList.Add(eventId);
|
||||
#if UNITY_EDITOR
|
||||
int iEventCnt = _processEventList.Count;
|
||||
#endif
|
||||
|
||||
var count = listListener.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var node = listListener[i];
|
||||
if (node.IsDeleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listListener[i].Callback is Action<TArg1, TArg2> callBack)
|
||||
{
|
||||
callBack(arg1, arg2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Fatal("Invalid event data type: {0}", eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Log.Assert(iEventCnt == _processEventList.Count);
|
||||
Log.Assert(eventId == _processEventList[^1]);
|
||||
#endif
|
||||
_processEventList.RemoveAt(_processEventList.Count - 1);
|
||||
|
||||
CheckDelayDelete(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="arg1">事件参数1。</param>
|
||||
/// <param name="arg2">事件参数2。</param>
|
||||
/// <param name="arg3">事件参数3。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数类型2。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数类型3。</typeparam>
|
||||
public void SendEvent<TArg1, TArg2, TArg3>(int eventId, TArg1 arg1, TArg2 arg2, TArg3 arg3)
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
_processEventList.Add(eventId);
|
||||
#if UNITY_EDITOR
|
||||
int iEventCnt = _processEventList.Count;
|
||||
#endif
|
||||
|
||||
var count = listListener.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var node = listListener[i];
|
||||
if (node.IsDeleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.Callback is Action<TArg1, TArg2, TArg3> callBack)
|
||||
{
|
||||
callBack(arg1, arg2, arg3);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Fatal("Invalid event data type: {0}", eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Log.Assert(iEventCnt == _processEventList.Count);
|
||||
Log.Assert(eventId == _processEventList[^1]);
|
||||
#endif
|
||||
_processEventList.RemoveAt(_processEventList.Count - 1);
|
||||
|
||||
CheckDelayDelete(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="arg1">事件参数1。</param>
|
||||
/// <param name="arg2">事件参数2。</param>
|
||||
/// <param name="arg3">事件参数3。</param>
|
||||
/// <param name="arg4">事件参数4。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数类型2。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数类型3。</typeparam>
|
||||
/// <typeparam name="TArg4">事件参数类型4。</typeparam>
|
||||
public void SendEvent<TArg1, TArg2, TArg3, TArg4>(int eventId, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
_processEventList.Add(eventId);
|
||||
#if UNITY_EDITOR
|
||||
int iEventCnt = _processEventList.Count;
|
||||
#endif
|
||||
|
||||
|
||||
var count = listListener.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var node = listListener[i];
|
||||
if (node.IsDeleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listListener[i].Callback is Action<TArg1, TArg2, TArg3, TArg4> callBack)
|
||||
{
|
||||
callBack(arg1, arg2, arg3, arg4);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Fatal("Invalid event data type: {0}", eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Log.Assert(iEventCnt == _processEventList.Count);
|
||||
Log.Assert(eventId == _processEventList[^1]);
|
||||
#endif
|
||||
_processEventList.RemoveAt(_processEventList.Count - 1);
|
||||
|
||||
CheckDelayDelete(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">事件回调。</param>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
public void AddEventListener(int eventId, Action eventCallback, object owner)
|
||||
{
|
||||
AddEventListenerImp(eventId, eventCallback, owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">事件回调。</param>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
public void AddEventListener<TArg1>(int eventId, Action<TArg1> eventCallback, object owner)
|
||||
{
|
||||
AddEventListenerImp(eventId, eventCallback, owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">事件回调。</param>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数类型2。</typeparam>
|
||||
public void AddEventListener<TArg1, TArg2>(int eventId, Action<TArg1, TArg2> eventCallback, object owner)
|
||||
{
|
||||
AddEventListenerImp(eventId, eventCallback, owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">事件回调。</param>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数类型2。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数类型3。</typeparam>
|
||||
public void AddEventListener<TArg1, TArg2, TArg3>(int eventId, Action<TArg1, TArg2, TArg3> eventCallback, object owner)
|
||||
{
|
||||
AddEventListenerImp(eventId, eventCallback, owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">事件回调。</param>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
/// <typeparam name="TArg1">事件参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数类型2。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数类型3。</typeparam>
|
||||
/// <typeparam name="TArg4">事件参数类型4。</typeparam>
|
||||
public void AddEventListener<TArg1, TArg2, TArg3, TArg4>(int eventId, Action<TArg1, TArg2, TArg3, TArg4> eventCallback, object owner)
|
||||
{
|
||||
AddEventListenerImp(eventId, eventCallback, owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听具体实现。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="listener">事件回调。</param>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
private void AddEventListenerImp(int eventId, Delegate listener, object owner)
|
||||
{
|
||||
if (!_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
listListener = new List<EventRegInfo>();
|
||||
_allEventListenerMap.Add(eventId, listListener);
|
||||
}
|
||||
|
||||
var existNode = listListener.Find((node) => node.Callback == listener);
|
||||
if (existNode != null)
|
||||
{
|
||||
if (existNode.IsDeleted)
|
||||
{
|
||||
existNode.IsDeleted = false;
|
||||
Log.Warning("AddEvent hashId deleted, repeat add: {0}", eventId);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Fatal("AddEvent hashId repeated: {0}", eventId);
|
||||
return;
|
||||
}
|
||||
|
||||
listListener.Add(new EventRegInfo(listener, owner));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过持有者Tag移除监听。
|
||||
/// </summary>
|
||||
/// <param name="owner">持有者Tag。</param>
|
||||
public void RemoveAllListenerByOwner(object owner)
|
||||
{
|
||||
var itr = _allEventListenerMap.GetEnumerator();
|
||||
while (itr.MoveNext())
|
||||
{
|
||||
var kv = itr.Current;
|
||||
var list = kv.Value;
|
||||
|
||||
int eventId = kv.Key;
|
||||
bool isProcessing = _processEventList.Contains(eventId);
|
||||
bool delayDeleted = false;
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var regInfo = list[i];
|
||||
if (regInfo.Owner == owner)
|
||||
{
|
||||
if (isProcessing)
|
||||
{
|
||||
regInfo.IsDeleted = true;
|
||||
delayDeleted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list[i] = list[^1];
|
||||
list.RemoveAt(list.Count - 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (delayDeleted)
|
||||
{
|
||||
AddDelayDelete(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
itr.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">消息回调。</param>
|
||||
public void RemoveEventListener(int eventId, Action eventCallback)
|
||||
{
|
||||
RemoveEventListenerImp(eventId, eventCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">消息回调。</param>
|
||||
/// <typeparam name="TArg1">参数类型1。</typeparam>
|
||||
public void RemoveEventListener<TArg1>(int eventId, Action<TArg1> eventCallback)
|
||||
{
|
||||
RemoveEventListenerImp(eventId, eventCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">消息回调。</param>
|
||||
/// <typeparam name="TArg1">参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">参数类型2。</typeparam>
|
||||
public void RemoveEventListener<TArg1, TArg2>(int eventId, Action<TArg1, TArg2> eventCallback)
|
||||
{
|
||||
RemoveEventListenerImp(eventId, eventCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">消息回调。</param>
|
||||
/// <typeparam name="TArg1">参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">参数类型2。</typeparam>
|
||||
/// <typeparam name="TArg3">参数类型3。</typeparam>
|
||||
public void RemoveEventListener<TArg1, TArg2, TArg3>(int eventId, Action<TArg1, TArg2, TArg3> eventCallback)
|
||||
{
|
||||
RemoveEventListenerImp(eventId, eventCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="eventCallback">消息回调。</param>
|
||||
/// <typeparam name="TArg1">参数类型1。</typeparam>
|
||||
/// <typeparam name="TArg2">参数类型2。</typeparam>
|
||||
/// <typeparam name="TArg3">参数类型3。</typeparam>
|
||||
/// <typeparam name="TArg4">参数类型4。</typeparam>
|
||||
public void RemoveEventListener<TArg1, TArg2, TArg3, TArg4>(int eventId, Action<TArg1, TArg2, TArg3, TArg4> eventCallback)
|
||||
{
|
||||
RemoveEventListenerImp(eventId, eventCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除监听,如果是正在处理的监听则标记为删除
|
||||
/// </summary>
|
||||
/// <param name="eventId">事件Id。</param>
|
||||
/// <param name="listener">事件监听。</param>
|
||||
protected void RemoveEventListenerImp(int eventId, Delegate listener)
|
||||
{
|
||||
if (_allEventListenerMap.TryGetValue(eventId, out var listListener))
|
||||
{
|
||||
bool isProcessing = _processEventList.Contains(eventId);
|
||||
if (!isProcessing)
|
||||
{
|
||||
listListener.RemoveAll(node => node.Callback == listener);
|
||||
}
|
||||
else
|
||||
{
|
||||
int listenCnt = listListener.Count;
|
||||
for (int i = 0; i < listenCnt; i++)
|
||||
{
|
||||
var node = listListener[i];
|
||||
if (node.Callback == listener)
|
||||
{
|
||||
node.IsDeleted = true;
|
||||
AddDelayDelete(eventId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除回收接口。
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
DestroyAllEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件注册信息。
|
||||
/// </summary>
|
||||
public class EventRegInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件回调。
|
||||
/// </summary>
|
||||
public readonly Delegate Callback;
|
||||
|
||||
/// <summary>
|
||||
/// 事件持有者。
|
||||
/// </summary>
|
||||
public readonly object Owner;
|
||||
|
||||
/// <summary>
|
||||
/// 事件是否删除。
|
||||
/// </summary>
|
||||
public bool IsDeleted;
|
||||
|
||||
public EventRegInfo(Delegate callback, object owner)
|
||||
{
|
||||
this.Callback = callback;
|
||||
Owner = owner;
|
||||
IsDeleted = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 222c2a26f3b14d42950d0e9a10b61b38
|
||||
timeCreated: 1673511406
|
@@ -25,7 +25,7 @@ namespace TEngine
|
||||
var cts = new CancellationTokenSource();
|
||||
cts.CancelAfterSlim(TimeSpan.FromSeconds(timeout));
|
||||
|
||||
UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);
|
||||
using UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);
|
||||
return await SendWebRequest(unityWebRequest, cts);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace TEngine
|
||||
var cts = new CancellationTokenSource();
|
||||
cts.CancelAfterSlim(TimeSpan.FromSeconds(timeout));
|
||||
|
||||
UnityWebRequest unityWebRequest = UnityWebRequest.Post(url, postData);
|
||||
using UnityWebRequest unityWebRequest = UnityWebRequest.Post(url, postData);
|
||||
return await SendWebRequest(unityWebRequest, cts);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace TEngine
|
||||
var cts = new CancellationTokenSource();
|
||||
cts.CancelAfterSlim(TimeSpan.FromSeconds(timeout));
|
||||
|
||||
UnityWebRequest unityWebRequest = UnityWebRequest.Post(url, formFields);
|
||||
using UnityWebRequest unityWebRequest = UnityWebRequest.Post(url, formFields);
|
||||
return await SendWebRequest(unityWebRequest, cts);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace TEngine
|
||||
var cts = new CancellationTokenSource();
|
||||
cts.CancelAfterSlim(TimeSpan.FromSeconds(timeout));
|
||||
|
||||
UnityWebRequest unityWebRequest = UnityWebRequest.Post(url, formData);
|
||||
using UnityWebRequest unityWebRequest = UnityWebRequest.Post(url, formData);
|
||||
return await SendWebRequest(unityWebRequest, cts);
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ namespace TEngine
|
||||
if (isCanceled)
|
||||
{
|
||||
Log.Warning($"HttpPost {unityWebRequest.url} be canceled!");
|
||||
unityWebRequest.Dispose();
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
@@ -98,11 +100,14 @@ namespace TEngine
|
||||
if (ex.CancellationToken == cts.Token)
|
||||
{
|
||||
Log.Warning("HttpPost Timeout");
|
||||
unityWebRequest.Dispose();
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
return unityWebRequest.downloadHandler.text;
|
||||
string ret = unityWebRequest.downloadHandler.text;
|
||||
unityWebRequest.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);
|
||||
|
@@ -175,10 +175,7 @@ namespace TEngine
|
||||
/// <returns>音频代理辅助器。</returns>
|
||||
public static AudioAgent Create(string path, bool bAsync, AudioCategory audioCategory, bool bInPool = false)
|
||||
{
|
||||
AudioAgent audioAgent = new AudioAgent
|
||||
{
|
||||
_audioModuleImp = ModuleImpSystem.GetModule<AudioModuleImp>()
|
||||
};
|
||||
AudioAgent audioAgent = new AudioAgent();
|
||||
audioAgent.Init(audioCategory);
|
||||
audioAgent.Load(path, bAsync, bInPool);
|
||||
return audioAgent;
|
||||
@@ -191,6 +188,7 @@ namespace TEngine
|
||||
/// <param name="index">音频代理辅助器编号。</param>
|
||||
public void Init(AudioCategory audioCategory, int index = 0)
|
||||
{
|
||||
_audioModuleImp = ModuleImpSystem.GetModule<AudioModuleImp>();
|
||||
GameObject host = new GameObject(Utility.Text.Format("Audio Agent Helper - {0} - {1}", audioCategory.AudioMixerGroup.name, index));
|
||||
host.transform.SetParent(audioCategory.InstanceRoot);
|
||||
host.transform.localPosition = Vector3.zero;
|
||||
|
@@ -38,6 +38,8 @@ namespace TEngine
|
||||
[SerializeField]
|
||||
private DebuggerActiveWindowType m_ActiveWindow = DebuggerActiveWindowType.AlwaysOpen;
|
||||
|
||||
public DebuggerActiveWindowType ActiveWindowType => m_ActiveWindow;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_ShowFullWindow = false;
|
||||
|
||||
@@ -393,7 +395,7 @@ namespace TEngine
|
||||
DrawDebuggerWindowGroup(subDebuggerWindowGroup);
|
||||
}
|
||||
|
||||
debuggerWindowGroup.SelectedWindow.OnDraw();
|
||||
debuggerWindowGroup?.SelectedWindow?.OnDraw();
|
||||
}
|
||||
|
||||
private void DrawDebuggerWindowIcon(int windowId)
|
||||
|
@@ -11,18 +11,29 @@ namespace TEngine
|
||||
{
|
||||
private static readonly Dictionary<Type, Module> _moduleMaps = new Dictionary<Type, Module>(ModuleImpSystem.DesignModuleCount);
|
||||
|
||||
private static GameObject _gameModuleRoot;
|
||||
|
||||
#region 框架模块
|
||||
/// <summary>
|
||||
/// 获取游戏基础模块。
|
||||
/// </summary>
|
||||
public static RootModule Base => _base ??= Get<RootModule>();
|
||||
public static RootModule Base
|
||||
{
|
||||
get => _base ??= Get<RootModule>();
|
||||
private set => _base = value;
|
||||
}
|
||||
|
||||
private static RootModule _base;
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试模块。
|
||||
/// </summary>
|
||||
public static DebuggerModule Debugger => _debugger ??= Get<DebuggerModule>();
|
||||
public static DebuggerModule Debugger
|
||||
{
|
||||
get => _debugger ??= Get<DebuggerModule>();
|
||||
private set => _debugger = value;
|
||||
}
|
||||
|
||||
|
||||
private static DebuggerModule _debugger;
|
||||
|
||||
@@ -117,7 +128,31 @@ namespace TEngine
|
||||
{
|
||||
Log.Info("GameModule Active");
|
||||
gameObject.name = $"[{nameof(GameModule)}]";
|
||||
_gameModuleRoot = gameObject;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public static void Shutdown(ShutdownType shutdownType)
|
||||
{
|
||||
Log.Info("GameModule Shutdown");
|
||||
if (_gameModuleRoot != null)
|
||||
{
|
||||
Destroy(_gameModuleRoot);
|
||||
_gameModuleRoot = null;
|
||||
}
|
||||
_moduleMaps.Clear();
|
||||
|
||||
_base = null;
|
||||
_debugger = null;
|
||||
_fsm = null;
|
||||
_procedure = null;
|
||||
_objectPool = null;
|
||||
_resource = null;
|
||||
_audio = null;
|
||||
_setting = null;
|
||||
_ui = null;
|
||||
_localization = null;
|
||||
_scene = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -77,16 +77,17 @@ 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)
|
||||
{
|
||||
rootModule.Shutdown();
|
||||
rootModule = null;
|
||||
}
|
||||
|
||||
_modules.Clear();
|
||||
|
||||
GameModule.Shutdown(shutdownType);
|
||||
|
||||
if (shutdownType == ShutdownType.None)
|
||||
{
|
||||
return;
|
||||
|
@@ -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)
|
||||
{
|
||||
@@ -62,7 +71,7 @@ namespace TEngine
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_operationHandle != null)
|
||||
if (_operationHandle is { IsValid: true })
|
||||
{
|
||||
_operationHandle.Release();
|
||||
_operationHandle = 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;
|
||||
}
|
||||
|
@@ -0,0 +1,28 @@
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源管理日志实现器。
|
||||
/// </summary>
|
||||
internal class AssetsLogger : YooAsset.ILogger
|
||||
{
|
||||
public void Log(string message)
|
||||
{
|
||||
TEngine.Log.Info(message);
|
||||
}
|
||||
|
||||
public void Warning(string message)
|
||||
{
|
||||
TEngine.Log.Warning(message);
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
{
|
||||
TEngine.Log.Error(message);
|
||||
}
|
||||
|
||||
public void Exception(System.Exception exception)
|
||||
{
|
||||
TEngine.Log.Fatal(exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb010b07ce0e492dae9f04e18a1af2e2
|
||||
timeCreated: 1698250627
|
@@ -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,76 +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;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址。</param>
|
||||
/// <param name="sceneMode">场景加载模式。</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起。</param>
|
||||
/// <param name="priority">优先级。</param>
|
||||
/// <returns>异步加载场景句柄。</returns>
|
||||
SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景.
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息。</param>
|
||||
/// <param name="sceneMode">场景加载模式。</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起。</param>
|
||||
/// <param name="priority">优先级。</param>
|
||||
/// <returns>异步加载场景句柄。</returns>
|
||||
SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false,
|
||||
int priority = 100);
|
||||
UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag, string packageName = "") where T : UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源。
|
||||
@@ -276,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>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -286,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>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -296,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>
|
||||
/// 异步加载子文件。
|
||||
@@ -313,29 +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="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="sceneMode">场景加载模式。</param>
|
||||
/// <param name="activateOnLoad">加载完毕时是否主动激活。</param>
|
||||
/// <param name="priority">优先级。</param>
|
||||
/// <returns>场景资源实例。</returns>
|
||||
UniTask<Scene> LoadSceneAsyncByUniTask(string location, CancellationToken cancellationToken = default, LoadSceneMode sceneMode = LoadSceneMode.Single,
|
||||
bool activateOnLoad = true, int priority = 100);
|
||||
/// <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)
|
||||
{
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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,64 +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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <returns>异步加载场景句柄。</returns>
|
||||
public SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false,
|
||||
int priority = 100)
|
||||
{
|
||||
return m_ResourceManager.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <returns>异步加载场景句柄。</returns>
|
||||
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false,
|
||||
int priority = 100)
|
||||
{
|
||||
return m_ResourceManager.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||
return await m_ResourceManager.LoadAssetsByTagAsync<T>(assetTag, packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -619,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>
|
||||
@@ -632,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>
|
||||
@@ -645,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>
|
||||
@@ -656,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>
|
||||
@@ -668,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>
|
||||
@@ -680,26 +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="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="sceneMode">场景加载模式。</param>
|
||||
/// <param name="activateOnLoad">加载完毕时是否主动激活。</param>
|
||||
/// <param name="priority">优先级。</param>
|
||||
/// <returns>场景资源实例。</returns>
|
||||
public async UniTask<Scene> LoadSceneAsyncByUniTask(string location, CancellationToken cancellationToken = default,
|
||||
LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
|
||||
/// <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 await m_ResourceManager.LoadSceneAsyncByUniTask(location, cancellationToken, sceneMode, activateOnLoad, priority);
|
||||
return m_ResourceManager.GetPreLoadAsset<T>(location, packageName: customPackageName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -20,8 +20,14 @@ namespace TEngine
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true);
|
||||
/// <param name="progressCallBack">加载进度回调。</param>
|
||||
public SceneOperationHandle LoadScene(string location,
|
||||
LoadSceneMode sceneMode = LoadSceneMode.Single,
|
||||
bool suspendLoad = false,
|
||||
int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null,
|
||||
bool gcCollect = true,
|
||||
Action<float> progressCallBack = null);
|
||||
|
||||
/// <summary>
|
||||
/// 激活场景(当同时存在多个场景时用于切换激活场景)。
|
||||
|
@@ -42,10 +42,11 @@ namespace TEngine
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true)
|
||||
/// <param name="progressCallBack">加载进度回调。</param>
|
||||
public SceneOperationHandle LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true, Action<float> progressCallBack = null)
|
||||
{
|
||||
_sceneModule.LoadScene(location, sceneMode, suspendLoad, priority, callBack, gcCollect);
|
||||
return _sceneModule.LoadScene(location, sceneMode, suspendLoad, priority, callBack, gcCollect, progressCallBack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,10 +57,11 @@ namespace TEngine
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadSubScene(string location, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true)
|
||||
/// <param name="progressCallBack">加载进度回调。</param>
|
||||
public SceneOperationHandle LoadSubScene(string location, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true, Action<float> progressCallBack = null)
|
||||
{
|
||||
_sceneModule.LoadScene(location, LoadSceneMode.Additive, suspendLoad, priority, callBack, gcCollect);
|
||||
return _sceneModule.LoadScene(location, LoadSceneMode.Additive, suspendLoad, priority, callBack, gcCollect, progressCallBack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
@@ -8,7 +9,7 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 场景管理器。
|
||||
/// </summary>
|
||||
internal class SceneModuleImp : ModuleImp,ISceneModule
|
||||
internal class SceneModuleImp : ModuleImp, ISceneModule
|
||||
{
|
||||
private string _currentMainSceneName = string.Empty;
|
||||
|
||||
@@ -40,40 +41,83 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 加载场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="location">场景的定位地址</param>R
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100, Action<SceneOperationHandle> callBack = null,bool gcCollect = true)
|
||||
/// <param name="progressCallBack">加载进度回调。</param>
|
||||
public SceneOperationHandle LoadScene(string location,
|
||||
LoadSceneMode sceneMode = LoadSceneMode.Single,
|
||||
bool suspendLoad = false,
|
||||
int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null,
|
||||
bool gcCollect = true,
|
||||
Action<float> progressCallBack = null)
|
||||
{
|
||||
if (sceneMode == LoadSceneMode.Additive)
|
||||
{
|
||||
if (_subScenes.ContainsKey(location))
|
||||
if (_subScenes.TryGetValue(location, out SceneOperationHandle subScene))
|
||||
{
|
||||
Log.Warning($"Could not load subScene while already loaded. Scene: {location}");
|
||||
return;
|
||||
return subScene;
|
||||
}
|
||||
var subScene = GameModule.Resource.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
subScene = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
subScene.Completed += callBack;
|
||||
}
|
||||
|
||||
if (progressCallBack != null)
|
||||
{
|
||||
InvokeProgress(subScene, progressCallBack).Forget();
|
||||
}
|
||||
_subScenes.Add(location, subScene);
|
||||
|
||||
return subScene;
|
||||
}
|
||||
else if(sceneMode == LoadSceneMode.Single)
|
||||
else
|
||||
{
|
||||
if (_currentMainScene is { IsDone: false })
|
||||
{
|
||||
Log.Warning($"Could not load MainScene while loading. CurrentMainScene: {_currentMainSceneName}.");
|
||||
return null;
|
||||
}
|
||||
|
||||
_currentMainSceneName = location;
|
||||
|
||||
_currentMainScene = GameModule.Resource.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
_currentMainScene = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
_currentMainScene.Completed += callBack;
|
||||
}
|
||||
|
||||
if (progressCallBack != null)
|
||||
{
|
||||
InvokeProgress(_currentMainScene, progressCallBack).Forget();
|
||||
}
|
||||
|
||||
GameModule.Resource.ForceUnloadUnusedAssets(gcCollect);
|
||||
|
||||
return _currentMainScene;
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTaskVoid InvokeProgress(SceneOperationHandle sceneOperationHandle,Action<float> progress)
|
||||
{
|
||||
if (sceneOperationHandle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (!sceneOperationHandle.IsDone)
|
||||
{
|
||||
await UniTask.Yield();
|
||||
|
||||
progress?.Invoke(sceneOperationHandle.Progress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fefbf9d90fc46eaaa7d12e5cd8cd219
|
||||
timeCreated: 1698301646
|
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 组件自动绑定工具
|
||||
/// </summary>
|
||||
public class ComponentAutoBindTool : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[Serializable]
|
||||
public class BindData
|
||||
{
|
||||
public BindData()
|
||||
{
|
||||
}
|
||||
|
||||
public BindData(string name, Component bindCom, bool isGameObject = false)
|
||||
{
|
||||
Name = name;
|
||||
BindCom = bindCom;
|
||||
IsGameObject = isGameObject;
|
||||
}
|
||||
|
||||
public string Name;
|
||||
public Component BindCom;
|
||||
public bool IsGameObject;
|
||||
}
|
||||
|
||||
public List<BindData> BindDatas = new List<BindData>();
|
||||
|
||||
[SerializeField]
|
||||
private string m_ClassName;
|
||||
|
||||
[SerializeField]
|
||||
private string m_Namespace;
|
||||
|
||||
[SerializeField]
|
||||
private string m_CodePath;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_IsWidget;
|
||||
|
||||
public string ClassName => m_ClassName;
|
||||
|
||||
public string Namespace => m_Namespace;
|
||||
|
||||
public string CodePath => m_CodePath;
|
||||
|
||||
|
||||
public bool IsWidget => m_IsWidget;
|
||||
|
||||
public IAutoBindRuleHelper RuleHelper
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#endif
|
||||
|
||||
[SerializeField]
|
||||
public List<Component> bindComponents = new List<Component>();
|
||||
|
||||
public T GetBindComponent<T>(int index) where T : Component
|
||||
{
|
||||
if (index >= bindComponents.Count)
|
||||
{
|
||||
Debug.LogError("索引无效");
|
||||
return null;
|
||||
}
|
||||
|
||||
T bindCom = bindComponents[index] as T;
|
||||
|
||||
if (bindCom == null)
|
||||
{
|
||||
Debug.LogError("类型无效");
|
||||
return null;
|
||||
}
|
||||
|
||||
return bindCom;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59269a619eb50d048840c07a31b0d368
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,77 @@
|
||||
#if false
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 默认自动绑定规则辅助器
|
||||
/// </summary>
|
||||
public class DefaultAutoBindRuleHelper : IAutoBindRuleHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 命名前缀与类型的映射
|
||||
/// </summary>
|
||||
private Dictionary<string, string> m_PrefixesDict = new Dictionary<string, string>()
|
||||
{
|
||||
{"Trans","Transform" },
|
||||
{"OldAnim","Animation"},
|
||||
{"NewAnim","Animator"},
|
||||
|
||||
{"Rect","RectTransform"},
|
||||
{"Canvas","Canvas"},
|
||||
{"Group","CanvasGroup"},
|
||||
{"VGroup","VerticalLayoutGroup"},
|
||||
{"HGroup","HorizontalLayoutGroup"},
|
||||
{"GGroup","GridLayoutGroup"},
|
||||
{"TGroup","ToggleGroup"},
|
||||
|
||||
{"Btn","UIButtonSuper"},
|
||||
{"Img","Image"},
|
||||
{"RImg","RawImage"},
|
||||
{"Txt","Text"},
|
||||
{"TxtM","TextMeshProUGUI"},
|
||||
{"Input","TMP_InputField"},
|
||||
{"Slider","Slider"},
|
||||
{"Mask","Mask"},
|
||||
{"Mask2D","RectMask2D"},
|
||||
{"Tog","Toggle"},
|
||||
{"Sbar","Scrollbar"},
|
||||
{"SRect","ScrollRect"},
|
||||
{"Drop","Dropdown"},
|
||||
{"USpriteAni","UGUISpriteAnimation"},
|
||||
{"VGridV","LoopGridView"},
|
||||
{"HGridV","LoopGridView"},
|
||||
{"VListV","LoopListView2"},
|
||||
{"HListV","LoopListView2"},
|
||||
};
|
||||
|
||||
public bool IsValidBind( Transform target, List<string> filedNames, List<string> componentTypeNames)
|
||||
{
|
||||
string[] strArray = target.name.Split('_');
|
||||
|
||||
if (strArray.Length == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string filedName = strArray[^1];
|
||||
|
||||
for (int i = 0; i < strArray.Length - 1; i++)
|
||||
{
|
||||
string str = strArray[i];
|
||||
if (m_PrefixesDict.TryGetValue(str,out var componentName))
|
||||
{
|
||||
filedNames.Add($"{str}_{filedName}");
|
||||
componentTypeNames.Add(componentName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"{target.name}的命名中{str}不存在对应的组件类型,绑定失败");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48a5faab9d684f14a38c5a001326eb03
|
||||
timeCreated: 1698301686
|
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 自动绑定规则辅助器接口
|
||||
/// </summary>
|
||||
public interface IAutoBindRuleHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否为有效绑定
|
||||
/// </summary>
|
||||
bool IsValidBind(Transform target,List<string> filedNames,List<string> componentTypeNames);
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5654ec3474b94b7fa84dfdc684fe2fa9
|
||||
timeCreated: 1698301670
|
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// UI自动绑定规则辅助器
|
||||
/// </summary>
|
||||
public class UIAutoBindRuleHelper: IAutoBindRuleHelper
|
||||
{
|
||||
public bool IsValidBind( Transform targetTransform, List<string> filedNames, List<string> componentTypeNames)
|
||||
{
|
||||
string uiElementName = targetTransform.name;
|
||||
string[] strArray = targetTransform.name.Split('_');
|
||||
|
||||
if (strArray.Length == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string filedName = strArray[^1];
|
||||
var rule = SettingsUtils.GetScriptGenerateRule().Find(t => uiElementName.StartsWith(t.uiElementRegex));
|
||||
|
||||
if (rule != null)
|
||||
{
|
||||
filedNames.Add($"{filedName}");
|
||||
componentTypeNames.Add(rule.componentName);
|
||||
return true;
|
||||
}
|
||||
Debug.LogWarning($"{targetTransform.name}的命名中{uiElementName}不存在对应的组件类型,绑定失败");
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4256bde2e254a7f91fc70ea1f7420d8
|
||||
timeCreated: 1698306650
|
@@ -1,15 +1,16 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class ErrorLogger
|
||||
public class ErrorLogger:IDisposable
|
||||
{
|
||||
public ErrorLogger()
|
||||
{
|
||||
Application.logMessageReceived += LogHandler;
|
||||
}
|
||||
|
||||
~ErrorLogger()
|
||||
public void Dispose()
|
||||
{
|
||||
Application.logMessageReceived -= LogHandler;
|
||||
}
|
||||
|
@@ -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
|
||||
{
|
||||
@@ -513,54 +527,5 @@ namespace TEngine
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UIElement
|
||||
|
||||
/// <summary>
|
||||
/// UI元素节点。
|
||||
/// </summary>
|
||||
protected UIElement UIElement;
|
||||
|
||||
/// <summary>
|
||||
/// 检测UI元素节点。
|
||||
/// </summary>
|
||||
protected virtual void CheckUIElement()
|
||||
{
|
||||
if (rectTransform != null)
|
||||
{
|
||||
UIElement = rectTransform.GetComponent<UIElement>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取子节点。
|
||||
/// </summary>
|
||||
/// <param name="childName">子节点名称。</param>
|
||||
/// <returns>子节点位置实例。</returns>
|
||||
protected Transform FChild(string childName)
|
||||
{
|
||||
if (UIElement != null)
|
||||
{
|
||||
var child = UIElement.Get(childName);
|
||||
if (child != null)
|
||||
{
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return FindChild(childName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取子节点脚本。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">子节点类型。</typeparam>
|
||||
/// <param name="childName">子节点名称。</param>
|
||||
/// <returns>子节点脚本实例。</returns>
|
||||
protected T FChild<T>(string childName) where T : Component
|
||||
{
|
||||
var child = FChild(childName);
|
||||
return child == null ? null : child.GetComponent<T>();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// UI元素节点。
|
||||
/// <remarks>通过mono序列化来绑定ui节点的元素换取查找与ui的稳定性。</remarks>
|
||||
/// </summary>
|
||||
public class UIElement : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// UI元素。
|
||||
/// </summary>
|
||||
[SerializeField] protected SerializableDictionary<string, Transform> elements = new SerializableDictionary<string, Transform>();
|
||||
|
||||
/// <summary>
|
||||
/// UI元素。
|
||||
/// </summary>
|
||||
public SerializableDictionary<string, Transform> Elements => elements;
|
||||
|
||||
/// <summary>
|
||||
/// 获取UI元素。
|
||||
/// </summary>
|
||||
/// <param name="uiID">ui元素标识。</param>
|
||||
/// <returns>UI元素。</returns>
|
||||
public Transform Get(string uiID)
|
||||
{
|
||||
elements.TryGetValue(uiID, out var uiTransform);
|
||||
return uiTransform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取UI元素。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">ui元素类型。</typeparam>
|
||||
/// <param name="uiID">ui元素标识。</param>
|
||||
/// <returns>ui元素标识。</returns>
|
||||
public T Get<T>(string uiID) where T : Component
|
||||
{
|
||||
var uiTransform = Get(uiID);
|
||||
return uiTransform == null ? null : uiTransform.GetComponent<T>();
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
elements.Clear();
|
||||
elements = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcd11033283847ee8f7c71eedd9a4771
|
||||
timeCreated: 1696656961
|
@@ -68,6 +68,25 @@ namespace TEngine
|
||||
|
||||
m_InstanceRoot.gameObject.layer = LayerMask.NameToLayer("UI");
|
||||
UIRootStatic = m_InstanceRoot;
|
||||
|
||||
switch (GameModule.Debugger.ActiveWindowType)
|
||||
{
|
||||
case DebuggerActiveWindowType.AlwaysOpen:
|
||||
m_enableErrorLog = true;
|
||||
break;
|
||||
|
||||
case DebuggerActiveWindowType.OnlyOpenWhenDevelopment:
|
||||
m_enableErrorLog = Debug.isDebugBuild;
|
||||
break;
|
||||
|
||||
case DebuggerActiveWindowType.OnlyOpenInEditor:
|
||||
m_enableErrorLog = Application.isEditor;
|
||||
break;
|
||||
|
||||
default:
|
||||
m_enableErrorLog = false;
|
||||
break;
|
||||
}
|
||||
if (m_enableErrorLog)
|
||||
{
|
||||
_errorLogger = new ErrorLogger();
|
||||
@@ -76,7 +95,16 @@ namespace TEngine
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_errorLogger != null)
|
||||
{
|
||||
_errorLogger.Dispose();
|
||||
_errorLogger = null;
|
||||
}
|
||||
CloseAll();
|
||||
if (m_InstanceRoot != null && m_InstanceRoot.parent != null)
|
||||
{
|
||||
Destroy(m_InstanceRoot.parent.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#region 设置安全区域
|
||||
|
@@ -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