Unity Editor扩展入门(1)
1.1 Editor文件夹
- Editor文件夹是一个特别的文件夹,专门为了Editor API的使用而存在。
- 一般来说,Editor API是不能够在Runtime的时候生效的。
- 在Assets文件夹下直接生成下面的这段代码,然后试一下在Build Settings窗口中进行Build。
没有Editor文件夹时的执行方法
- 在Runtime时需要执行的脚本有时候会包含Editor API。
- 这个场合下需要使用#define。
- UnityEditor上已经有UNITY_EDITOR的宏定义。
- Build的时候,脚本编译是没有UNITY_EDITOR的定义的。
- 因此#if UNITY_EDITOR中包含的代码将会被去除。
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class NewBehaviourScript : MonoBehaviour
{
void OnEnable ()
{
#if UNITY_EDITOR
EditorWindow.GetWindow<ExampleWindow> ();
#endif
}
}
1.2 Editor Default Resources文件夹
- 和”Resources”文件夹类似,这个文件夹是存放Editor技能扩展中所使用的资源文件。
- ”Editor Default Resources“文件夹中存放的Asset可以使用EditorGUIUtility.Load进行访问。
var tex = EditorGUIUtility.Load ("logo.png") as Texture;