美文网首页UnityEditorUnity编辑器开发分享unity修炼之路
【Unity3d编辑器从入门到精通】文件夹的使用

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

作者: 霸俊流年 | 来源:发表于2017-08-23 17:15 被阅读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);
    }
}

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/zovcdxtx.html