AssetDatabase.CreateAsset 新建资源

static function CreateAsset (asset : Object, path : string) : void


Creates a new asset at path.


You must ensure that the path uses a supported extension ('.mat' for materials, '.cubemap' for cubemaps, '.GUISkin' for skins, '.anim' for animations and '.asset' for arbitrary other assets.)

你必须保证使用的路径是一个被支持的扩展('.mat' 代表 materials, '.cubemap' 代表 cubemaps, '.GUISkin' 代表 skins, '.anim' 代表 animations and '.asset' 代表任意其他的资源文件。)

You can add more assets to the file using AssetDatabase.AddObjectToAsset after the asset has been created. If an asset already exists at path it will be deleted prior to creating a new asset. All paths are relative to the project folder. Like: "Assets/MyTextures/hello.png"

当资源被创建后,你可以使用AssetDatabase.AddObjectToAsset把更多的资源添加到文件。如果资源已经存在于指定路径,那么这将会删除原有的资源并新建。所有的路径都是相对于工程目录文件。例如” Assets/MyTextures/hello.png”。

@MenuItem("GameObject/Create Material")
static function CreateMaterial () {
	// Create a simple material asset
	var material = new Material (Shader.Find("Specular"));
	AssetDatabase.CreateAsset(material, "Assets/MyMaterial.mat");

	// Print the path of the created asset
Page last updated: 2011-5-31