Unity 中 Prefab(預製體)的建立工具

2021-09-29 23:35:38 字數 783 閱讀 4877

很多時候會用到 prefab,因為這個的確使用方便,廢話不多說,直接上**(放置在editor目錄中):

using unityengine;

using unityeditor;

using system;

using unityeditor.scenemanagement;

using system.io;

namespace prefabsbuilder

//新增選單欄用於開啟視窗

[menuitem("mytools/prefabs build")]

static void showwindow()

void ongui()

m_outputname = editorguilayout.textarea(m_outputname, guilayout.maxheight(16));

guilayout.endhorizontal();

editorguilayout.space();

//新增名為"build"按鈕,用於呼叫build()函式

if (guilayout.button("build"))

guilayout.endvertical();

}//用於儲存當前資訊

void build()

tryif (issuccessed)

else

}catch(exception e)

}}//end class

}//end namespace

批量製作 預製物體Prefab

有時候場景中一大批物體都需要製作成預製物體,但是unity只能手動乙個乙個的建立,感覺非常的蹩腳,下面乙個編輯器類的方法解決你的麻煩。檢視文字列印 static object createprefab gameobject go,string name 這個方法可以隨意根據任何規則來寫,比如可以遍歷...

Unity設定Prefab中children的變數

已有結構 prefab p gameobject a script aaa id title.gameobbject b 目的 建立乙個prefab的clone並設定aaa的屬性id 實現 gameobject tmp gameobject gameobject.instantiate p,some...

Unity小功能分享 預製體庫

在平時開發的時候經常會用到預製體,還會結合resources在執行時載入預製體,不過使用resources的方式會把所有放在resources目錄下的東西都打包到build的程式包中,這樣就會把測試的內容也打包進去,而且resources資料夾可以在assets的任意子目錄中不方便管理,這並不是我們...