UnityEditorUnity编辑器开发分享unity修炼之路

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

2017-08-23  本文已影响48人  霸俊流年

通用文件夹使用要求

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);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读