- 引入 UnityGameFramework

- 使用 Luban 替代原来的 UGF 的数据表
This commit is contained in:
huangjun
2026-08-30 18:08:55 +08:00
parent 42ad134759
commit 92bf3e9097
1925 changed files with 362268 additions and 4859 deletions
@@ -0,0 +1,82 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace SepCore.UI
{
public class CommonButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{
private const float FadeTime = 0.3f;
private const float OnHoverAlpha = 0.7f;
private const float OnClickAlpha = 0.6f;
[SerializeField]
private UnityEvent m_OnHover = null;
[SerializeField]
private UnityEvent m_OnClick = null;
private CanvasGroup m_CanvasGroup = null;
private void Awake()
{
m_CanvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
}
private void OnDisable()
{
m_CanvasGroup.alpha = 1f;
}
public void OnPointerEnter(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left)
{
return;
}
StopAllCoroutines();
StartCoroutine(m_CanvasGroup.FadeToAlpha(OnHoverAlpha, FadeTime));
m_OnHover.Invoke();
}
public void OnPointerExit(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left)
{
return;
}
StopAllCoroutines();
StartCoroutine(m_CanvasGroup.FadeToAlpha(1f, FadeTime));
}
public void OnPointerDown(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left)
{
return;
}
m_CanvasGroup.alpha = OnClickAlpha;
m_OnClick.Invoke();
}
public void OnPointerUp(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left)
{
return;
}
m_CanvasGroup.alpha = OnHoverAlpha;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a5079836f95c2a44b96fa331487ebb70
timeCreated: 1528026160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,116 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
namespace SepCore.UI
{
/// <summary>
/// 对话框显示数据。
/// </summary>
public class DialogParams
{
/// <summary>
/// 模式,即按钮数量。取值 1、2、3。
/// </summary>
public int Mode
{
get;
set;
}
/// <summary>
/// 标题。
/// </summary>
public string Title
{
get;
set;
}
/// <summary>
/// 消息内容。
/// </summary>
public string Message
{
get;
set;
}
/// <summary>
/// 弹出窗口时是否暂停游戏。
/// </summary>
public bool PauseGame
{
get;
set;
}
/// <summary>
/// 确认按钮文本。
/// </summary>
public string ConfirmText
{
get;
set;
}
/// <summary>
/// 确定按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickConfirm
{
get;
set;
}
/// <summary>
/// 取消按钮文本。
/// </summary>
public string CancelText
{
get;
set;
}
/// <summary>
/// 取消按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickCancel
{
get;
set;
}
/// <summary>
/// 中立按钮文本。
/// </summary>
public string OtherText
{
get;
set;
}
/// <summary>
/// 其它按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickOther
{
get;
set;
}
/// <summary>
/// 用户自定义数据。
/// </summary>
public string UserData
{
get;
set;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ad9ca3c36c52b0a4e8b25c8b451966da
timeCreated: 1528026160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,243 @@
using System.Collections;
using System.Collections.Generic;
using SepCore.Sound;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace SepCore.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()
{
Close(false);
}
public void Close(bool ignoreFade)
{
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,46 @@
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace SepCore.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 transform = GetComponent<RectTransform>();
transform.anchorMin = Vector2.zero;
transform.anchorMax = Vector2.one;
transform.anchoredPosition = Vector2.zero;
transform.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,37 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace SepCore.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;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 75bcd42d756109f43ba02364f595a6b5
timeCreated: 1528026162
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: