在开发UI界面时,在面对需多UI组件都有各种逻辑时,获取组件的相对路径是一件很痛苦的事儿,在这里提供一个编辑器脚本,可以快速获取各种组件的相对路径:
创建UIPathExporter.cs 放入Editor 文件夹下即可,目前只是针对部分ui的组件有需要增加的自行在componentTypes中添加;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions; // 用于正则表达式处理
public class UIPathExporter : EditorWindow
{
private GameObject uiPrefab;
private GameObject objectToExport; // 新增字段用于拖入 GameObject
private List<string> componentTypes = new List<string> { "Button", "TextMeshProUGUI", "Image", "RawImage", "TMP_InputField" }; // 保留关键字
private bool[] componentSelection;
private string customTransformName = "UITransform"; // 默认为 UITransform
private bool includeInactive = false; // 是否输出未激活的游戏对象
[MenuItem("Tools/目标路径导出工