53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
public class SkillSpriteFiller
|
|
{
|
|
|
|
[MenuItem("填表脚本/补全SkillDataAsset的Sprite信息(UI2.0迭代一次性)")]
|
|
public static void SaveData()
|
|
{
|
|
// 1. 自动在场景中根据路径查找对象
|
|
string objectPath = "UICanvas/BottomInfoPanel/InfoGroup/UnitBaseInfo/SkillIconArea";
|
|
GameObject targetObject = GameObject.Find(objectPath);
|
|
if (targetObject == null)
|
|
{
|
|
Debug.LogError($"无法在场景中找到对象: {objectPath}");
|
|
return;
|
|
}
|
|
|
|
string dataAssetPath = "DataAssets/SkillDataAssets";
|
|
SkillDataAssets skillDataAssets = TH1Resource.ResourceLoader.Load<SkillDataAssets>(dataAssetPath);
|
|
|
|
|
|
// 2. 从找到的对象上获取组件
|
|
foreach (Transform child in targetObject.transform)
|
|
{
|
|
var skillMono = child.GetComponent<SkillIdMono>();
|
|
if (skillMono == null) continue;
|
|
var t = child.Find("Icon")?.GetComponent<Image>()?.sprite;
|
|
if (t == null) continue;
|
|
|
|
string assetPath = AssetDatabase.GetAssetPath(t);
|
|
if (string.IsNullOrEmpty(assetPath))
|
|
{
|
|
Debug.LogWarning($"Sprite '{t.name}' on '{child.name}' is not a persistent asset. Skipping.", child);
|
|
continue;
|
|
}
|
|
if (skillDataAssets.GetSkillInfo(skillMono.SkillTpe, out var info))
|
|
{
|
|
// 假设 SkillInfo 中有 SkillIconPath 字段
|
|
info.SkillIcon = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
|
|
}
|
|
|
|
}
|
|
|
|
EditorUtility.SetDirty(skillDataAssets);
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
}
|
|
} |