v10 全量评审:修复 TD-06 至 TD-12(InputReader 移除资产扫描回退 / EmergencySave 解除 LocalFileStorage 直接依赖 / AccessibilityManager 注册 IAccessibilityService / HUDController HP/SpringIcon SetActive 复用 / MovingPlatform 缓存 WaitForSeconds / RewardSO IRewardTarget 解耦 Quest←Player 依赖 / CrashReporter 频率限制崩溃日志)
This commit is contained in:
@@ -18,14 +18,20 @@ namespace BaseGames.UI
|
||||
[SerializeField] private float _floatDistance = 1.5f;
|
||||
[SerializeField] private float _duration = 0.8f;
|
||||
|
||||
private UnityEngine.Camera _cam;
|
||||
/// <summary>
|
||||
/// 父级 Canvas(用于 RectTransformUtility 坐标转换)。
|
||||
/// 适配所有 Canvas 渲染模式(Overlay / Camera / World Space),
|
||||
/// Screen Space - Overlay 时可传 null(会自动 fallback 到 null camera)。
|
||||
/// </summary>
|
||||
[SerializeField] private Canvas _parentCanvas;
|
||||
|
||||
private RectTransform _rectTransform;
|
||||
private Coroutine _animCoroutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rectTransform = (RectTransform)transform;
|
||||
_cam = UnityEngine.Camera.main;
|
||||
// 不在 Awake 缓存 Camera.main,避免 Boss 过场切换主摄像机后引用过期
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,16 +45,36 @@ namespace BaseGames.UI
|
||||
_text.text = damage.ToString();
|
||||
_text.color = GetColorForType(type);
|
||||
|
||||
// 将世界坐标转为屏幕坐标
|
||||
if (_cam != null)
|
||||
{
|
||||
Vector2 screenPos = _cam.WorldToScreenPoint(worldPosition);
|
||||
_rectTransform.anchoredPosition = screenPos;
|
||||
}
|
||||
|
||||
SetAnchoredPosition(worldPosition);
|
||||
_animCoroutine = StartCoroutine(FloatAndFade(worldPosition));
|
||||
}
|
||||
|
||||
private void SetAnchoredPosition(Vector2 worldPosition)
|
||||
{
|
||||
var cam = (_parentCanvas != null && _parentCanvas.renderMode == RenderMode.ScreenSpaceCamera)
|
||||
? _parentCanvas.worldCamera
|
||||
: UnityEngine.Camera.main;
|
||||
|
||||
var screenPoint = UnityEngine.Camera.main != null
|
||||
? (Vector2)UnityEngine.Camera.main.WorldToScreenPoint(worldPosition)
|
||||
: Vector2.zero;
|
||||
|
||||
var canvasRect = _parentCanvas != null
|
||||
? (RectTransform)_parentCanvas.transform
|
||||
: null;
|
||||
|
||||
if (canvasRect != null)
|
||||
{
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
canvasRect, screenPoint, cam, out var localPoint);
|
||||
_rectTransform.anchoredPosition = localPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
_rectTransform.anchoredPosition = screenPoint;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FloatAndFade(Vector2 startWorld)
|
||||
{
|
||||
float elapsed = 0f;
|
||||
@@ -59,10 +85,7 @@ namespace BaseGames.UI
|
||||
{
|
||||
float t = elapsed / _duration;
|
||||
|
||||
// 向上飘动(屏幕坐标)
|
||||
Vector2 currentWorld = startWorld + new Vector2(0, _floatDistance * t);
|
||||
if (_cam != null)
|
||||
_rectTransform.anchoredPosition = (Vector2)_cam.WorldToScreenPoint(currentWorld);
|
||||
SetAnchoredPosition(startWorld + new Vector2(0, _floatDistance * t));
|
||||
|
||||
// alpha 淡出(后半段开始)
|
||||
_text.color = new Color(color.r, color.g, color.b,
|
||||
|
||||
Reference in New Issue
Block a user