- S4-03 | 先固化 Tag 系统设计与首发范围

- S4-04 | 实现组件实例 Tag 的统一生成入口
- S4-05 | 实现组塔后的 Tag 汇总与展示入口
This commit is contained in:
SepComet
2026-03-09 21:06:43 +08:00
parent 73b7adedb8
commit 34ef001ef3
31 changed files with 1280 additions and 178 deletions
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using GeometryTD.Definition;
using UnityEngine;
namespace GeometryTD.UI
@@ -11,6 +9,6 @@ namespace GeometryTD.UI
public string Description;
public int Price;
public Vector3 TargetPos;
public List<TagType> Tags;
public TagItemContext[] Tags;
}
}
}
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using GameFramework.Event;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
@@ -35,18 +35,33 @@ namespace GeometryTD.UI
Description = rawData.Description,
Price = rawData.Price,
TargetPos = rawData.TargetPos,
Tags = BuildTags(rawData.Tags)
Tags = BuildTags(rawData)
};
}
private static List<TagType> BuildTags(TagType[] tags)
private static TagItemContext[] BuildTags(ItemDescFormRawData rawData)
{
if (tags == null || tags.Length <= 0)
string[] tagTexts = rawData?.TagTexts;
if ((tagTexts == null || tagTexts.Length <= 0) && rawData?.Tags != null)
{
return new List<TagType>();
tagTexts = TagDisplayUtility.BuildTagTexts(rawData.Tags);
}
return new List<TagType>(tags);
if (tagTexts == null || tagTexts.Length <= 0)
{
return System.Array.Empty<TagItemContext>();
}
TagItemContext[] contexts = new TagItemContext[tagTexts.Length];
for (int i = 0; i < tagTexts.Length; i++)
{
contexts[i] = new TagItemContext
{
TagName = tagTexts[i] ?? string.Empty
};
}
return contexts;
}
public int? OpenUI(ItemDescFormRawData rawData)
@@ -179,44 +179,24 @@ namespace GeometryTD.UI
private static TagItemContext[] BuildTagContexts(TagType[] tags)
{
if (tags == null || tags.Length <= 0)
string[] tagTexts = TagDisplayUtility.BuildTagTexts(tags);
if (tagTexts == null || tagTexts.Length <= 0)
{
return System.Array.Empty<TagItemContext>();
}
TagItemContext[] contexts = new TagItemContext[tags.Length];
for (int i = 0; i < tags.Length; i++)
TagItemContext[] contexts = new TagItemContext[tagTexts.Length];
for (int i = 0; i < tagTexts.Length; i++)
{
TagType tagType = tags[i];
contexts[i] = new TagItemContext
{
TagName = ResolveTagName(tagType)
TagName = tagTexts[i]
};
}
return contexts;
}
private static string ResolveTagName(TagType tagType)
{
if (tagType == TagType.None)
{
return string.Empty;
}
var tagTable = GameEntry.DataTable.GetDataTable<DRTag>();
if (tagTable != null)
{
DRTag tagRow = tagTable.GetDataRow((int)tagType);
if (tagRow != null && !string.IsNullOrWhiteSpace(tagRow.Name))
{
return tagRow.Name;
}
}
return tagType.ToString();
}
private void OnRewardSelected(object sender, GameEventArgs e)
{
if (!IsEventFromCurrentForm(sender) || !(e is RewardSelectItemSelectedEventArgs args))
@@ -11,5 +11,6 @@ namespace GeometryTD.UI
public int Price;
public Vector3 TargetPos;
public TagType[] Tags;
public string[] TagTexts;
}
}
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -249,11 +247,11 @@ namespace GeometryTD.UI
return value >= min && value <= max;
}
private void RefreshTags(List<TagType> tags)
private void RefreshTags(TagItemContext[] tags)
{
ClearTags();
if (_tagAreaParent == null || _tagItemPrefab == null || tags == null || tags.Count <= 0)
if (_tagAreaParent == null || _tagItemPrefab == null || tags == null || tags.Length <= 0)
{
return;
}
@@ -263,10 +261,10 @@ namespace GeometryTD.UI
_tagItemPrefab.SetActive(false);
}
for (int i = 0; i < tags.Count; i++)
for (int i = 0; i < tags.Length; i++)
{
string tagName = ResolveTagName(tags[i]);
if (string.IsNullOrWhiteSpace(tagName))
TagItemContext tagContext = tags[i];
if (tagContext == null || string.IsNullOrWhiteSpace(tagContext.TagName))
{
continue;
}
@@ -276,17 +274,14 @@ namespace GeometryTD.UI
if (tagGo.TryGetComponent(out TagItem tagItem))
{
tagItem.OnInit(new TagItemContext
{
TagName = tagName
});
tagItem.OnInit(tagContext);
}
else
{
TMP_Text tagText = tagGo.GetComponentInChildren<TMP_Text>(true);
if (tagText != null)
{
tagText.text = tagName;
tagText.text = tagContext.TagName;
}
}
@@ -308,26 +303,6 @@ namespace GeometryTD.UI
_runtimeTagItems.Clear();
}
private static string ResolveTagName(TagType tagType)
{
if (tagType == TagType.None)
{
return string.Empty;
}
var tagTable = GameEntry.DataTable.GetDataTable<DRTag>();
if (tagTable != null)
{
DRTag tagRow = tagTable.GetDataRow((int)tagType);
if (tagRow != null && !string.IsNullOrWhiteSpace(tagRow.Name))
{
return tagRow.Name;
}
}
return tagType.ToString();
}
private void CloseSelf()
{
GameEntry.UI.CloseUIForm(this);