继续重构调整(UI)

- 引入 UniTask 和异步版本的 UIModule
- 调整 Runtime/UIBase 和 Presentation 下的脚本命名空间到 SepCore.UI
- 将原来的 5 层 UI 迁移到异步实现
- 规范各层的 UI 脚本命名
This commit is contained in:
SepComet
2026-06-03 09:58:37 +08:00
parent 6b8a6a8789
commit 7bba8bbb80
552 changed files with 83648 additions and 2726 deletions
@@ -1,14 +1,8 @@
//------------------------------------------------------------
// 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;
using Entity;
using UI;
using SepCore.UI;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
@@ -20,22 +14,15 @@ namespace StarForce
private const float KeepSeconds = 0.4f;
private const float FadeOutSeconds = 0.3f;
[SerializeField]
private Slider m_HPBar = null;
[FormerlySerializedAs("m_HPBar")] [SerializeField] private Slider _hPBar = null;
private Canvas m_ParentCanvas = null;
private RectTransform m_CachedTransform = null;
private CanvasGroup m_CachedCanvasGroup = null;
private EntityBase m_Owner = null;
private Canvas _parentCanvas = null;
private RectTransform _cachedTransform = null;
private CanvasGroup _cachedCanvasGroup = null;
private EntityBase _owner = null;
private int m_OwnerId = 0;
public EntityBase Owner
{
get
{
return m_Owner;
}
}
public EntityBase Owner => _owner;
public void Init(EntityBase owner, Canvas parentCanvas, float fromHPRatio, float toHPRatio)
{
@@ -45,16 +32,16 @@ namespace StarForce
return;
}
m_ParentCanvas = parentCanvas;
_parentCanvas = parentCanvas;
gameObject.SetActive(true);
StopAllCoroutines();
m_CachedCanvasGroup.alpha = 1f;
if (m_Owner != owner || m_OwnerId != owner.Id)
_cachedCanvasGroup.alpha = 1f;
if (_owner != owner || m_OwnerId != owner.Id)
{
m_HPBar.value = fromHPRatio;
m_Owner = owner;
_hPBar.value = fromHPRatio;
_owner = owner;
m_OwnerId = owner.Id;
}
@@ -65,21 +52,22 @@ namespace StarForce
public bool Refresh()
{
if (m_CachedCanvasGroup.alpha <= 0f)
if (_cachedCanvasGroup.alpha <= 0f)
{
return false;
}
if (m_Owner != null && Owner.Available && Owner.Id == m_OwnerId)
if (_owner != null && Owner.Available && Owner.Id == m_OwnerId)
{
Vector3 worldPosition = m_Owner.CachedTransform.position + Vector3.forward;
Vector3 worldPosition = _owner.CachedTransform.position + Vector3.forward;
Vector3 screenPosition = GameEntry.Scene.MainCamera.WorldToScreenPoint(worldPosition);
Vector2 position;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)m_ParentCanvas.transform, screenPosition,
m_ParentCanvas.worldCamera, out position))
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)_parentCanvas.transform,
screenPosition,
_parentCanvas.worldCamera, out position))
{
m_CachedTransform.localPosition = position;
_cachedTransform.localPosition = position;
}
}
@@ -89,23 +77,23 @@ namespace StarForce
public void Reset()
{
StopAllCoroutines();
m_CachedCanvasGroup.alpha = 1f;
m_HPBar.value = 1f;
m_Owner = null;
_cachedCanvasGroup.alpha = 1f;
_hPBar.value = 1f;
_owner = null;
gameObject.SetActive(false);
}
private void Awake()
{
m_CachedTransform = GetComponent<RectTransform>();
if (m_CachedTransform == null)
_cachedTransform = GetComponent<RectTransform>();
if (_cachedTransform == null)
{
Log.Error("RectTransform is invalid.");
return;
}
m_CachedCanvasGroup = GetComponent<CanvasGroup>();
if (m_CachedCanvasGroup == null)
_cachedCanvasGroup = GetComponent<CanvasGroup>();
if (_cachedCanvasGroup == null)
{
Log.Error("CanvasGroup is invalid.");
return;
@@ -114,9 +102,9 @@ namespace StarForce
private IEnumerator HPBarCo(float value, float animationDuration, float keepDuration, float fadeOutDuration)
{
yield return m_HPBar.SmoothValue(value, animationDuration);
yield return _hPBar.SmoothValue(value, animationDuration);
yield return new WaitForSeconds(keepDuration);
yield return m_CachedCanvasGroup.FadeToAlpha(0f, fadeOutDuration);
yield return _cachedCanvasGroup.FadeToAlpha(0f, fadeOutDuration);
}
}
}