【Unity3d編輯器從入門(mén)到精通】文件夾的使用

通用文件夾使用要求

Editor文件夾

由于unity是分別編譯的,會(huì)生成不同的dll文件,比如: Assembly-CSharp.dll,Assembly-CSharp-Editor.dll,所以通常要把編輯器相關(guān)代碼寫(xiě)到Editor名字命名的文件夾下。
比如

Assets/Editor
Assets/MyFolder/Scripts/Editor
Assets/Standard Assets/Editor

UNITY_EDITOR

#if UNITY_EDITOR
該寫(xiě)法通常用于包裹編輯器腳本:

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調(diào)用

Editor Default Resources.png

var tex = EditorGUIUtility.Load ("logo.png") as Texture;

內(nèi)置資源

編輯器默認(rèn)的資源文件可由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);
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容