P0-02 补齐数据表:组件、敌人、波次、节点、事件、商店商品

- 组件:
    - 底座:Assets\GameMain\DataTables\BaseComp.txt
    - 轴承:Assets\GameMain\DataTables\BearingComp.txt
    - 枪口:Assets\GameMain\DataTables\MuzzleComp.txt
- 敌人:Assets\GameMain\DataTables\Enemy.txt
- 波次:
    - 关卡:Assets\GameMain\DataTables\Level.txt
    - 关卡阶段(波次):Assets\GameMain\DataTables\LevelPhase.txt
    - 波次条目(波次出怪规则):Assets\GameMain\DataTables\LevelSpawnEntry.txt
- 事件:Assets\GameMain\DataTables\Event.txt
- 商店:Assets\GameMain\DataTables\ShopPrice.txt
This commit is contained in:
SepComet
2026-02-26 21:36:29 +08:00
parent bb0a4edfb7
commit 11e4c1c1f2
115 changed files with 3218 additions and 135 deletions
@@ -19,10 +19,16 @@ public partial class GameEntry : MonoBehaviour
public static EnemyManagerComponent EnemyManager { get; private set; }
public static EventNodeComponent EventNode { get; private set; }
public static CombatNodeComponent CombatNode { get; private set; }
private static void InitCustomComponents()
{
BuiltinData = UnityGameFramework.Runtime.GameEntry.GetComponent<BuiltinDataComponent>();
HPBar = UnityGameFramework.Runtime.GameEntry.GetComponent<HPBarComponent>();
EnemyManager = UnityGameFramework.Runtime.GameEntry.GetComponent<EnemyManagerComponent>();
EventNode = UnityGameFramework.Runtime.GameEntry.GetComponent<EventNodeComponent>();
CombatNode = UnityGameFramework.Runtime.GameEntry.GetComponent<CombatNodeComponent>();
}
}
}
@@ -0,0 +1,145 @@
using System.Collections.Generic;
using GameFramework.DataTable;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace GeometryTD.CustomComponent
{
/// <summary>
/// 战斗节点组件
/// </summary>
public class CombatNodeComponent : GameFrameworkComponent
{
// Level.Id => Level
private readonly Dictionary<int, DRLevel> _levelsById = new();
// LevelId => LevelPhases
private readonly Dictionary<int, List<DRLevelPhase>> _phasesByLevelId = new();
// LevelPhase.Id => LevelSpawnEntries
private readonly Dictionary<int, List<DRLevelSpawnEntry>> _spawnEntriesByPhaseId = new();
private readonly List<int> _levelIdBuffer = new();
public LevelThemeType CurrentThemeType { get; private set; }
public DRLevel CurrentLevel { get; private set; }
public void OnInit(LevelThemeType themeType)
{
CurrentThemeType = themeType;
CurrentLevel = null;
_levelsById.Clear();
_phasesByLevelId.Clear();
_spawnEntriesByPhaseId.Clear();
_levelIdBuffer.Clear();
IDataTable<DRLevel> dtLevel = GameEntry.DataTable.GetDataTable<DRLevel>();
IDataTable<DRLevelPhase> dtLevelPhase = GameEntry.DataTable.GetDataTable<DRLevelPhase>();
IDataTable<DRLevelSpawnEntry> dtSpawnEntry = GameEntry.DataTable.GetDataTable<DRLevelSpawnEntry>();
if (dtLevel == null || dtLevelPhase == null || dtSpawnEntry == null)
{
Log.Warning("CombatNodeComponent init failed. Missing data table(s).");
return;
}
DRLevel[] levels = dtLevel.GetAllDataRows();
foreach (var level in levels)
{
if (level.LevelThemeType != themeType)
{
continue;
}
_levelsById[level.Id] = level;
_phasesByLevelId[level.Id] = new List<DRLevelPhase>();
_levelIdBuffer.Add(level.Id);
}
DRLevelPhase[] levelPhases = dtLevelPhase.GetAllDataRows();
foreach (var phase in levelPhases)
{
int levelId = phase.Id / 1000;
if (!_levelsById.ContainsKey(levelId))
{
continue;
}
if (!_phasesByLevelId.TryGetValue(levelId, out List<DRLevelPhase> phases))
{
phases = new List<DRLevelPhase>();
_phasesByLevelId[levelId] = phases;
}
phases.Add(phase);
_spawnEntriesByPhaseId[phase.Id] = new List<DRLevelSpawnEntry>();
}
DRLevelSpawnEntry[] spawnEntries = dtSpawnEntry.GetAllDataRows();
for (int i = 0; i < spawnEntries.Length; i++)
{
DRLevelSpawnEntry spawnEntry = spawnEntries[i];
int phaseId = spawnEntry.Id / 1000;
int levelId = phaseId / 1000;
if (!_levelsById.ContainsKey(levelId))
{
continue;
}
if (!_spawnEntriesByPhaseId.TryGetValue(phaseId, out List<DRLevelSpawnEntry> entries))
{
entries = new List<DRLevelSpawnEntry>();
_spawnEntriesByPhaseId[phaseId] = entries;
}
entries.Add(spawnEntry);
}
Log.Info(
"CombatNodeComponent initialized. Theme={0}, Levels={1}, Phases={2}, Entries={3}",
themeType,
_levelsById.Count,
CountPhases(),
CountEntries());
}
public void StartCombat()
{
if (_levelIdBuffer.Count <= 0)
{
Log.Warning("CombatNodeComponent has no level cache. Call OnInit(levelThemeType) first.");
return;
}
int randomIndex = Random.Range(0, _levelIdBuffer.Count);
int randomLevelId = _levelIdBuffer[randomIndex];
CurrentLevel = _levelsById[randomLevelId];
// TODO: 在这里接入真实战斗节点玩法启动流程(场景进入、敌人生成、结算等)。
Log.Info("StartCombat selected level '{0}' (Theme={1}).", CurrentLevel.Id, CurrentThemeType);
}
private int CountPhases()
{
int count = 0;
foreach (List<DRLevelPhase> phases in _phasesByLevelId.Values)
{
count += phases.Count;
}
return count;
}
private int CountEntries()
{
int count = 0;
foreach (var list in _spawnEntriesByPhaseId.Values)
{
count += list.Count;
}
return count;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5e646500b9304d438746f2351c71a0f4
timeCreated: 1772103300
@@ -0,0 +1,172 @@
using System.Collections.Generic;
using GameFramework.DataTable;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using Newtonsoft.Json.Linq;
using GeometryTD.UI;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace GeometryTD.CustomComponent
{
public class EventNodeComponent : GameFrameworkComponent
{
private readonly List<EventItem> _eventItems = new List<EventItem>();
private EventFormUseCase _eventFormUseCase;
private EventFormController _eventFormController;
private bool _initialized;
public void OnInit()
{
_eventItems.Clear();
IDataTable<DREvent> dtEvent = GameEntry.DataTable.GetDataTable<DREvent>();
if (dtEvent == null)
{
Log.Warning("Event data table is not loaded.");
_initialized = true;
return;
}
DREvent[] rows = dtEvent.GetAllDataRows();
foreach (var drEvent in rows)
{
EventOption[] options = ParseOptions(drEvent.OptionsRaw);
_eventItems.Add(new EventItem(drEvent.Id, drEvent.Title, drEvent.Description, options));
}
if (_eventFormUseCase == null)
{
_eventFormUseCase = new EventFormUseCase();
}
if (_eventFormController == null)
{
_eventFormController = new EventFormController();
_eventFormController.BindUseCase(_eventFormUseCase);
}
_initialized = true;
Log.Info("EventNodeComponent initialized with {0} events.", _eventItems.Count);
}
public void StartEvent()
{
if (!_initialized)
{
OnInit();
}
if (_eventItems.Count <= 0)
{
Log.Warning("EventNodeComponent has no event data.");
return;
}
int index = Random.Range(0, _eventItems.Count);
EventItem randomEvent = _eventItems[index];
if (_eventFormUseCase == null || _eventFormController == null)
{
Log.Warning("EventNodeComponent StartEvent failed. Event form is not initialized.");
return;
}
_eventFormUseCase.SetCurrentEvent(randomEvent);
_eventFormController.OpenUI();
}
private static EventOption[] ParseOptions(string optionsRaw)
{
if (string.IsNullOrWhiteSpace(optionsRaw))
{
return System.Array.Empty<EventOption>();
}
try
{
JArray array = JArray.Parse(optionsRaw);
List<EventOption> options = new List<EventOption>(array.Count);
for (int i = 0; i < array.Count; i++)
{
if (!(array[i] is JObject optionObj))
{
continue;
}
string optionText = optionObj.Value<string>("optionText") ?? string.Empty;
float probability = optionObj.Value<float?>("probability") ?? 1f;
EventRequirementBase[] requirements = ParseRequirements(optionObj["requirements"] as JArray);
EventEffectBase[] costEffects = ParseEffects(optionObj["costEffects"] as JArray, probability);
EventEffectBase[] rewardEffects = ParseEffects(optionObj["rewardEffects"] as JArray, probability);
options.Add(new EventOption(optionText, requirements, costEffects, rewardEffects, probability));
}
return options.ToArray();
}
catch (System.Exception e)
{
Log.Warning("Failed to parse event options json. {0}", e.Message);
return System.Array.Empty<EventOption>();
}
}
private static EventRequirementBase[] ParseRequirements(JArray requirementsArray)
{
if (requirementsArray == null || requirementsArray.Count == 0)
{
return System.Array.Empty<EventRequirementBase>();
}
List<EventRequirementBase> requirements = new List<EventRequirementBase>(requirementsArray.Count);
for (int i = 0; i < requirementsArray.Count; i++)
{
if (!(requirementsArray[i] is JObject reqObj))
{
continue;
}
string type = reqObj.Value<string>("type");
JObject param = reqObj["param"] as JObject;
EventRequirementBase requirement = EventRequirementFactory.Create(type, param);
if (requirement != null)
{
requirements.Add(requirement);
}
}
return requirements.ToArray();
}
private static EventEffectBase[] ParseEffects(JArray effectsArray, float probability)
{
if (effectsArray == null || effectsArray.Count == 0)
{
return System.Array.Empty<EventEffectBase>();
}
List<EventEffectBase> effects = new List<EventEffectBase>(effectsArray.Count);
for (int i = 0; i < effectsArray.Count; i++)
{
if (!(effectsArray[i] is JObject effectObj))
{
continue;
}
string type = effectObj.Value<string>("type");
JObject param = effectObj["param"] as JObject;
EventEffectBase effect = EventEffectFactory.Create(type, param, probability);
if (effect != null)
{
effects.Add(effect);
}
}
return effects.ToArray();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0a0c1c547ca24c95819f5f62f0bd3ea3
timeCreated: 1772102402
@@ -0,0 +1,63 @@
using UnityGameFramework.Runtime;
namespace GeometryTD.DataTable
{
/// <summary>
/// 敌人配置表
/// </summary>
public class DREnemy : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// 获取敌人编号
/// </summary>
public override int Id => m_Id;
/// <summary>
/// 获取敌人实体编号
/// </summary>
public int EntityId { get; private set; }
/// <summary>
/// 获取敌人基础血量
/// </summary>
public int BaseHp { get; private set; }
/// <summary>
/// 获取敌人基础基地伤害
/// </summary>
public int BaseDamage { get; private set; }
/// <summary>
/// 获取敌人移动速度
/// </summary>
public float Speed { get; private set; }
/// <summary>
/// 获取敌人掉落金币
/// </summary>
public int DropCoin { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
EntityId = int.Parse(columnStrings[index++]);
BaseHp = int.Parse(columnStrings[index++]);
BaseDamage = int.Parse(columnStrings[index++]);
Speed = float.Parse(columnStrings[index++]);
DropCoin = int.Parse(columnStrings[index++]);
return true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0f9832b810954c4eb0f45ad735bb5a58
timeCreated: 1772101800
@@ -0,0 +1,52 @@
using UnityGameFramework.Runtime;
namespace GeometryTD.DataTable
{
/// <summary>
/// 事件配置表
/// </summary>
public class DREvent : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// 获取事件编号
/// </summary>
public override int Id => m_Id;
/// <summary>
/// 获取事件题目
/// </summary>
public string Title { get; private set; }
/// <summary>
/// 获取事件描述
/// </summary>
public string Description { get; private set; }
/// <summary>
/// 获取事件选项
/// </summary>
/// <remarks>原始字符串(如 JSON 文本),不在此处做解析。</remarks>
public string OptionsRaw { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
Title = columnStrings[index++];
Description = columnStrings[index++];
OptionsRaw = columnStrings[index++];
return true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 57e29dfa7f1044a1acfbf3abde81859f
timeCreated: 1772097514
@@ -0,0 +1,72 @@
using System;
using GeometryTD.Definition;
using GeometryTD.CustomUtility;
using UnityGameFramework.Runtime;
namespace GeometryTD.DataTable
{
/// <summary>
/// 关卡表
/// </summary>
public class DRLevel : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// 获取关卡编号
/// </summary>
public override int Id => m_Id;
/// <summary>
/// 获取关卡所属主题类型
/// </summary>
public LevelThemeType LevelThemeType { get; private set; }
/// <summary>
/// 获取关卡初始基地生命
/// </summary>
public int BaseHp { get; private set; }
/// <summary>
/// 获取关卡初始硬币数量
/// </summary>
public int StartCoin { get; private set; }
/// <summary>
/// 获取关卡胜利条件
/// </summary>
public LevelVictoryType LevelVictoryType { get; private set; }
/// <summary>
/// 获取关卡胜利奖励金币
/// </summary>
public int RewardGold { get; private set; }
/// <summary>
/// 获取关卡胜利条件参数
/// </summary>
public string VictoryParams { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
LevelThemeType = EnumUtility<LevelThemeType>.Get(columnStrings[index++]);
BaseHp = int.Parse(columnStrings[index++]);
StartCoin = int.Parse(columnStrings[index++]);
LevelVictoryType = EnumUtility<LevelVictoryType>.Get(columnStrings[index++]);
VictoryParams = columnStrings[index++];
RewardGold = int.Parse(columnStrings[index++]);
return true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e0eb47d184fe4204b38dc7c9e86da609
timeCreated: 1772089145
@@ -0,0 +1,64 @@
using System;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
namespace GeometryTD.DataTable
{
/// <summary>
/// 关卡阶段表
/// </summary>
public class DRLevelPhase : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// 获取关卡阶段编号
/// </summary>
public override int Id => m_Id;
/// <summary>
/// 获取阶段持续时间(秒)
/// </summary>
public int DurationSeconds { get; private set; }
/// <summary>
/// 获取阶段结束条件类型
/// </summary>
public PhaseEndType EndType { get; private set; }
/// <summary>
/// 获取阶段结束参数
/// </summary>
public string EndParam { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
DurationSeconds = int.Parse(columnStrings[index++]);
EndType = ParsePhaseEndType(columnStrings[index++]);
EndParam = columnStrings[index++];
return true;
}
private PhaseEndType ParsePhaseEndType(string raw)
{
if (string.IsNullOrWhiteSpace(raw))
{
return PhaseEndType.None;
}
return EnumUtility<PhaseEndType>.Get(raw);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f1fd79e88eca4bfbb38f5bcb8091e2dd
timeCreated: 1772090000
@@ -0,0 +1,94 @@
using System;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
namespace GeometryTD.DataTable
{
/// <summary>
/// 关卡阶段出怪条目表
/// </summary>
public class DRLevelSpawnEntry : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// 获取阶段条目编号
/// </summary>
public override int Id => m_Id;
/// <summary>
/// 获取敌人出生口编号
/// </summary>
public int SpawnPointId { get; private set; }
/// <summary>
/// 获取相对开始时间(秒)
/// </summary>
public int StartTime { get; private set; }
/// <summary>
/// 获取出怪条目类型
/// </summary>
public EntryType EntryType { get; private set; }
/// <summary>
/// 获取敌人编号
/// </summary>
public int EnemyId { get; private set; }
/// <summary>
/// 获取单次出怪数量
/// </summary>
public int Count { get; private set; }
/// <summary>
/// 获取出怪间隔(秒)
/// </summary>
public float Interval { get; private set; }
/// <summary>
/// 获取持续时间(秒)
/// </summary>
public int Duration { get; private set; }
/// <summary>
/// 获取单怪出生间隔(秒)
/// </summary>
public float Gap { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
SpawnPointId = int.Parse(columnStrings[index++]);
StartTime = int.Parse(columnStrings[index++]);
EntryType = ParseEntryType(columnStrings[index++]);
EnemyId = int.Parse(columnStrings[index++]);
Count = int.Parse(columnStrings[index++]);
Interval = float.Parse(columnStrings[index++]);
Duration = int.Parse(columnStrings[index++]);
Gap = float.Parse(columnStrings[index++]);
return true;
}
private EntryType ParseEntryType(string raw)
{
if (string.IsNullOrWhiteSpace(raw))
{
return EntryType.None;
}
return EnumUtility<EntryType>.Get(raw);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b06804b242d247bd8a937cdce930cee1
timeCreated: 1772090001
@@ -0,0 +1,38 @@
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
namespace GeometryTD.DataTable
{
public class DRShopPrice : DataRowBase
{
private int m_Id = 0;
public override int Id => m_Id;
public RarityType Rarity { get; set; }
public int MinPrice { get; set; }
public int MaxPrice { get; set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
Rarity = EnumUtility<RarityType>.Get(columnStrings[index++]);
MinPrice = int.Parse(columnStrings[index++]);
MaxPrice = int.Parse(columnStrings[index++]);
return true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7c47aaecd99446f2b8c9ec84c797005b
timeCreated: 1772105886
@@ -0,0 +1,18 @@
namespace GeometryTD.Definition
{
public class EventItem
{
public EventItem(int id, string title, string description, EventOption[] options)
{
Id = id;
Title = title;
Description = description;
Options = options ?? System.Array.Empty<EventOption>();
}
public int Id { get; private set; }
public string Title { get; private set; }
public string Description { get; private set; }
public EventOption[] Options { get; private set; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c2a6dce0183e4efdbada20c25be949c0
timeCreated: 1772097196
@@ -0,0 +1,25 @@
namespace GeometryTD.Definition
{
public class EventOption
{
public string OptionText { get; private set; }
public EventRequirementBase[] Requirements { get; private set; }
public EventEffectBase[] CostEffects { get; private set; }
public EventEffectBase[] RewardEffects { get; private set; }
public float Probability { get; private set; }
public EventOption(
string optionText,
EventRequirementBase[] requirements,
EventEffectBase[] costEffects,
EventEffectBase[] rewardEffects,
float probability = 1f)
{
OptionText = optionText;
Requirements = requirements ?? System.Array.Empty<EventRequirementBase>();
CostEffects = costEffects ?? System.Array.Empty<EventEffectBase>();
RewardEffects = rewardEffects ?? System.Array.Empty<EventEffectBase>();
Probability = probability;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bcb612057a454fcf97f41fdf5c6d9b22
timeCreated: 1772097742
@@ -3,7 +3,7 @@ namespace GeometryTD.Definition
public enum AttackPropertyType : byte
{
None = 0,
Physical = 1,
Physics = 1,
Fire = 2,
Water = 3,
Earth = 4,
@@ -0,0 +1,13 @@
namespace GeometryTD.Definition
{
/// <summary>
/// 出怪条目类型
/// </summary>
public enum EntryType : byte
{
None = 0,
Stream = 1,
Burst = 2,
Boss = 3
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 14433e1048844c5d942c885c2f50ffe0
timeCreated: 1772090003
@@ -0,0 +1,21 @@
namespace GeometryTD.Definition
{
public enum EventEffectType
{
None,
AddGold,
RemoveGold,
AddRandomComps,
RemoveRandomComps,
AddRandomCompsEndurance,
RemoveRandomCompsEndurance,
AddRandomTowersEndurance,
DamageRandomTowersEndurance,
TransformComponents,
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6f11ba35aa8f491f942964435b32cba6
timeCreated: 1772095333
@@ -0,0 +1,11 @@
namespace GeometryTD.Definition
{
public enum EventRequirementType
{
None,
GoldAtLeast,
CompCountAtLeast,
TowerCountAtLeast,
HasRelic,
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f9da1af87a4f4115b9a5da706b4e1092
timeCreated: 1772095290
@@ -0,0 +1,10 @@
namespace GeometryTD.Definition
{
public enum LevelThemeType
{
None,
Plain,
Volcano,
Mountain
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 06ec7c0ec8924c7988e521abdd97bffe
timeCreated: 1772089321
@@ -0,0 +1,10 @@
namespace GeometryTD.Definition
{
public enum LevelVictoryType
{
None,
PhasesCleared,
BossDead,
TimeElapsed
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ea9b7c078511464fa572923f66cc200e
timeCreated: 1772089447
@@ -0,0 +1,13 @@
namespace GeometryTD.Definition
{
/// <summary>
/// 关卡阶段结束类型
/// </summary>
public enum PhaseEndType : byte
{
None = 0,
TimeElapsed = 1,
EnemiesCleared = 2,
BossDead = 3
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eed7685430c24cdaac639581331393f3
timeCreated: 1772090002
@@ -26,5 +26,10 @@
/// 关于。
/// </summary>
AboutForm = 102,
/// <summary>
/// 事件节点界面。
/// </summary>
EventForm = 200,
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8a291a17879242cc8c7cec678aa5aaf1
timeCreated: 1772101365
@@ -0,0 +1,25 @@
namespace GeometryTD.Definition
{
public class AddGoldEffect : EventEffectBase
{
public override EventEffectType EffectType => EventEffectType.AddGold;
public override EventEffectParam Param => _param;
private AddGoldParam _param;
public AddGoldEffect(AddGoldParam param, float? probability = null)
{
_param = param;
Probability = probability;
}
}
public class AddGoldParam : EventEffectParam
{
public int Count;
public AddGoldParam(int count)
{
Count = count;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 75cacc997d8f414ca73f381cad303b5b
timeCreated: 1772101474
@@ -0,0 +1,28 @@
namespace GeometryTD.Definition
{
public class AddRandomCompsEffect : EventEffectBase
{
public override EventEffectType EffectType => EventEffectType.AddRandomComps;
public override EventEffectParam Param => _param;
private AddRandomCompsParam _param;
public AddRandomCompsEffect(AddRandomCompsParam param, float? probability = null)
{
_param = param;
Probability = probability;
}
}
public class AddRandomCompsParam : EventEffectParam
{
public int Count;
public RarityType Rarity;
public AddRandomCompsParam(int count, RarityType rarity)
{
Count = count;
Rarity = rarity;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 35656d42c28448268d0547c19938b2d8
timeCreated: 1772101530
@@ -0,0 +1,34 @@
namespace GeometryTD.Definition
{
public class DamageRandomTowerEnduranceEffect : EventEffectBase
{
public override EventEffectType EffectType => EventEffectType.DamageRandomTowersEndurance;
public override EventEffectParam Param => _param;
private DamageRandomTowerEnduranceParam _param;
public DamageRandomTowerEnduranceEffect(DamageRandomTowerEnduranceParam param, float? probability = null)
{
_param = param;
Probability = probability;
}
}
public class DamageRandomTowerEnduranceParam : EventEffectParam
{
/// <summary>
/// 减少耐久的防御塔数量
/// </summary>
public int Count;
/// <summary>
/// 防御塔耐久减少的量
/// </summary>
public int Amount;
public DamageRandomTowerEnduranceParam(int count, int amount)
{
Count = count;
Amount = amount;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a1b06f274c054844ad68b1db02d3737a
timeCreated: 1772101563
@@ -0,0 +1,14 @@
namespace GeometryTD.Definition
{
public abstract class EventEffectBase
{
public abstract EventEffectType EffectType { get; }
public abstract EventEffectParam Param { get; }
public float? Probability;
}
public class EventEffectParam
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2be5a7ff782240f79bde2dd0310d11ea
timeCreated: 1772101392
@@ -0,0 +1,27 @@
namespace GeometryTD.Definition
{
public class RemoveRandomCompsEffect : EventEffectBase
{
public override EventEffectType EffectType => EventEffectType.RemoveRandomComps;
public override EventEffectParam Param => _param;
private RemoveRandomCompsParam _param;
public RemoveRandomCompsEffect(RemoveRandomCompsParam param, float? probability = null)
{
_param = param;
Probability = probability;
}
}
public class RemoveRandomCompsParam : EventEffectParam
{
public int Count;
public RarityType Rarity;
public RemoveRandomCompsParam(int Count, RarityType Rarity)
{
this.Count = Count;
this.Rarity = Rarity;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77f8e0d1879b48108e6ad5faca07d7f7
timeCreated: 1772101548
@@ -0,0 +1,76 @@
using GeometryTD.CustomUtility;
using Newtonsoft.Json.Linq;
using UnityGameFramework.Runtime;
namespace GeometryTD.Definition
{
public static class EventEffectFactory
{
public static EventEffectBase Create(string rawType, JObject param, float? probability = null)
{
if (string.IsNullOrWhiteSpace(rawType))
{
return null;
}
EventEffectType type = EnumUtility<EventEffectType>.Get(rawType);
switch (type)
{
case EventEffectType.AddGold:
{
int count = GetInt(param, "Count");
return new AddGoldEffect(new AddGoldParam(count), probability);
}
case EventEffectType.RemoveRandomComps:
{
int count = GetInt(param, "Count");
RarityType rarity = EnumUtility<RarityType>.Get(GetString(param, "Rarity"));
return new RemoveRandomCompsEffect(new RemoveRandomCompsParam(count, rarity), probability);
}
case EventEffectType.AddRandomComps:
{
int count = GetInt(param, "Count");
RarityType rarity = EnumUtility<RarityType>.Get(GetString(param, "Rarity"));
return new AddRandomCompsEffect(new AddRandomCompsParam(count, rarity), probability);
}
case EventEffectType.DamageRandomTowersEndurance:
{
int count = GetInt(param, "Count");
int amount = GetInt(param, "Amount");
return new DamageRandomTowerEnduranceEffect(new DamageRandomTowerEnduranceParam(count, amount), probability);
}
default:
Log.Warning("Unsupported EventEffectType '{0}'.", rawType);
return null;
}
}
private static int GetInt(JObject param, params string[] keys)
{
if (param == null)
{
return 0;
}
foreach (string key in keys)
{
if (param.TryGetValue(key, out JToken token) && token.Type != JTokenType.Null)
{
return token.Value<int>();
}
}
return 0;
}
private static string GetString(JObject param, string key)
{
if (param == null || !param.TryGetValue(key, out JToken token) || token.Type == JTokenType.Null)
{
return string.Empty;
}
return token.Value<string>();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fae04d7a401d4c7fbe2de385c3f23580
timeCreated: 1772102401
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cee1f415e08743a9914efd2ecbc6273e
timeCreated: 1772100925
@@ -0,0 +1,26 @@
namespace GeometryTD.Definition
{
public class CompCountAtLeastRequirement : EventRequirementBase
{
public override EventRequirementType RequirementType => EventRequirementType.CompCountAtLeast;
public override EventRequirementParam Param => _param;
private CompCountAtLeastParam _param;
public CompCountAtLeastRequirement(CompCountAtLeastParam param)
{
_param = param;
}
}
public class CompCountAtLeastParam : EventRequirementParam
{
public int Count;
public RarityType Rarity;
public CompCountAtLeastParam(int count, RarityType rarity)
{
Count = count;
Rarity = rarity;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b845abef81934b75b266a738597bb890
timeCreated: 1772101103
@@ -0,0 +1,12 @@
namespace GeometryTD.Definition
{
public abstract class EventRequirementBase
{
public abstract EventRequirementType RequirementType { get; }
public abstract EventRequirementParam Param { get; }
}
public class EventRequirementParam
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eaa757b9c4cd4bcca38d73a30ab06285
timeCreated: 1772100961
@@ -0,0 +1,24 @@
namespace GeometryTD.Definition
{
public class GoldAtLeastRequirement : EventRequirementBase
{
public override EventRequirementType RequirementType => EventRequirementType.GoldAtLeast;
public override EventRequirementParam Param => _param;
private GoldAtLeastParam _param;
public GoldAtLeastRequirement(GoldAtLeastParam param)
{
_param = param;
}
}
public class GoldAtLeastParam : EventRequirementParam
{
public int Gold;
public GoldAtLeastParam(int gold)
{
Gold = gold;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a2de86ff2b442dd9f7d6af64f518bb8
timeCreated: 1772101058
@@ -0,0 +1,24 @@
namespace GeometryTD.Definition
{
public class HasRelicRequirement : EventRequirementBase
{
public override EventRequirementType RequirementType => EventRequirementType.HasRelic;
public override EventRequirementParam Param => _param;
private HasRelicParam _param;
public HasRelicRequirement(HasRelicParam param)
{
_param = param;
}
}
public class HasRelicParam : EventRequirementParam
{
public int RelicId;
public HasRelicParam(int relicId)
{
RelicId = relicId;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b06e03ee597d4345b95c524c7a6a27d4
timeCreated: 1772101234
@@ -0,0 +1,24 @@
namespace GeometryTD.Definition
{
public class TowerCountAtLeastRequirement : EventRequirementBase
{
public override EventRequirementType RequirementType => EventRequirementType.TowerCountAtLeast;
public override EventRequirementParam Param => _param;
private TowerCountAtLeastParam _param;
public TowerCountAtLeastRequirement(TowerCountAtLeastParam param)
{
_param = param;
}
}
public class TowerCountAtLeastParam : EventRequirementParam
{
public int Count;
public TowerCountAtLeastParam(int count)
{
Count = count;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 81a1102b3c0e4a53ae74ebb779ea7c19
timeCreated: 1772101156
@@ -0,0 +1,74 @@
using GeometryTD.CustomUtility;
using Newtonsoft.Json.Linq;
using UnityGameFramework.Runtime;
namespace GeometryTD.Definition
{
public static class EventRequirementFactory
{
public static EventRequirementBase Create(string rawType, JObject param)
{
if (string.IsNullOrWhiteSpace(rawType))
{
return null;
}
EventRequirementType type = EnumUtility<EventRequirementType>.Get(rawType);
switch (type)
{
case EventRequirementType.GoldAtLeast:
{
int count = GetInt(param, "Count", "Gold");
return new GoldAtLeastRequirement(new GoldAtLeastParam(count));
}
case EventRequirementType.CompCountAtLeast:
{
int count = GetInt(param, "Count");
RarityType rarity = EnumUtility<RarityType>.Get(GetString(param, "Rarity"));
return new CompCountAtLeastRequirement(new CompCountAtLeastParam(count, rarity));
}
case EventRequirementType.TowerCountAtLeast:
{
int count = GetInt(param, "Count");
return new TowerCountAtLeastRequirement(new TowerCountAtLeastParam(count));
}
case EventRequirementType.HasRelic:
{
int relicId = GetInt(param, "RelicId", "Id");
return new HasRelicRequirement(new HasRelicParam(relicId));
}
default:
Log.Warning("Unsupported EventRequirementType '{0}'.", rawType);
return null;
}
}
private static int GetInt(JObject param, params string[] keys)
{
if (param == null)
{
return 0;
}
foreach (string key in keys)
{
if (param.TryGetValue(key, out JToken token) && token.Type != JTokenType.Null)
{
return token.Value<int>();
}
}
return 0;
}
private static string GetString(JObject param, string key)
{
if (param == null || !param.TryGetValue(key, out JToken token) || token.Type == JTokenType.Null)
{
return string.Empty;
}
return token.Value<string>();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3b92d366cac404394c9e6aa1aa4062b
timeCreated: 1772102400
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7e5a261a50044ebe841fc7ae36c96f16
timeCreated: 1772112201
@@ -0,0 +1,27 @@
using GameFramework;
using GameFramework.Event;
namespace GeometryTD.CustomEvent
{
public class EventOptionItemSelectedEventArgs : GameEventArgs
{
public static int EventId => typeof(EventOptionItemSelectedEventArgs).GetHashCode();
public override int Id => EventId;
public int SelectedItemId { get; private set; } = -1;
public static EventOptionItemSelectedEventArgs Create(int selectedItemId)
{
var args = ReferencePool.Acquire<EventOptionItemSelectedEventArgs>();
args.SelectedItemId = selectedItemId;
return args;
}
public override void Clear()
{
SelectedItemId = -1;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e6152ef428a64a08a9dd279b73f45520
timeCreated: 1772112224
@@ -46,7 +46,7 @@ namespace GeometryTD.Procedure
GameEntry.Base.ResetNormalGameSpeed();
_nextSceneId = procedureOwner.GetData<VarInt32>("NextSceneId");
IDataTable<DRScene> dtScene = GameEntry.DataTable.GetDataTable<DRScene>();
DRScene drScene = dtScene.GetDataRow(_nextSceneId);
if (drScene == null)
@@ -55,7 +55,8 @@ namespace GeometryTD.Procedure
return;
}
GameEntry.Scene.LoadScene(AssetUtility.GetSceneAsset(drScene.AssetName), Constant.AssetPriority.SceneAsset, this);
GameEntry.Scene.LoadScene(AssetUtility.GetSceneAsset(drScene.AssetName), Constant.AssetPriority.SceneAsset,
this);
_backgroundMusicId = drScene.BackgroundMusicId;
}
@@ -81,13 +82,15 @@ namespace GeometryTD.Procedure
SceneType sceneType = (SceneType)_nextSceneId;
switch (sceneType)
{
//TODO:场景切换
// case SceneId.StressTest:
// ChangeState<ProcedureStressTest>(procedureOwner);
// break;
// default:
// Log.Debug($"Scene {sceneId.ToString()} don't configure a procedure");
// break;
case SceneType.Menu:
ChangeState<ProcedureMenu>(procedureOwner);
break;
case SceneType.Main:
ChangeState<ProcedureTest>(procedureOwner);
break;
default:
Log.Debug($"Scene {sceneType.ToString()} don't configure a procedure");
break;
}
}
@@ -139,7 +142,8 @@ namespace GeometryTD.Procedure
return;
}
Log.Info("Load scene '{0}' dependency asset '{1}', count '{2}/{3}'.", ne.SceneAssetName, ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString());
Log.Info("Load scene '{0}' dependency asset '{1}', count '{2}/{3}'.", ne.SceneAssetName,
ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString());
}
}
}
}
@@ -0,0 +1,49 @@
using GameFramework.Fsm;
using GameFramework.Procedure;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
namespace GeometryTD.Procedure
{
public class ProcedureMenu : ProcedureBase
{
public override bool UseNativeDialog => false;
public bool GameStart { get; set; }
#region FSM
protected override void OnInit(IFsm<IProcedureManager> procedureOwner)
{
base.OnInit(procedureOwner);
}
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
GameStart = false;
GameEntry.EventNode.OnInit();
GameEntry.CombatNode.OnInit(LevelThemeType.Plain);
}
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
float realElapseSeconds)
{
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
if (GameStart)
{
procedureOwner.SetData<VarInt32>("NextSceneId", (int)SceneType.Main);
ChangeState<ProcedureChangeScene>(procedureOwner);
}
}
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
{
base.OnLeave(procedureOwner, isShutdown);
}
#endregion
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ac91f61cef224d7ab324491156d904bb
timeCreated: 1772105440
@@ -25,16 +25,22 @@ namespace GeometryTD.Procedure
{
public static readonly string[] DataTableNames = new string[]
{
"BaseComp",
"BearingComp",
"Enemy",
"Entity",
"Event",
"Level",
"LevelPhase",
"LevelSpawnEntry",
"Music",
"MuzzleComp",
"Scene",
"ShopPrice",
"Sound",
"Tag",
"UIForm",
"UISound",
"MuzzleComp",
"BearingComp",
"BaseComp",
"Tag",
};
private Dictionary<string, bool> _loadedFlag = new Dictionary<string, bool>();
@@ -128,37 +134,39 @@ namespace GeometryTD.Procedure
private void LoadFont(string fontName)
{
_loadedFlag.Add(Utility.Text.Format("Font.{0}", fontName), false);
GameEntry.Resource.LoadAsset(AssetUtility.GetFontAsset(fontName), Constant.AssetPriority.FontAsset, new LoadAssetCallbacks(
(assetName, asset, duration, userData) =>
{
_loadedFlag[Utility.Text.Format("Font.{0}", fontName)] = true;
UGuiForm.SetMainFont((Font)asset);
Log.Info("Load font '{0}' OK.", fontName);
},
(assetName, status, errorMessage, userData) =>
{
Log.Error("Can not load font '{0}' from '{1}' with error message '{2}'.", fontName, assetName, errorMessage);
}));
GameEntry.Resource.LoadAsset(AssetUtility.GetFontAsset(fontName), Constant.AssetPriority.FontAsset,
new LoadAssetCallbacks(
(assetName, asset, duration, userData) =>
{
_loadedFlag[Utility.Text.Format("Font.{0}", fontName)] = true;
UGuiForm.SetMainFont((Font)asset);
Log.Info("Load font '{0}' OK.", fontName);
},
(assetName, status, errorMessage, userData) =>
{
Log.Error("Can not load font '{0}' from '{1}' with error message '{2}'.", fontName, assetName,
errorMessage);
}));
}
private void LoadTMPFont(string fontName)
{
_loadedFlag.Add(Utility.Text.Format("Font.{0}", fontName), false);
GameEntry.Resource.LoadAsset(AssetUtility.GetTMPFontAsset(fontName), Constant.AssetPriority.FontAsset, new LoadAssetCallbacks(
(assetName, asset, duration, userData) =>
{
_loadedFlag[Utility.Text.Format("Font.{0}", fontName)] = true;
UGuiForm.SetMainTMPFont((TMP_FontAsset)asset);
Log.Info("Load font '{0}' OK.", fontName);
},
(assetName, status, errorMessage, userData) =>
{
Log.Error("Can not load font '{0}' from '{1}' with error message '{2}'.", fontName, assetName, errorMessage);
}));
GameEntry.Resource.LoadAsset(AssetUtility.GetTMPFontAsset(fontName), Constant.AssetPriority.FontAsset,
new LoadAssetCallbacks(
(assetName, asset, duration, userData) =>
{
_loadedFlag[Utility.Text.Format("Font.{0}", fontName)] = true;
UGuiForm.SetMainTMPFont((TMP_FontAsset)asset);
Log.Info("Load font '{0}' OK.", fontName);
},
(assetName, status, errorMessage, userData) =>
{
Log.Error("Can not load font '{0}' from '{1}' with error message '{2}'.", fontName, assetName,
errorMessage);
}));
}
private void OnLoadConfigSuccess(object sender, GameEventArgs e)
{
LoadConfigSuccessEventArgs ne = (LoadConfigSuccessEventArgs)e;
@@ -179,7 +187,8 @@ namespace GeometryTD.Procedure
return;
}
Log.Error("Can not load config '{0}' from '{1}' with error message '{2}'.", ne.ConfigAssetName, ne.ConfigAssetName, ne.ErrorMessage);
Log.Error("Can not load config '{0}' from '{1}' with error message '{2}'.", ne.ConfigAssetName,
ne.ConfigAssetName, ne.ErrorMessage);
}
private void OnLoadDataTableSuccess(object sender, GameEventArgs e)
@@ -202,7 +211,8 @@ namespace GeometryTD.Procedure
return;
}
Log.Error("Can not load data table '{0}' from '{1}' with error message '{2}'.", ne.DataTableAssetName, ne.DataTableAssetName, ne.ErrorMessage);
Log.Error("Can not load data table '{0}' from '{1}' with error message '{2}'.", ne.DataTableAssetName,
ne.DataTableAssetName, ne.ErrorMessage);
}
private void OnLoadDictionarySuccess(object sender, GameEventArgs e)
@@ -225,7 +235,8 @@ namespace GeometryTD.Procedure
return;
}
Log.Error("Can not load dictionary '{0}' from '{1}' with error message '{2}'.", ne.DictionaryAssetName, ne.DictionaryAssetName, ne.ErrorMessage);
Log.Error("Can not load dictionary '{0}' from '{1}' with error message '{2}'.", ne.DictionaryAssetName,
ne.DictionaryAssetName, ne.ErrorMessage);
}
}
}
}
@@ -0,0 +1,30 @@
using GameFramework.Fsm;
using GameFramework.Procedure;
namespace GeometryTD.Procedure
{
public class ProcedureTest : ProcedureBase
{
public override bool UseNativeDialog => false;
#region FSM
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
}
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
float realElapseSeconds)
{
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
}
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
{
base.OnLeave(procedureOwner, isShutdown);
}
#endregion
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a5a3c55b2b34a159cbb1680728d87d3
timeCreated: 1772105466
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 34c97e1af6767d049b17b5c4ff75cb5a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,12 @@
using GeometryTD.UI;
namespace GeometryTD.UI
{
public class EventFormContext : UIContext
{
public int EventId;
public string Title;
public string Description;
public EventOptionItemContext[] OptionItems;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 95f3e80a51954c66b14e41365622d63f
timeCreated: 1772104202
@@ -0,0 +1,8 @@
namespace GeometryTD.UI
{
public class EventOptionItemContext
{
public int OptionIndex;
public string OptionText;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f56befc364564ac8b499f81ca48a165b
timeCreated: 1772104201
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 043cb0d817552b549aeff457ac685a0b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
using GeometryTD.Definition;
using GeometryTD.CustomEvent;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace GeometryTD.UI
{
public class EventFormController : UIFormControllerCommonBase<EventFormContext, EventForm>
{
private EventFormUseCase m_UseCase;
protected override UIFormType UIFormTypeId => UIFormType.EventForm;
protected override void RefreshUI(EventForm form, EventFormContext context)
{
form.RefreshUI(context);
}
protected override void SubscribeCustomEvents()
{
GameEntry.Event.Subscribe(EventOptionItemSelectedEventArgs.EventId, OnEventOptionItemSelected);
}
protected override void UnsubscribeCustomEvents()
{
GameEntry.Event.Unsubscribe(EventOptionItemSelectedEventArgs.EventId, OnEventOptionItemSelected);
}
public override int? OpenUI(object userData = null)
{
if (userData is EventFormContext eventFormContext)
{
return OpenUIInternal(eventFormContext);
}
if (userData is EventFormRawData rawDataFromUserData)
{
return OpenUI(rawDataFromUserData);
}
if (userData != null)
{
Log.Warning("EventFormController.OpenUI() userData type is invalid.");
return null;
}
if (m_UseCase == null)
{
Log.Error("EventFormController.OpenUI() useCase is null.");
return null;
}
EventFormRawData rawData = m_UseCase.CreateInitialModel();
return OpenUI(rawData);
}
public int? OpenUI(EventFormRawData rawData)
{
EventFormContext context = BuildContext(rawData);
return OpenUIInternal(context);
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is EventFormUseCase eventFormUseCase))
{
Log.Error("EventFormController.BindUseCase() useCase is invalid.");
return;
}
m_UseCase = eventFormUseCase;
}
private static EventFormContext BuildContext(EventFormRawData rawData)
{
if (rawData?.EventItem == null)
{
return null;
}
EventOptionItemContext[] options = new EventOptionItemContext[4];
for (int i = 0; i < options.Length; i++)
{
string optionText = string.Empty;
if (rawData.EventItem.Options != null && i < rawData.EventItem.Options.Length &&
rawData.EventItem.Options[i] != null)
{
optionText = rawData.EventItem.Options[i].OptionText;
}
options[i] = new EventOptionItemContext
{
OptionIndex = i,
OptionText = optionText
};
}
return new EventFormContext
{
EventId = rawData.EventItem.Id,
Title = rawData.EventItem.Title,
Description = rawData.EventItem.Description,
OptionItems = options
};
}
private void OnEventOptionItemSelected(object sender, GameEventArgs e)
{
if (!(e is EventOptionItemSelectedEventArgs args))
{
return;
}
if (m_UseCase == null)
{
Log.Warning("EventFormController.OnOptionSelected() useCase is null.");
return;
}
m_UseCase.SelectOption(args.SelectedItemId);
CloseUI();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 916da3490ed14b01ae064cbb37880bba
timeCreated: 1772104204
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a0e002d6d3ee84d46859c7933b285513
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
using GeometryTD.Definition;
namespace GeometryTD.UI
{
public class EventFormRawData
{
public EventItem EventItem;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 463e60ff83314069b83158ccf64cddef
timeCreated: 1772104200
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 90fb2ec88edcd2942abcf17a4e206f3e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,46 @@
using GeometryTD.Definition;
using GeometryTD.UI;
using UnityGameFramework.Runtime;
namespace GeometryTD.UI
{
public class EventFormUseCase : IUIUseCase
{
private EventItem m_CurrentEvent;
public void SetCurrentEvent(EventItem eventItem)
{
m_CurrentEvent = eventItem;
}
public EventFormRawData CreateInitialModel()
{
if (m_CurrentEvent == null)
{
return null;
}
return new EventFormRawData
{
EventItem = m_CurrentEvent
};
}
public EventOption SelectOption(int optionIndex)
{
if (m_CurrentEvent == null || m_CurrentEvent.Options == null)
{
return null;
}
if (optionIndex < 0 || optionIndex >= m_CurrentEvent.Options.Length)
{
Log.Warning("EventFormUseCase.SelectOption() option index is invalid: {0}", optionIndex);
return null;
}
// TODO: 执行 Requirements 校验、CostEffects/RewardEffects 结算与后续节点推进。
return m_CurrentEvent.Options[optionIndex];
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 80d6d6100109462ea498781e9e70201d
timeCreated: 1772104203
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1f5bf29ff4f1c404cb5b42fb54a8e0b4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,81 @@
using TMPro;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace GeometryTD.UI
{
public class EventForm : UGuiForm
{
[SerializeField] private TMP_Text m_TitleText;
[SerializeField] private TMP_Text m_DescriptionText;
[SerializeField] private EventOptionItem[] m_OptionItems;
private EventFormContext m_Context;
public void RefreshUI(EventFormContext context)
{
m_Context = context;
if (m_TitleText != null)
{
m_TitleText.text = context?.Title ?? string.Empty;
}
if (m_DescriptionText != null)
{
m_DescriptionText.text = context?.Description ?? string.Empty;
}
for (int i = 0; i < m_OptionItems.Length; i++)
{
EventOptionItemContext optionContext = null;
if (context?.OptionItems != null && i < context.OptionItems.Length)
{
optionContext = context.OptionItems[i];
}
if (m_OptionItems[i] != null)
{
m_OptionItems[i].OnInit(optionContext);
}
}
}
protected override void OnOpen(object userData)
{
base.OnOpen(userData);
if (userData is EventFormContext context)
{
RefreshUI(context);
return;
}
Log.Warning("EventForm requires EventFormContext as userData.");
}
protected override void OnClose(bool isShutdown, object userData)
{
m_Context = null;
if (m_TitleText != null)
{
m_TitleText.text = string.Empty;
}
if (m_DescriptionText != null)
{
m_DescriptionText.text = string.Empty;
}
for (int i = 0; i < m_OptionItems.Length; i++)
{
if (m_OptionItems[i] != null)
{
m_OptionItems[i].OnReset();
}
}
base.OnClose(isShutdown, userData);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 81064d72b60548b6b54d07d94d20b519
timeCreated: 1772104206
@@ -0,0 +1,50 @@
using GeometryTD.CustomEvent;
using TMPro;
using UnityEngine;
namespace GeometryTD.UI
{
public class EventOptionItem : MonoBehaviour
{
[SerializeField] private TMP_Text _optionText;
private int _optionIndex;
public void OnInit(EventOptionItemContext context)
{
if (context == null)
{
OnReset();
gameObject.SetActive(false);
return;
}
_optionIndex = context.OptionIndex;
if (_optionText != null)
{
_optionText.text = context.OptionText ?? string.Empty;
}
gameObject.SetActive(!string.IsNullOrEmpty(context.OptionText));
}
public void OnReset()
{
_optionIndex = -1;
if (_optionText != null)
{
_optionText.text = string.Empty;
}
}
public void OnClick()
{
if (_optionIndex < 0)
{
return;
}
GameEntry.Event.Fire(this, EventOptionItemSelectedEventArgs.Create(_optionIndex));
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 86cf465d14c649a58473c19ae946d220
timeCreated: 1772104205
@@ -23,7 +23,8 @@ namespace GeometryTD.CustomUtility
public static string GetDictionaryAsset(string assetName, bool fromBytes)
{
return Utility.Text.Format("Assets/GameMain/Localization/{0}/Dictionaries/{1}.{2}", GameEntry.Localization.Language, assetName, fromBytes ? "bytes" : "xml");
return Utility.Text.Format("Assets/GameMain/Localization/{0}/Dictionaries/{1}.{2}",
GameEntry.Localization.Language, assetName, fromBytes ? "bytes" : "xml");
}
public static string GetFontAsset(string assetName)
@@ -35,7 +36,7 @@ namespace GeometryTD.CustomUtility
{
return Utility.Text.Format("Assets/GameMain/Fonts/{0}.asset", assetName);
}
public static string GetSceneAsset(string assetName)
{
return Utility.Text.Format("Assets/GameMain/Scenes/{0}.unity", assetName);
@@ -65,5 +66,10 @@ namespace GeometryTD.CustomUtility
{
return Utility.Text.Format("Assets/GameMain/UI/UISounds/{0}.wav", assetName);
}
public static string GetLevelMapAsset(string assetName)
{
return Utility.Text.Format("Assets/GameMain/LevelMap/Level{0}.prefab", assetName);
}
}
}
}
@@ -0,0 +1,26 @@
using System;
using Newtonsoft.Json;
namespace GeometryTD.CustomUtility
{
/// <summary>
/// Newtonsoft.Json 函数集辅助器。
/// </summary>
public class JsonNetUtility : GameFramework.Utility.Json.IJsonHelper
{
public string ToJson(object obj)
{
return JsonConvert.SerializeObject(obj);
}
public T ToObject<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json);
}
public object ToObject(Type objectType, string json)
{
return JsonConvert.DeserializeObject(json, objectType);
}
}
}
@@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: 894291f7d20e5dc4bb7264dec378b1ce
timeCreated: 1528026163
licenseType: Pro
guid: a64f8e5b71575bd43802e0761393bc50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
@@ -1,52 +0,0 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using LitJson;
using System;
namespace GeometryTD.CustomUtility
{
/// <summary>
/// LitJSON 函数集辅助器。
/// </summary>
internal class LitJsonHelper : Utility.Json.IJsonHelper
{
/// <summary>
/// 将对象序列化为 JSON 字符串。
/// </summary>
/// <param name="obj">要序列化的对象。</param>
/// <returns>序列化后的 JSON 字符串。</returns>
public string ToJson(object obj)
{
return JsonMapper.ToJson(obj);
}
/// <summary>
/// 将 JSON 字符串反序列化为对象。
/// </summary>
/// <typeparam name="T">对象类型。</typeparam>
/// <param name="json">要反序列化的 JSON 字符串。</param>
/// <returns>反序列化后的对象。</returns>
public T ToObject<T>(string json)
{
return JsonMapper.ToObject<T>(json);
}
/// <summary>
/// 将 JSON 字符串反序列化为对象。
/// </summary>
/// <param name="objectType">对象类型。</param>
/// <param name="json">要反序列化的 JSON 字符串。</param>
/// <returns>反序列化后的对象。</returns>
public object ToObject(Type objectType, string json)
{
// TODO: 可反射为 ToObject<T>(string json)
throw new NotSupportedException("ToObject(Type objectType, string json)");
}
}
}