using System.IO;
using TMPro;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
using Colosseum.Passives;
using Colosseum.UI;
namespace Colosseum.Editor
{
///
/// 패시브 트리 uGUI 프리팹을 재생성하는 에디터 유틸리티입니다.
///
public static class PassiveTreeUiPrefabBuilder
{
private const string PrefabFolder = "Assets/_Game/Prefabs/UI/PassiveTree";
private const string ViewPrefabPath = PrefabFolder + "/UI_PassiveTreeView.prefab";
private const string NodePrefabPath = PrefabFolder + "/UI_PassiveTreeNode.prefab";
private const string PlayerHudPrefabPath = "Assets/_Game/Prefabs/UI/UI_PlayerResources.prefab";
private const string PreferredFontAssetPath = "Assets/_Game/Fonts/TMP/TMP_MaruBuri.asset";
private const string NormalIconSpritePath = "Assets/_Game/Icons/Icon_Passive_Normal.png";
private const string SpecialIconSpritePath = "Assets/_Game/Icons/Icon_Passive_Special.png";
private const string PassiveCatalogAssetPath = "Assets/_Game/Data/Passives/Data_PassivePrototypeCatalog.asset";
private static readonly Color PanelBackgroundColor = new(0.07f, 0.07f, 0.10f, 0.98f);
private static readonly Color SectionBackgroundColor = new(0.12f, 0.12f, 0.16f, 0.96f);
private static readonly Color SectionOverlayColor = new(0f, 0f, 0f, 0.12f);
private static readonly Color ToggleButtonColor = new(0.18f, 0.21f, 0.16f, 0.96f);
private static readonly Color CloseButtonColor = new(0.34f, 0.20f, 0.20f, 0.96f);
private static readonly Color ButtonColor = new(0.20f, 0.20f, 0.24f, 0.96f);
private static readonly Color TextColor = new(0.90f, 0.88f, 0.82f, 1f);
private static readonly Color NodeColor = new(0.16f, 0.16f, 0.18f, 0.98f);
private static readonly Color NodeFillColor = new(0.08f, 0.08f, 0.10f, 0.98f);
private static readonly Color NodeOutlineColor = new(0f, 0f, 0f, 0.45f);
[MenuItem("Tools/Colosseum/Passives/Rebuild Passive UI Prefabs")]
public static void RebuildPassiveUiPrefabs()
{
EnsureFolders();
PassiveTreeNodeView nodePrefab = BuildNodePrefab();
PassiveTreeViewReferences viewPrefab = BuildViewPrefab();
BindPlayerHudPrefab(viewPrefab, nodePrefab);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log("[PassiveTreeUiPrefabBuilder] 패시브 UI 프리팹 재생성을 완료했습니다.");
}
private static void EnsureFolders()
{
if (!AssetDatabase.IsValidFolder("Assets/_Game/Prefabs/UI"))
{
AssetDatabase.CreateFolder("Assets/_Game/Prefabs", "UI");
}
if (!AssetDatabase.IsValidFolder(PrefabFolder))
{
AssetDatabase.CreateFolder("Assets/_Game/Prefabs/UI", "PassiveTree");
}
}
private static PassiveTreeNodeView BuildNodePrefab()
{
GameObject root = new("UI_PassiveTreeNode", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button), typeof(Outline), typeof(PassiveTreeNodeView));
try
{
RectTransform rect = root.GetComponent();
rect.sizeDelta = new Vector2(62f, 62f);
Image background = root.GetComponent();
background.sprite = LoadPassiveNodeSprite(false);
background.type = Image.Type.Simple;
background.preserveAspect = true;
background.color = NodeColor;
Outline outline = root.GetComponent();
outline.effectColor = NodeOutlineColor;
outline.effectDistance = new Vector2(2f, 2f);
Button button = root.GetComponent