找回密码
 立即注册
查看: 115|回复: 0

Unity自动化 - 编纂器扩展篇

[复制链接]
发表于 2024-8-2 09:34 | 显示全部楼层 |阅读模式
UnityEditor扩展

Unity可以在Hierarchy、Project、东西栏(别名:Context)等(右键)列表中新增功能。
注意:

  • 函数必需静态才能调用。
  • 这类方式需要放在Editor文件下,否则打不出包。
Hierarchy


  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Nory
  4. {
  5.     public static class HierarchyMenuInspector
  6.     {
  7.         [MenuItem(”GameObject/扩展/重定名/挨次父节点名”, priority = 0)]
  8.         static void OrderName()
  9.         {
  10.             Transform parent = Selection.activeTransform;
  11.             string name = parent.name;
  12.             for (int i = 0; i < parent.childCount; i++)
  13.             {
  14.                 Transform t = parent.GetChild(i);
  15.                 Undo.RegisterFullObjectHierarchyUndo(t, t.name);
  16.                 t.name = name + i;
  17.             }
  18.         }
  19. }
复制代码
<hr/>Project


  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Nory
  4. {
  5.     public static class ProjectMenuInspector
  6.     {
  7.         [MenuItem(”Assets/Copy Resource Path”, false, 2)]
  8.         public static void CopyResourcePath()
  9.         {
  10.             string[] strs = Selection.assetGUIDs;
  11.             string path = AssetDatabase.GUIDToAssetPath(strs[0]);
  12.             string pre_path = path.Substring(17);
  13.             string last_path = pre_path.Split(&#39;.&#39;)[0];
  14.             GUIUtility.systemCopyBuffer = last_path;
  15.         }
  16.     }
  17. }
复制代码
<hr/>Context


  1. using System.Text;
  2. using System;
  3. using System.IO;
  4. using UnityEngine;
  5. using UnityEditor;
  6. namespace Nory
  7. {
  8.     public static class ContextMenuInspector
  9.     {
  10.         [MenuItem(”Tools/输出预制体名”)]
  11.         public static void OutName()
  12.         {
  13.             string path = ”Assets/Art/Perfab”;//Assets/Scenes
  14.             string outpath = @”Assets/Art/outmes.txt”;
  15.             if (Directory.Exists(path))
  16.             {
  17.                 DirectoryInfo directoryInfo = new DirectoryInfo(path);
  18.                 FileInfo[] fileInfos = directoryInfo.GetFiles(”*”, SearchOption.AllDirectories);
  19.                 StringBuilder builder = new StringBuilder();
  20.                 for (int i = 0; i < fileInfos.Length; i++)
  21.                 {
  22.                     if (fileInfos[i].Name.EndsWith(”.prefab”))
  23.                     {
  24.                         builder.Append(Path.GetFileNameWithoutExtension(fileInfos[i].Name) + Environment.NewLine);
  25.                     }
  26.                 }
  27.                 File.WriteAllText(outpath, builder.ToString());
  28.                 Debug.Log(”Done”);
  29.             }
  30.         }
  31.     }
  32. }
复制代码
<hr/>Game

即时模式 GUI (IMGUI) - Unity 手册

  • 创建游戏内调试显示和东西。
  • 为脚本组件创建自定义检视面板。
  • 创建新的编纂器窗口和东西以扩展 Unity 本身。
<hr/>Inspector


  • 自定义编纂器 - Unity 手册
  • Unity3D研究院之Inspector面板枚举的别号与排序(八十九) | 雨松MOMO法式研究院(中文枚举)
  • Unity中实现字段/枚举编纂器中显示中文(中文枚举、中文标签)
  • Unity3d Editor 编纂器扩展功能详解(1) 目录索引 - 李恒的文章 - 知乎
<hr/>ProjectSetting

UnityEditor.SettingsProvider - Unity 脚本 API

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-21 10:46 , Processed in 0.132114 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表