Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
AssetDatabase.AddObjectToAsset 添加对象到资源
# [AssetDatabase](AssetDatabase.html).AddObjectToAsset 添加对象到资源 static function *AddObjectToAsset* (*objectToAdd* : [Object](../Object/Object.html), *assetPath* : string) : void *Description* 描述 ### Adds objectToAdd to an existing asset at path. 将 objectToAdd 这个对象添加到指定路径上的现有资源。 Please note that you should only add assets to '.asset' assets, imported models or texture assets for example will lose their data. All paths are relative to the project folder. Like: "Assets/MyTextures/hello.png" 请注意,你应该添加资源到”.assets”目录下的资源中,例如导入的模型或纹理将会丢失它们地数据。所有的路径都是相对于工程目录文件。 例如” 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"); // Add an animation clip to it //添加一个动画剪辑到材质上 var animationClip = new AnimationClip (); animationClip.name = "My Clip"; AssetDatabase.AddObjectToAsset(animationClip, material); // Reimport the asset after adding an object. //在新建一个对象后重新导入资源 // Otherwise the change only shows up when saving the project //否则这个更改只会在保存工程时才显示 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(animationClip)); // Print the path of the created asset //打印新建的资源 Debug.Log(AssetDatabase.GetAssetPath(material)); } ``` • static function *AddObjectToAsset* (*objectToAdd* : [Object](../Object/Object.html), *assetObject* : Object) : void *Description* 描述 Adds objectToAdd to an existing asset identified by assetObject. 将 objectToAdd 这个对象添加到 assertObject 定义的资源上。 Please note that you should only add assets to '.asset' files, imported models or texture assets for example will lose their data when reimporting or quitting Unity. 请注意,你只能添加资源到”.asset”文件中,例如导入模型或纹理在重新导入或退出 Unity 时将会丢失数据。 ``` @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"); // Add an animation clip to it //添加一个动画剪辑到材质上 var animationClip = new AnimationClip (); animationClip.name = "My Clip"; AssetDatabase.AddObjectToAsset(animationClip, material); // Reimport the asset after adding an object. //添加对象后重新导入资源 // Otherwise the change only shows up when saving the project //否则这个更改只会在保存工程时才显示 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(animationClip)); // Print the path of the created asset //打印新建的资源 Debug.Log(AssetDatabase.GetAssetPath(material)); } ```
da
2022年5月14日 12:58
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码