Unity 添加自定義菜單(插件),添加功能


網上介紹如何寫這種插件的文章很多。。。但是對於新手來說,最基本的,怎么運行這個插件,都不知道。。。網上的文章都懶得說這個。。。
 
幸好,看了半天官方網站別的資料,突然就發現辦法了。。。
 
這個不是放到Unity的安裝目錄,而是放到工程目錄中。
 
在Project視圖里,新建一個Editor目錄,注意大小寫。然后在里邊添加一個C#腳本,文件名和類名一致。
然后寫代碼,不用重啟unity,每次切換回來,它會自動檢測,語法ok了,就自動刷新菜單了。
 
 
例如在腳本里邊添加:
 
using UnityEngine;
using UnityEditor;

public class ExportAssetBundles {
    [MenuItem("Custom/Build AssetBundle")]
        static void ExportResource () {
            string path = "Assets/myAssetBundle.unity3d";
            Object[] selection =  Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
        }
}
 
菜單里就會有這個玩意了。。。
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM