S5 finish
This commit is contained in:
@@ -8,7 +8,7 @@ namespace GeometryTD.UI
|
||||
public string TypeText;
|
||||
public string Description;
|
||||
public int Price;
|
||||
public Vector3 TargetPos;
|
||||
public Vector2 ScreenPosition;
|
||||
public TagItemContext[] Tags;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace GeometryTD.UI
|
||||
TypeText = rawData.TypeText,
|
||||
Description = BuildDescription(rawData),
|
||||
Price = rawData.Price,
|
||||
TargetPos = rawData.TargetPos,
|
||||
ScreenPosition = rawData.ScreenPosition,
|
||||
Tags = BuildTags(rawData)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace GeometryTD.UI
|
||||
public string TypeText;
|
||||
public string Description;
|
||||
public int Price;
|
||||
public Vector3 TargetPos;
|
||||
public Vector2 ScreenPosition;
|
||||
public TagType[] Tags;
|
||||
public TagRuntimeData[] TagRuntimes;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace GeometryTD.UI
|
||||
|
||||
[SerializeField] private TMP_Text _itemTypeText;
|
||||
|
||||
[SerializeField] private RectTransform _descScrollView;
|
||||
|
||||
[SerializeField] private TMP_Text _itemDescription;
|
||||
|
||||
[SerializeField] private TMP_Text _itemPrice;
|
||||
@@ -30,6 +32,8 @@ namespace GeometryTD.UI
|
||||
|
||||
[SerializeField] private float _fixedWidth = 300f;
|
||||
|
||||
[SerializeField] private float _maxDescriptionViewportHeight = 0f;
|
||||
|
||||
[SerializeField] private float _screenEdgePadding = 0f;
|
||||
|
||||
[SerializeField] private float _sideGap = 16f;
|
||||
@@ -45,7 +49,7 @@ namespace GeometryTD.UI
|
||||
private readonly List<GameObject> _runtimeTagItems = new List<GameObject>();
|
||||
|
||||
private ItemDescFormContext _context;
|
||||
private Vector3 _targetPos;
|
||||
private Vector2 _targetPos;
|
||||
private bool _isOpened;
|
||||
|
||||
public void RefreshUI(ItemDescFormContext context)
|
||||
@@ -58,7 +62,7 @@ namespace GeometryTD.UI
|
||||
|
||||
_context = context;
|
||||
|
||||
_targetPos = ConvertWorldToAnchored(_context.TargetPos);
|
||||
_targetPos = ConvertScreenToAnchored(_context.ScreenPosition);
|
||||
|
||||
if (_content != null)
|
||||
{
|
||||
@@ -146,16 +150,62 @@ namespace GeometryTD.UI
|
||||
}
|
||||
|
||||
_itemDescription.ForceMeshUpdate();
|
||||
var descriptionSize = _itemDescription.rectTransform.sizeDelta;
|
||||
descriptionSize.y = _itemDescription.preferredHeight;
|
||||
_itemDescription.rectTransform.sizeDelta = descriptionSize;
|
||||
float descriptionHeight = Mathf.Max(0f, _itemDescription.preferredHeight);
|
||||
float targetHeight = _fixedTopHeight + descriptionHeight + _fixedBottomHeight;
|
||||
SetRectHeight(_itemDescription.rectTransform, descriptionHeight);
|
||||
|
||||
RectTransform scrollContent = _itemDescription.rectTransform.parent as RectTransform;
|
||||
if (scrollContent != null)
|
||||
{
|
||||
SetRectHeight(scrollContent, descriptionHeight);
|
||||
}
|
||||
|
||||
float viewportHeight = descriptionHeight;
|
||||
if (_descScrollView != null)
|
||||
{
|
||||
viewportHeight = Mathf.Min(descriptionHeight, ResolveMaxDescriptionViewportHeight());
|
||||
SetRectHeight(_descScrollView, viewportHeight);
|
||||
|
||||
if (_descScrollView.TryGetComponent(out ScrollRect scrollRect))
|
||||
{
|
||||
scrollRect.verticalNormalizedPosition = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
float targetHeight = _fixedTopHeight + viewportHeight + _fixedBottomHeight;
|
||||
|
||||
Vector2 size = new Vector2(_fixedWidth, targetHeight);
|
||||
_content.sizeDelta = size;
|
||||
}
|
||||
|
||||
private float ResolveMaxDescriptionViewportHeight()
|
||||
{
|
||||
float maxViewportHeight = _maxDescriptionViewportHeight;
|
||||
RectTransform parent = _content.parent as RectTransform;
|
||||
if (parent != null)
|
||||
{
|
||||
float availableHeight = parent.rect.height - _fixedTopHeight - _fixedBottomHeight
|
||||
- _screenEdgePadding * 2f;
|
||||
availableHeight = Mathf.Max(0f, availableHeight);
|
||||
maxViewportHeight = maxViewportHeight > 0f
|
||||
? Mathf.Min(maxViewportHeight, availableHeight)
|
||||
: availableHeight;
|
||||
}
|
||||
|
||||
return maxViewportHeight > 0f ? maxViewportHeight : float.MaxValue;
|
||||
}
|
||||
|
||||
private static void SetRectHeight(RectTransform rectTransform, float height)
|
||||
{
|
||||
if (rectTransform == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 size = rectTransform.sizeDelta;
|
||||
size.y = height;
|
||||
rectTransform.sizeDelta = size;
|
||||
}
|
||||
|
||||
private void ApplySideAnchoredTargetPos()
|
||||
{
|
||||
if (_content == null)
|
||||
@@ -207,20 +257,20 @@ namespace GeometryTD.UI
|
||||
finalX = minX <= maxX ? Mathf.Clamp(leftCandidateX, minX, maxX) : 0f;
|
||||
}
|
||||
|
||||
_content.anchoredPosition3D = new Vector3(finalX, clampedY, _targetPos.z);
|
||||
_content.anchoredPosition = new Vector2(finalX, clampedY);
|
||||
}
|
||||
|
||||
private Vector3 ConvertWorldToAnchored(Vector3 worldPos)
|
||||
private Vector2 ConvertScreenToAnchored(Vector2 screenPosition)
|
||||
{
|
||||
if (_content == null)
|
||||
{
|
||||
return worldPos;
|
||||
return screenPosition;
|
||||
}
|
||||
|
||||
RectTransform parent = _content.parent as RectTransform;
|
||||
if (parent == null)
|
||||
{
|
||||
return worldPos;
|
||||
return screenPosition;
|
||||
}
|
||||
|
||||
Canvas canvas = _content.GetComponentInParent<Canvas>();
|
||||
@@ -231,15 +281,13 @@ namespace GeometryTD.UI
|
||||
uiCamera = rootCanvas.worldCamera != null ? rootCanvas.worldCamera : Camera.main;
|
||||
}
|
||||
|
||||
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(uiCamera, worldPos);
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPoint, uiCamera,
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPosition, uiCamera,
|
||||
out Vector2 localPoint))
|
||||
{
|
||||
return worldPos;
|
||||
return screenPosition;
|
||||
}
|
||||
|
||||
float z = _content.anchoredPosition3D.z;
|
||||
return new Vector3(localPoint.x, localPoint.y, z);
|
||||
return localPoint;
|
||||
}
|
||||
|
||||
private static bool IsInsideBounds(float value, float min, float max)
|
||||
|
||||
Reference in New Issue
Block a user