unity3D技术之AssetDatabase.CreateAsset 新建资源
- 格式:docx
- 大小:13.29 KB
- 文档页数:2
一、Unity基础本部分是你开始Unity的关键。
这里将解释Unity的界面,菜单项,使用资源,创建场景,和发布。
当你完全阅读了该部分后,你将能够理解Unity是如何工作的,以及如何使其更加有效的工作,和如何将简单的游戏放置在一起。
1.(Learning the interface)现在我们开始学习Unity,如果你还没有打开Unity,你可以通过双击位于Application->Unity文件夹中的Unity图标来运行它,当它第一次运行时你将看到如下的场景:Unity运时场,过实,图有很多需要学习的东西,让我们花费点时间来观察理解上述界面。
我们将介绍每一个接口元素。
概要主窗口的每一个部分都被称为视图(View)。
在Unity中有多种类型的视图,但是,你不需要同时看见所有的视图。
不同的布局模式(Layout modes)包含的视图是不同的。
通过单击布局下拉控件来选择不同的布局,该控件位于窗口的右上角。
选择现在,单击布局选择,并单击Animation,切换到动画布局(Animation layout)。
还可以从菜单中选择Window->Layouts->Animation来切换。
动画布局包含所有的视图,这是昀好的用来介绍它们的方法。
通过视图左上角的名称你可以迅速的分辨这些视图。
这些视图是:场景视图(Scene View)-用于放置物体游戏视图(Game View)-表示游戏在运行时的外观层次视图(Hierarchy)-当前场景中的游戏物体的列表工程视图(Project)-显示当前打开工程中所有可用的物体和资源检视视图(Instpector)-显示当前选中物体的细节和属性时间线(Timeline)-用于为当前选中物体创建基本的时间线动画场景视图(Scene View)场视图场景视图(Scene View)是一个可交互的沙盘。
你将使用它来选择并在场景中定位所有的游戏物体(GameObjects),包括玩家,摄像机,敌人等。
function OnAssignMaterialModel(material: Material, renderer: Renderer) : MaterialDescription描述Feeds a source material获取一个源材质。
[狗刨学习网]The returned material will be assigned to the renderer. If you return null, Unity will use its default material finding / generation method to assign a material. The sourceMaterial is generated directly from the model before importing and will be destroyed immediately after OnAssignMaterial.返回的材质将被赋于渲染器,如果返回null,Unity将使用缺省材质查找/生成方法来分配材质。
sourceMaterial在模型导入并在销毁前,OnAssignMaterial之后直接从模型生成。
1.class MyMeshPostprocessor extends AssetPostprocessor {2.3. function OnAssignMaterialModel (material : Material , renderer :Renderer ) : Material4. {5. var materialPath = "Assets/" + + ".mat";6.7. // Find if there is a material at the material path8. // Turn this off to always regeneration materials9. // 根据路径查找是否有材质,关闭后自动生成材质10.if ( AssetDatabase.LoadAssetAtPath (materialPath,typeof( Material )))11. return AssetDatabase.LoadAssetAtPath (materialPath,typeof( Material ));12.13. // Create a new material asset using the specular shader14. // but otherwise the default values from the model15. // 用特定着色器创建新材质资源,否则使用默认值16. material.shader = Shader.Find ("Specular");17. AssetDatabase.CreateAsset (material, "Assets/" + + ".mat");18. return material;19. }20.}复制代码。
assetdatabase.getassetpath用法摘要:1.assetdatabase.getassetpath 用法概述2.assetdatabase.getassetpath 的作用3.assetdatabase.getassetpath 的语法4.assetdatabase.getassetpath 的参数5.assetdatabase.getassetpath 的返回值6.assetdatabase.getassetpath 的示例7.assetdatabase.getassetpath 的注意事项正文:一、assetdatabase.getassetpath 用法概述assetdatabase.getassetpath 是Unity 游戏引擎中AssetDatabase 类的一个方法,用于获取指定资产(Asset)的完整路径。
这个方法在开发过程中,特别是在处理资源管理和加载方面非常有用。
二、assetdatabase.getassetpath 的作用assetdatabase.getassetpath 主要用于获取AssetDatabase 中某个资产的完整路径,方便开发者对其进行操作,如读取、修改、删除等。
三、assetdatabase.getassetpath 的语法```csharppublic string getassetpath(Asset asset)```四、assetdatabase.getassetpath 的参数- asset:需要获取其完整路径的资产对象。
五、assetdatabase.getassetpath 的返回值该方法返回一个字符串类型(string)的资产完整路径。
六、assetdatabase.getassetpath 的示例下面是一个使用assetdatabase.getassetpath 的示例:```csharp// 创建一个新的纹理Texture2D newTexture = new Texture2D (1, 1);// 将新创建的纹理保存到AssetDatabase 中AssetDatabase.AddAsset(newTexture, "New Texture");// 获取新创建纹理的完整路径string texturePath = AssetDatabase.getassetpath(newTexture);Debug.Log("Texture path: " + texturePath);```七、assetdatabase.getassetpath 的注意事项在使用assetdatabase.getassetpath 时,请确保所提供的资产对象是有效的。
unity 3d入门教程本节我们将介绍如何入门使用Unity 3D。
Unity 3D是一款非常强大的游戏开发引擎,可以用于开发2D和3D的游戏。
1. 获取Unity要开始使用Unity 3D,你首先需要下载并安装Unity。
你可以在Unity官方网站上免费下载Unity的最新版本。
根据你的操作系统选择相应的下载版本,并按照安装向导一步一步安装。
2. 创建新项目打开Unity 3D,并点击"New Project"按钮来创建一个新的项目。
输入项目名称和存储路径,并选择适当的模板。
Unity提供了许多预设的模板,你可以选择基于你的游戏类型来选择适合的模板。
点击"Create"按钮创建新项目。
3. 探索Unity界面一旦项目创建成功,你将看到Unity的编辑界面。
Unity界面由多个窗口组成,包括场景视图、游戏视图、项目视图、检视器视图等等。
你可以根据你的需要调整窗口的布局,以便更方便地开发游戏。
4. 添加游戏对象在Unity中,所有的游戏对象都是通过层次结构组织的。
在项目视图中,你可以创建新的游戏对象,例如角色、环境、道具等等。
选择一个游戏对象并将其拖放到场景视图中,你就可以在场景中看到该对象了。
5. 设置游戏对象属性通过选择游戏对象并在检视器视图中修改其属性,你可以设置游戏对象的位置、旋转和缩放等属性。
你还可以为游戏对象添加组件,例如碰撞器、脚本等等,以便实现更多的功能。
6. 编写脚本Unity使用C#作为主要的脚本语言。
你可以在Unity中创建和编辑C#脚本文件,并将其附加到游戏对象上。
通过编写脚本,你可以控制游戏对象的行为、实现游戏逻辑等等。
7. 运行游戏在编辑场景视图中,你可以通过点击Unity界面的"Play"按钮来运行游戏。
你可以通过游戏视图来观察游戏的实时运行效果,并进行交互。
这是入门使用Unity 3D的基本步骤。
希望本教程对你有所帮助,并祝你在Unity 3D的学习和开发中取得成功!。
unity根据顶点生成模型的方法Unity是一款强大的游戏开发引擎,它提供了丰富的工具和功能,使开发者能够轻松创建各种类型的游戏。
其中,Unity可以根据顶点生成模型,为开发者提供了更多的创作可能性。
本文将介绍Unity中根据顶点生成模型的方法,帮助开发者更好地理解和应用这一功能。
在Unity中,顶点是构成三维模型的基本单元。
通过调整顶点的位置和属性,可以创建出各种形状和效果的模型。
根据顶点生成模型的方法主要有两种:通过代码生成和通过3D建模软件导入。
我们来看通过代码生成模型的方法。
在Unity中,可以使用C#脚本来动态生成模型,具体步骤如下:1. 创建一个空物体作为模型的容器。
在Unity的层次面板中,右键点击空白处,选择“Create Empty”创建一个空物体。
2. 添加一个MeshFilter组件。
选中空物体,在Inspector面板中点击“Add Component”按钮,搜索并添加“Mesh Filter”组件。
这个组件用于存储模型的顶点数据。
3. 添加一个MeshRenderer组件。
同样地,在Inspector面板中点击“Add Component”按钮,搜索并添加“Mesh Renderer”组件。
这个组件用于渲染模型。
4. 创建一个Mesh对象并设置顶点数据。
在脚本中使用Mesh类来创建一个Mesh对象,并根据需要设置顶点的位置、颜色等属性。
5. 更新Mesh对象。
在脚本中调用Mesh类的方法,将更新后的顶点数据应用到Mesh对象上。
6. 将Mesh对象赋值给MeshFilter组件。
在脚本中将创建并更新后的Mesh对象赋值给MeshFilter组件的mesh属性。
7. 完成模型的生成。
运行游戏,即可看到根据顶点生成的模型。
通过上述步骤,开发者可以通过代码自定义生成模型的形状和属性,实现更加个性化的游戏效果。
除了通过代码生成模型,开发者还可以使用3D建模软件来制作模型,并导入到Unity中。
如何使用Unity创建游戏场景和角色一、介绍Unity引擎Unity引擎是目前最流行的跨平台游戏开发引擎之一,可用于创建2D和3D游戏。
Unity以其简单易用的界面和强大的功能而受到广大游戏开发者的欢迎。
本文将介绍如何使用Unity创建游戏场景和角色。
二、创建游戏场景1. 新建场景:打开Unity后,点击"File",然后选择"New Scene",将会创建一个空白的场景。
2. 导入资源:在游戏场景中,我们希望有一些背景图像、音频和3D模型等资源。
点击"Assets",然后选择"Import New Asset",选择你想导入的资源文件。
Unity支持众多类型的文件格式,如.png、.jpg、.mp3和.obj等。
3. 设计场景布局:拖拽导入的资源文件到场景视图中,以构建你希望的场景布局。
可以调整资源的大小、位置和旋转等属性。
4. 添加灯光:在游戏场景中,灯光是非常重要的元素,可以为场景增加真实感。
点击"Game Object",然后选择"Light",从中选择合适的灯光类型,如平行光、点光源或聚光灯。
5. 设置相机:相机决定了玩家在游戏中所看到的视角。
在场景中创建一个相机对象,并设置其位置和旋转。
为了获得更好的游戏体验,可以调整相机的背景颜色和视野范围。
6. 设计地形:Unity提供了强大的地形编辑器,可以帮助开发者轻松创建山脉、平原或河流等游戏地形。
点击"Terrain",然后选择"Create Terrain",即可开始创建地形。
7. 添加特效:特效可以为游戏场景增加动态效果。
点击"GameObject",然后选择"Particle System",可以添加火焰、烟雾或雨等特效。
三、创建游戏角色1. 导入角色模型:与导入场景资源类似,点击"Assets",然后选择"Import New Asset",将角色模型文件导入Unity。
unity3D技术之AssetDatabase.CreateAsset新建资源AssetDatabase.CreateAsset 新建资源static function CreateAsset (asset : Object, path : string) : voidDescription描述[狗刨学习⽹]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把更多的资源添加到⽂件。
unity3d导入资源工作流程Alcohol1982原创翻译,不对之处敬请指出。
Asset Workflow(资源工作流程)Here we'll explain the steps to use a single asset with Unity. These steps are general and are meant only as an overview for basic actions. For the example, we'll talk about using a 3D mesh.这里我们将介绍unity中使用一个asset的步骤。
这些步骤是一个基本行为的常规、必须步骤。
例如:我们将说说使用3D mesh。
Create Rough Asset(建立一个草图资源)Use any supported 3D modeling package to create a rough version of your asset. Our example will use Maya. Work with the asset until you are ready to save. For a list of applications that are supported by Unity, please see this page.使用支持的3D建模软件创建你的基础资源,我们将使用Maya,直到你做好基础资源并且保存。
这个列表中的软件都是被unity支持的。
Import(导入)When you save your asset initially, you should save it normally to the Assets folder in your Project folder. When you open the Unity project, the asset will be detected and imported into the project. When you look in the Project View, you'll see the asset located there, right where you saved it. Please note that Unity uses the FBX exporter provided by your modeling package to convert your models to the FBX file format. You will need to have the FBX exporter of your modeling package available for Unity to use. Alternatively, you can directly export as FBX from your application and save in the Projects folder. For a list of applications that are supported by Unity, please see this page.首先,当你保存了你做好的资源(模型),你需要把它保存在项目文件夹下的assest文件夹里。
Unity Manual > User Guide > Asset Import and CreationAsset Import and Creation(资源导入与创建)A large part of making a game is utilizing your asset source files in your GameObjects. This goes for textures, models, sound effects and behaviour scripts. Using the Project View inside Unity, you have quick access to all the files that make up your game:做一个游戏的很大一部分是在你的游戏对象中使用资源源文件,比如纹理、模型、声音效果和行为脚本。
使用Unity中的项目视图,你可以快速存取所有文件来构建你的游戏:The Project View displays all source files and created Prefabs项目视图显示所有源文件和创建的预设This view shows the organization of files in your project's Assets folder. Whenever you update one of your asset files, the changes are immediately reflected in your game!这个视图显示了在你的项目资源文件夹中的文件组织结构。
每当你更新一个你的资源文件,更改会立即反映在你的游戏中!To import an asset file into your project, move the file into (your Project folder)->Assets in the Finder, and it will automatically be imported into Unity. To apply your assets, simply drag the asset file from the Project View window into the Hierarchy or Scene View. If the asset is meant to be applied to another object, drag the asset over the object.要导入资源文件到你的项目中,在探测器中移动文件到(你的项目文件夹)- > Assets文件夹,它会自动导入到Unity中。
AssetDatabase.CreateAsset 新建资源
static function CreateAsset (asset : Object, path : string) : void
Description描述[狗刨学习网]
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”。
1.MenuItem("GameObject/Create Material")
2.static function CreateMaterial () {
3. // Create a simple material asset
4. //新建一个简单的材质资源
5. var material = new Material (Shader.Find("Specular"));
6. AssetDatabase.CreateAsset(material,
"Assets/MyMaterial.mat");
7.
8. // Print the path of the created asset
9. //打印新建资源的路径
10. Debug.Log(AssetDatabase.GetAssetPath(material));
11.}
复制代码。