第一批重构,主要是物理迁移脚本和部分命名空间的调整

- 结构上迁移文件,将脚本分成 Base/Runtime/Presentation/Procedure/Editor 五大文件夹
- 调整 DataTable 和 Definition 下脚本的命名空间
- 依据 UI-5层架构设计规范 拆分原先的 UI 到 Runtime 和 Presentation 下
This commit is contained in:
SepComet
2026-06-02 19:12:34 +08:00
parent 56f74eee9a
commit 34c0784190
655 changed files with 1272 additions and 516 deletions
@@ -0,0 +1,9 @@
namespace UI
{
public interface IUIFormController
{
int? OpenUI(object userData = null);
void CloseUI();
void BindUseCase(IUIUseCase useCase);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08145adf06b2b2c4b9d61d3ef6d39cfc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UI
{
public interface IUIUseCase
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8b527e4ad6d6207418137211caa179d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,245 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using StarForce;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
{
public abstract class UGuiForm : UIFormLogic
{
public const int DepthFactor = 100;
private const float FadeTime = 0.3f;
private static Font _mainFont = null;
private static TMP_FontAsset _mainTMPFont = null;
private Canvas _cachedCanvas = null;
private CanvasGroup _canvasGroup = null;
private List<Canvas> _cachedCanvasContainer = new List<Canvas>();
public int OriginalDepth { get; private set; }
public int Depth => _cachedCanvas.sortingOrder;
public void Close(bool ignoreFade = false)
{
StopAllCoroutines();
if (ignoreFade)
{
GameEntry.UI.CloseUIForm(this);
}
else
{
StartCoroutine(CloseCo(FadeTime));
}
}
public void PlayUISound(int uiSoundId)
{
GameEntry.Sound.PlayUISound(uiSoundId);
}
public static void SetMainFont(Font mainFont)
{
if (mainFont == null)
{
Log.Error("Main font is invalid.");
return;
}
_mainFont = mainFont;
}
public static void SetMainTMPFont(TMP_FontAsset mainTMPFont)
{
if (mainTMPFont == null)
{
Log.Error("Main font is invalid.");
return;
}
_mainTMPFont = mainTMPFont;
}
#if UNITY_2017_3_OR_NEWER
protected override void OnInit(object userData)
#else
protected internal override void OnInit(object userData)
#endif
{
base.OnInit(userData);
_cachedCanvas = gameObject.GetOrAddComponent<Canvas>();
_cachedCanvas.overrideSorting = true;
OriginalDepth = _cachedCanvas.sortingOrder;
_canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
RectTransform rect = GetComponent<RectTransform>();
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero;
gameObject.GetOrAddComponent<GraphicRaycaster>();
if (_mainTMPFont == null)
{
Log.Warning("Main TMP font isn't set.");
}
else
{
var tmp_texts = GetComponentsInChildren<TMP_Text>(true);
foreach (var text in tmp_texts)
{
text.font = _mainTMPFont;
// if (!string.IsNullOrEmpty(text.text))
// {
// text.text = GameEntry.Localization.GetString(text.text);
// }
}
}
if (_mainFont == null)
{
Log.Warning("Main font isn't set.");
}
else
{
var texts = GetComponentsInChildren<Text>(true);
foreach (var text in texts)
{
text.font = _mainFont;
// if (!string.IsNullOrEmpty(text.text))
// {
// text.text = GameEntry.Localization.GetString(text.text);
// }
}
}
}
#if UNITY_2017_3_OR_NEWER
protected override void OnRecycle()
#else
protected internal override void OnRecycle()
#endif
{
base.OnRecycle();
}
#if UNITY_2017_3_OR_NEWER
protected override void OnOpen(object userData)
#else
protected internal override void OnOpen(object userData)
#endif
{
base.OnOpen(userData);
_canvasGroup.alpha = 0f;
StopAllCoroutines();
StartCoroutine(_canvasGroup.FadeToAlpha(1f, FadeTime));
}
#if UNITY_2017_3_OR_NEWER
protected override void OnClose(bool isShutdown, object userData)
#else
protected internal override void OnClose(bool isShutdown, object userData)
#endif
{
base.OnClose(isShutdown, userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnPause()
#else
protected internal override void OnPause()
#endif
{
base.OnPause();
}
#if UNITY_2017_3_OR_NEWER
protected override void OnResume()
#else
protected internal override void OnResume()
#endif
{
base.OnResume();
_canvasGroup.alpha = 0f;
StopAllCoroutines();
StartCoroutine(_canvasGroup.FadeToAlpha(1f, FadeTime));
}
#if UNITY_2017_3_OR_NEWER
protected override void OnCover()
#else
protected internal override void OnCover()
#endif
{
base.OnCover();
}
#if UNITY_2017_3_OR_NEWER
protected override void OnReveal()
#else
protected internal override void OnReveal()
#endif
{
base.OnReveal();
}
#if UNITY_2017_3_OR_NEWER
protected override void OnRefocus(object userData)
#else
protected internal override void OnRefocus(object userData)
#endif
{
base.OnRefocus(userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
#else
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
#endif
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
#else
protected internal override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
#endif
{
int oldDepth = Depth;
base.OnDepthChanged(uiGroupDepth, depthInUIGroup);
int deltaDepth = UGuiGroupHelper.DepthFactor * uiGroupDepth + DepthFactor * depthInUIGroup - oldDepth +
OriginalDepth;
GetComponentsInChildren(true, _cachedCanvasContainer);
for (int i = 0; i < _cachedCanvasContainer.Count; i++)
{
_cachedCanvasContainer[i].sortingOrder += deltaDepth;
}
_cachedCanvasContainer.Clear();
}
private IEnumerator CloseCo(float duration)
{
yield return _canvasGroup.FadeToAlpha(0f, duration);
GameEntry.UI.CloseUIForm(this);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0b92f84dc56dc764a9c261fe47df5520
timeCreated: 1528026161
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
{
/// <summary>
/// uGUI 界面组辅助器。
/// </summary>
public class UGuiGroupHelper : UIGroupHelperBase
{
public const int DepthFactor = 10000;
private int m_Depth = 0;
private Canvas m_CachedCanvas = null;
/// <summary>
/// 设置界面组深度。
/// </summary>
/// <param name="depth">界面组深度。</param>
public override void SetDepth(int depth)
{
m_Depth = depth;
m_CachedCanvas.overrideSorting = true;
m_CachedCanvas.sortingOrder = DepthFactor * depth;
}
private void Awake()
{
m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
gameObject.GetOrAddComponent<GraphicRaycaster>();
}
private void Start()
{
m_CachedCanvas.overrideSorting = true;
m_CachedCanvas.sortingOrder = DepthFactor * m_Depth;
RectTransform rect = GetComponent<RectTransform>();
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 05a35a4a1f7dd5646a70cb1a73348780
timeCreated: 1528026161
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UI
{
public class UIContext
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7ac4a8b30b5b7684ca58f70386314a4b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,160 @@
using GameFramework.DataTable;
using GameFramework.UI;
using System.Collections;
using SepCore.DataTable;
using SepCore.Definition;
using CustomUtility;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
{
public static class UIExtension
{
public static IEnumerator FadeToAlpha(this CanvasGroup canvasGroup, float alpha, float duration)
{
float time = 0f;
float originalAlpha = canvasGroup.alpha;
while (time < duration)
{
time += Time.deltaTime;
canvasGroup.alpha = Mathf.Lerp(originalAlpha, alpha, time / duration);
yield return new WaitForEndOfFrame();
}
canvasGroup.alpha = alpha;
}
public static IEnumerator SmoothValue(this Slider slider, float value, float duration)
{
float time = 0f;
float originalValue = slider.value;
while (time < duration)
{
time += Time.deltaTime;
slider.value = Mathf.Lerp(originalValue, value, time / duration);
yield return new WaitForEndOfFrame();
}
slider.value = value;
}
public static bool HasUIForm(this UIComponent uiComponent, UIFormType uiFormType, string uiGroupName = null)
{
return uiComponent.HasUIForm((int)uiFormType, uiGroupName);
}
public static bool HasUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return false;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (string.IsNullOrEmpty(uiGroupName))
{
return uiComponent.HasUIForm(assetName);
}
IUIGroup uiGroup = uiComponent.GetUIGroup(uiGroupName);
if (uiGroup == null)
{
return false;
}
return uiGroup.HasUIForm(assetName);
}
public static UGuiForm GetUIForm(this UIComponent uiComponent, UIFormType uiFormType, string uiGroupName = null)
{
return uiComponent.GetUIForm((int)uiFormType, uiGroupName);
}
public static UGuiForm GetUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
UIForm uiForm = null;
if (string.IsNullOrEmpty(uiGroupName))
{
uiForm = uiComponent.GetUIForm(assetName);
if (uiForm == null)
{
return null;
}
return (UGuiForm)uiForm.Logic;
}
IUIGroup uiGroup = uiComponent.GetUIGroup(uiGroupName);
if (uiGroup == null)
{
return null;
}
uiForm = (UIForm)uiGroup.GetUIForm(assetName);
if (uiForm == null)
{
return null;
}
return (UGuiForm)uiForm.Logic;
}
public static void CloseUIForm(this UIComponent uiComponent, UGuiForm uiForm)
{
uiComponent.CloseUIForm(uiForm.UIForm);
}
public static int? OpenUIForm(this UIComponent uiComponent, UIFormType uiFormType, object userData = null)
{
return uiComponent.OpenUIForm((int)uiFormType, userData);
}
public static int? OpenUIForm(this UIComponent uiComponent, int uiFormId, object userData = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
Log.Warning("Can not load UI form '{0}' from data table.", uiFormId.ToString());
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (!drUIForm.AllowMultiInstance)
{
if (uiComponent.IsLoadingUIForm(assetName))
{
return null;
}
if (uiComponent.HasUIForm(assetName))
{
return null;
}
}
return uiComponent.OpenUIForm(assetName, drUIForm.UIGroupName, Constant.AssetPriority.UIFormAsset, drUIForm.PauseCoveredUIForm, userData);
}
private static void OpenNativeDialog(DialogFormRawData rawData)
{
// TODO:这里应该弹出原生对话框,先简化实现为直接按确认按钮
if (rawData != null && rawData.OnClickConfirm != null)
{
rawData.OnClickConfirm(rawData.UserData);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9cfc2c881ce240349901812c61f4476b
timeCreated: 1528026162
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
namespace UI
{
public abstract class UIFormControllerBase<TContext> : IUIFormController where TContext : UIContext
{
protected abstract int? OpenUIInternal(TContext context);
public abstract int? OpenUI(object userData = null);
public abstract void CloseUI();
public abstract void BindUseCase(IUIUseCase useCase);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 692b282b1ecbf5a44839d5bf4a03a937
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,183 @@
using SepCore.Definition;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public abstract class UIFormControllerCommonBase<TContext, TForm> : UIFormControllerBase<TContext>
where TContext : UIContext
where TForm : UGuiForm
{
private TContext _context;
private TForm _form;
private int? _formSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
protected TContext Context => _context;
protected TForm Form => _form;
protected int? FormSerialId => _formSerialId;
protected abstract UIFormType UIFormTypeId { get; }
protected abstract void RefreshUI(TForm form, TContext context);
protected virtual void SubscribeCustomEvents()
{
}
protected virtual void UnsubscribeCustomEvents()
{
}
protected virtual void CloseLoadedFormDirect(TForm form)
{
form.Close();
}
protected void SetContext(TContext context)
{
_context = context;
}
protected void RefreshCurrentUI()
{
if (_context == null)
{
return;
}
if (_form == null)
{
_pendingRefresh = true;
return;
}
RefreshUI(_form, _context);
_pendingRefresh = false;
}
protected override int? OpenUIInternal(TContext context)
{
if (context == null)
{
Log.Warning("{0}.OpenUI() context is null.", GetType().Name);
return null;
}
_context = context;
if (_form != null && _formSerialId.HasValue && GameEntry.UI.HasUIForm(_formSerialId.Value))
{
RefreshUI(_form, _context);
return _formSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_formSerialId = GameEntry.UI.OpenUIForm(UIFormTypeId, _context);
return _formSerialId;
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_formSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_formSerialId.Value))
{
GameEntry.UI.CloseUIForm(_formSerialId.Value);
}
_form = null;
_formSerialId = null;
return;
}
if (_form != null)
{
CloseLoadedFormDirect(_form);
_form = null;
}
}
private void SubscribeEvents()
{
if (_isBindEvent)
{
return;
}
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
SubscribeCustomEvents();
_isBindEvent = true;
}
private void UnsubscribeEvents()
{
if (!_isBindEvent)
{
return;
}
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
UnsubscribeCustomEvents();
_isBindEvent = false;
}
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_formSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _formSerialId.Value || args.UserData != _context)
{
return;
}
_form = args.UIForm.Logic as TForm;
if (_form == null)
{
Log.Warning("{0} open success but form logic is invalid.", GetType().Name);
return;
}
if (_pendingRefresh)
{
RefreshCurrentUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _formSerialId)
{
return;
}
_form = null;
_formSerialId = null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 696c0314286f89c4082c2aa2eddaec2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
using SepCore.Definition;
using UnityGameFramework.Runtime;
namespace UI
{
public class TUIFormController : UIFormControllerCommonBase<UIContext, TUIForm>
{
private IUIUseCase _useCase;
protected override UIFormType UIFormTypeId => UIFormType.TUIForm;
protected override void RefreshUI(TUIForm form, UIContext context)
{
form.RefreshUI(context);
}
public override int? OpenUI(object userData = null)
{
if (userData is UIContext context)
{
return OpenUIInternal(context);
}
if (userData != null)
{
Log.Warning("TUIFormController.OpenUI() userData type is invalid.");
return null;
}
return OpenUIInternal(Context);
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is IUIUseCase uiFormUseCase))
{
Log.Error("LevelUpForm.BindUseCase() useCase is invalid.");
return;
}
_useCase = uiFormUseCase;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e46538e3d51b6b4ca463fa6080ad335
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using UnityEngine;
using UnityGameFramework.Runtime;
namespace UI
{
public class TUIForm : UGuiForm
{
public void RefreshUI(UIContext context)
{
}
protected override void OnOpen(object userData)
{
base.OnOpen(userData);
if (!(userData is UIContext context))
{
Log.Error("UIContext is invalid.");
return;
}
RefreshUI(context);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8bc5e59a2be3094798c8c46d1a4999f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: