Unity自动化 - 编纂器扩展篇
UnityEditor扩展Unity可以在Hierarchy、Project、东西栏(别名:Context)等(右键)列表中新增功能。
注意:
[*]函数必需静态才能调用。
[*]这类方式需要放在Editor文件下,否则打不出包。
Hierarchy
using UnityEditor;
using UnityEngine;
namespace Nory
{
public static class HierarchyMenuInspector
{
static void OrderName()
{
Transform parent = Selection.activeTransform;
string name = parent.name;
for (int i = 0; i < parent.childCount; i++)
{
Transform t = parent.GetChild(i);
Undo.RegisterFullObjectHierarchyUndo(t, t.name);
t.name = name + i;
}
}
}<hr/>Project
using UnityEditor;
using UnityEngine;
namespace Nory
{
public static class ProjectMenuInspector
{
public static void CopyResourcePath()
{
string[] strs = Selection.assetGUIDs;
string path = AssetDatabase.GUIDToAssetPath(strs);
string pre_path = path.Substring(17);
string last_path = pre_path.Split('.');
GUIUtility.systemCopyBuffer = last_path;
}
}
}<hr/>Context
using System.Text;
using System;
using System.IO;
using UnityEngine;
using UnityEditor;
namespace Nory
{
public static class ContextMenuInspector
{
public static void OutName()
{
string path = ”Assets/Art/Perfab”;//Assets/Scenes
string outpath = @”Assets/Art/outmes.txt”;
if (Directory.Exists(path))
{
DirectoryInfo directoryInfo = new DirectoryInfo(path);
FileInfo[] fileInfos = directoryInfo.GetFiles(”*”, SearchOption.AllDirectories);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < fileInfos.Length; i++)
{
if (fileInfos.Name.EndsWith(”.prefab”))
{
builder.Append(Path.GetFileNameWithoutExtension(fileInfos.Name) + Environment.NewLine);
}
}
File.WriteAllText(outpath, builder.ToString());
Debug.Log(”Done”);
}
}
}
}<hr/>Game
即时模式 GUI (IMGUI) - Unity 手册
[*]创建游戏内调试显示和东西。
[*]为脚本组件创建自定义检视面板。
[*]创建新的编纂器窗口和东西以扩展 Unity 本身。
<hr/>Inspector
[*]自定义编纂器 - Unity 手册
[*]Unity3D研究院之Inspector面板枚举的别号与排序(八十九) | 雨松MOMO法式研究院(中文枚举)
[*]Unity中实现字段/枚举编纂器中显示中文(中文枚举、中文标签)
[*]Unity3d Editor 编纂器扩展功能详解(1) 目录索引 - 李恒的文章 - 知乎
<hr/>ProjectSetting
UnityEditor.SettingsProvider - Unity 脚本 API
页:
[1]