TH1/Unity/Assets/Editor/TechToTechAtomDataAssetFiller.cs
2025-11-19 21:11:18 +08:00

106 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using Logic.Action;
public class TechToTechAtomDataAssetFiller
{
[MenuItem("填表脚本/Tech所有Action转化为TechAtom")]
public static void FillMissingCivSprites()
{
string assetPath = "Assets/Resources/DataAssets/TechDataAssets.asset";
var asset = AssetDatabase.LoadAssetAtPath<TechDataAssets>(assetPath);
string actionAssetPath = "Assets/Resources/DataAssets/ActionDataAssets.asset";
var actionAsset = AssetDatabase.LoadAssetAtPath<ActionDataAssets>(actionAssetPath);
if (asset == null)
{
Debug.LogError("❌ 找不到 UnitTypeDataAssets.asset请确认路径正确");
return;
}
int addCount = 0;
foreach (var techInfo in asset.TechList)
{
foreach (var action in techInfo.techActions)
{
if (action.ActionType is CommonActionType.UnitSkill or CommonActionType.UnitAction
or CommonActionType.TrainUnit or CommonActionType.BuildWonder or CommonActionType.StartWonder)
{
//Debug.Log(action.SkillType);
var str = "";
if(action.ActionType is CommonActionType.UnitSkill)
str = "UnitSkill" + action.SkillType.ToString();
if(action.ActionType is CommonActionType.UnitAction)
str = "UnitAction" + action.UnitActionType.ToString();
if(action.ActionType is CommonActionType.TrainUnit)
str = "TrainUnit" + action.UnitType.ToString();
if(action.ActionType is CommonActionType.StartWonder)
str = "StartWonder" + action.WonderType.ToString();
if(action.ActionType is CommonActionType.BuildWonder)
str = "BuildWonder" + action.WonderType.ToString();
var has = false;
foreach(var techAtom in asset.TechAtomList)
if (techAtom.TechAtom.ToString() == str)
{
has = true;
break;
}
if (!has)
{
var info = new TechAtomInfo();
if (TechAtom.TryParse(str, out info.TechAtom))
{
foreach (var actionInfo in actionAsset.ActionList)
{
if (actionInfo.ActionId == action)
{
info.TechAtomName = actionInfo.ActionName;
info.Desc = actionInfo.NeedTechDesc ? actionInfo.TechDesc : actionInfo.Desc;
}
}
asset.TechAtomList.Add(info);
addCount++;
}
}
if (TechAtom.TryParse(str, out TechAtom techAtom2))
{
bool alreadyHas = false;
foreach(var techAtom in techInfo.TechAtomList)
if (techAtom == techAtom2)
{
alreadyHas = true;
break;
}
if (!alreadyHas)
{
techInfo.TechAtomList.Add(techAtom2);
}
}
}
}
}
EditorUtility.SetDirty(asset);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log($"✅ 补全完成:共添加了 {addCount} 个 TechAtom 条目。");
}
}