拆分 UIController 组装 Context 职责 + 描述文本滚动展示
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using GeometryTD.CustomEvent;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
@@ -15,6 +16,12 @@ namespace GeometryTD.UI
|
||||
|
||||
[SerializeField] private TMP_Text _descriptionText;
|
||||
|
||||
[SerializeField] private RectTransform _descriptionScrollView;
|
||||
|
||||
[SerializeField] private RectTransform _descriptionContent;
|
||||
|
||||
[SerializeField] private float _maxDescriptionViewportHeight = 0f;
|
||||
|
||||
[SerializeField] private Transform _tagItemParent;
|
||||
|
||||
[SerializeField] private TagItem _tagItemTemplate;
|
||||
@@ -63,6 +70,8 @@ namespace GeometryTD.UI
|
||||
_descriptionText.text = context.Description ?? string.Empty;
|
||||
}
|
||||
|
||||
ResizeDescriptionArea();
|
||||
|
||||
RefreshTags(context.Tags);
|
||||
}
|
||||
|
||||
@@ -90,6 +99,8 @@ namespace GeometryTD.UI
|
||||
_descriptionText.text = string.Empty;
|
||||
}
|
||||
|
||||
ResetDescriptionScroll();
|
||||
|
||||
ClearTags();
|
||||
}
|
||||
|
||||
@@ -133,6 +144,54 @@ namespace GeometryTD.UI
|
||||
}
|
||||
}
|
||||
|
||||
private void ResizeDescriptionArea()
|
||||
{
|
||||
if (_descriptionText == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_descriptionText.ForceMeshUpdate();
|
||||
float descriptionHeight = Mathf.Max(0f, _descriptionText.preferredHeight);
|
||||
SetRectHeight(_descriptionText.rectTransform, descriptionHeight);
|
||||
|
||||
if (_descriptionContent != null)
|
||||
{
|
||||
SetRectHeight(_descriptionContent, descriptionHeight);
|
||||
}
|
||||
|
||||
if (_descriptionScrollView != null)
|
||||
{
|
||||
float viewportHeight = _maxDescriptionViewportHeight > 0f
|
||||
? Mathf.Min(descriptionHeight, _maxDescriptionViewportHeight)
|
||||
: descriptionHeight;
|
||||
SetRectHeight(_descriptionScrollView, viewportHeight);
|
||||
}
|
||||
|
||||
ResetDescriptionScroll();
|
||||
}
|
||||
|
||||
private void ResetDescriptionScroll()
|
||||
{
|
||||
if (_descriptionScrollView != null &&
|
||||
_descriptionScrollView.TryGetComponent(out ScrollRect scrollRect))
|
||||
{
|
||||
scrollRect.verticalNormalizedPosition = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetRectHeight(RectTransform rectTransform, float height)
|
||||
{
|
||||
if (rectTransform == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 size = rectTransform.sizeDelta;
|
||||
size.y = height;
|
||||
rectTransform.sizeDelta = size;
|
||||
}
|
||||
|
||||
private TagItem ResolveTagTemplate()
|
||||
{
|
||||
if (_tagItemTemplate != null)
|
||||
|
||||
Reference in New Issue
Block a user