【Unity3d编辑器从入门到精通】文件夹的使用

通用文件夹使用要求

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调用

Editor Default Resources.png

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);
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容