常用的编辑器语法:
unity编辑器核心功能类:EditorUtility
EditorUtility.DisplayPopupMenu 小窗口
EditorUtility.DisplayProgressBar 显示进度条
EditorUtility.DisplayDialog 警告框
EditorUtility.OpenFilePanel 打开文件路径
EditorUtility.OpenFolderPanel 打开文件夹路径
EditorUtility.CreateEmptyPrefab 创建预制体
编辑器文件类:FileUtil
FileUtil.CopyFileOrDirectory 复制文件
FileUtil.MoveFileOrDirectory 移动文件
FileUtil.ReplaceFile 替换文件
编辑器绘制UI类:Handles
Handles.CubeHandleCap 绘制cube
Handles.DrawLine 绘制线条
Handles.ArrowHandleCap 绘制箭头
编辑器帮助类:Help
Help.BrowseURL 浏览指定的额URL
Help.ShowHelpPage 展示帮助页面
编辑器inspected可以编辑器类:CustomEditor
编辑器应用类:EditorApplication
EditorApplication.OpenScene 打开场景
EditorApplication.isPlaying 编辑器是否在运行
菜单选中:
const string kAIMenu = "AI/On";
static bool isOn = EpicPrefs.GetBool(PrefsName.aiSwitch);
[MenuItem(kAIMenu)]
public static void ToggleSimulateAssetBundle()
{
isOn = !isOn;
EpicPrefs.SetBool(PrefsName.aiSwitch, isOn);
}
[MenuItem(kAIMenu, true)]
public static bool ToggleSimulateAssetBundleValidate()
{
Menu.SetChecked(kAIMenu, isOn);
return true;
}
以下为编辑器制作使用的语法例子:
1.编辑器界面启动:(注:%代表Ctrl ,&代表ALT, #代表Shift)
[MenuItem("Tools/地图编辑器 _&_s")]
static void CreatFightMapWindow()
{
window = GetWindow
window.autoRepaintOnSceneChange = true;
window.Init();
window.position = rtWindow;
window.Show();
}
2.绘图
private string[] spellAreaArr = new string[] { "4:5", "5:6", "6:7", "7:8", "8:9", "9:10" };
private int spellIndex = 0;
private void OnGUI()
{
//绘制窗口分区域用
// 下拉菜单
spellIndex = EditorGUILayout.Popup(spellIndex, spellAreaArr );
//文件区窗口
Rect rtFileWindow = new Rect(0, 0, partSize * 2, rtWindow.height);
//操作区窗口
Rect rtOperatorWindow = new Rect(rtViewWindow.x + rtViewWindow.width, 0, partSize * 4, partSize * 6);
window.BeginWindows();
rtFileWindow = GUILayout.Window(1, rtFileWindow, CreateFileWindow, "文件区");
rtOperatorWindow = GUILayout.Window(3, rtMonsterWindow, CreateOperatorWindow, "操作区");
window.EndWindows();
}
private void CreateFileWindow(int windowID)
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("保存"))
{
MapDataManager.Instance.ToJson(paramList);
AssetDatabase.Refresh();
}
EditorGUILayout.EndHorizontal();
isShowFileList = EditorGUILayout.Foldout(isShowFileList,"地图列表");
if(isShowFileList)
{
fileScroll = EditorGUILayout.BeginScrollView(fileScroll);
List
for (int i = 0; i < rangeParamList.Count; i++)
{
string name = "空";
Record_Stage stage = MapDataManager.Instance.GetStage(paramList[i].id);
if(null != stage)
{
name = stage.stageName;
}
nameList.Add(paramList[i].id + "_" + name);
}
selectFileIndex = GUILayout.SelectionGrid(selectFileIndex, nameList.ToArray(), 1);
EditorGUILayout.EndScrollView();
}
}
private void CreateOperatorWindow(int windowID)
{
if(true)
{
EditorGUILayout.BeginHorizontal();
//输入文字
EditorGUILayout.LabelField("总数量区间:", GUILayout.MaxWidth(partSize));
//输入文字
rspData.minNum = EditorGUILayout.IntField(rspData.minNum);
EditorGUILayout.LabelField("~", GUILayout.MaxWidth(partSize * 0.25f));
rspData.maxNum = EditorGUILayout.IntField(rspData.maxNum);
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.BeginHorizontal();
EditorGUILayout.EndHorizontal();
}
AssetDatabase.Refresh();
EditorUtility.DisplayDialog编辑器弹提示
GUILayout的使用在圣典里有http://www.manew.com/youxizz/1312.html