通用文件夹使用要求
Editor文件夹
由于unity是分别编译的,会生成不同的dll文件,比如: Assembly-CSharp.dll,Assembly-CSharp-Editor.dll,所以通常要把编辑器相关代码写到Editor名字命名的文件夹下。
比如
Assets/Editor
Assets/MyFolder/Scripts/Editor
Assets/Standard Assets/Editor
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
}
}
Editor Default Resources
类似Resources文件夹,提供给EditorGUIUtility.Load
调用
var tex = EditorGUIUtility.Load ("logo.png") as Texture;
内置资源
编辑器默认的资源文件可由EditorGUIUtility.GetEditorAssetBundle
获取
[InitializeOnLoadMethod]
static void GetBultinAssetNames ()
{
var flags = BindingFlags.Static | BindingFlags.NonPublic;
var info = typeof(EditorGUIUtility).GetMethod ("GetEditorAssetBundle", flags);
var bundle = info.Invoke (null, new object[0]) as AssetBundle;
foreach (var n in bundle.GetAllAssetNames()) {
Debug.Log (n);
}
}