// Copyright (c) 2025 EFramework Innovation. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using EFramework.Unity.Editor;
namespace EFramework.Unity.UIPlugin.Editor
{
///
/// UICanvasEditor 是 UICanvas 组件的编辑器工具,提供了自定义图标和项目视图集成。
///
///
///
/// 功能特性
/// - 为 Canvas 预制体在项目窗口中显示自定义图标
/// - 自动处理资源导入和移动事件
/// - 支持在项目视图中快速识别 Canvas 对象
///
/// 更多信息请参考模块文档。
///
public class UICanvasEditor : XEditor.Event.Internal.OnEditorLoad
{
///
/// icon 是 UICanvas 组件的自定义图标,用于优化资源的显示。
///
internal static Texture2D icon;
int XEditor.Event.Callback.Priority { get; }
bool XEditor.Event.Callback.Singleton { get => true; }
///
/// OnEditorLoad 事件回调处理了文件视图的绘制监听。
///
void XEditor.Event.Internal.OnEditorLoad.Process(params object[] _)
{
// 加载图标
var pkg = XEditor.Utility.FindPackage();
icon = AssetDatabase.LoadAssetAtPath($"Packages/{pkg.name}/Editor/Resources/Icon/Canvas.png");
// 监听绘制
if (icon) EditorApplication.projectWindowItemOnGUI += OnProjectWindowItemOnGUI;
}
///
/// OnProjectWindowItemOnGUI 是项目窗口绘制的回调,为 UICanvas 预制体添加自定义图标。
///
/// 资源的 GUID
/// 项目窗口中的绘制区域
internal static void OnProjectWindowItemOnGUI(string guid, Rect selectionRect)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
if (path.EndsWith("prefab") && AssetDatabase.LoadAssetAtPath