assetpostprocessor 前端怎么调用后台接口

unity3d API/SDK参考大全,unity3d 使用手册 API之家,最大的中文API社区
当前位置:>API/SDK参考大全>unity3d参考手册
( 21:41:52)AccelerationEvent.acceleration
( 21:41:52)AccelerationEvent.deltaTime
( 21:41:52)AndroidInput
( 21:41:52)AndroidInput.GetSecondaryTouch
( 21:41:52)AndroidInput.secondaryTouchEnabled
( 21:41:52)AndroidInput.secondaryTouchHeight
( 21:41:52)AndroidInput.secondaryTouchWidth
( 21:41:52)AndroidInput.touchCountSecondary
( 21:41:52)AndroidJavaClass
( 21:41:52)AndroidJavaClass.AndroidJavaClass
( 21:41:52)AndroidJavaObject
( 21:41:52)AndroidJavaObject.AndroidJavaObject
( 21:41:52)AndroidJavaObject.Call
( 21:41:52)AndroidJavaObject.Call.ReturnType
( 21:41:52)AndroidJavaObject.CallStatic
( 21:41:52)AndroidJavaObject.CallStatic.ReturnType
( 21:41:52)AndroidJavaObject.Dispose
( 21:41:52)AndroidJavaObject.Get.FieldType
( 21:41:52)AndroidJavaObject.GetRawClass
( 21:41:52)AndroidJavaObject.GetRawObject
( 21:41:52)AndroidJavaObject.GetStatic.FieldType
AnimationState.normalizedTime
AssetPostprocessor.OnPostprocessTexture
BuildPipeline.BuildPlayer
Application.LoadLevelAsync
AssetDatabase.LoadAssetAtPath
Camera.ScreenPointToRay
Application.LoadLevel
Application.persistentDataPath
AssetDatabase.LoadMainAssetAtPath
Collider.OnTriggerStay
Collider.Raycast
AndroidJavaClass.AndroidJavaClass
AudioSource.PlayClipAtPoint
AndroidJavaObject.Call.ReturnType
AssetDatabase.LoadAllAssetsAtPath
最新unity3d API参考
ControllerColliderHit.transform
ControllerColliderHit.rigidbody
ControllerColliderHit.point
ControllerColliderHit.normal
ControllerColliderHit.moveLength
ControllerColliderHit.moveDirection
ControllerColliderHit.gameObject
ControllerColliderHit.controller
ControllerColliderHit.collider
ControllerColliderHit
ContactPoint.thisCollider
ContactPoint.point
ContactPoint.otherCollider
ContactPoint.normal
ContactPoint
责任申明:本站内容均整理自互联网,若有侵权,请联系我们。使用本站提供的任务技术内容造成不良后果,本站不负任何责任。
欢迎投稿,电子邮件:(#号换成@)&& QQ群1: &&自动创建Prefab
本文所属图书&>&
本书以实例教学为主线,循序渐进地介绍了Unity在游戏开发方面的不同功能。第1章,由零开始,引导读者熟悉Unity编辑器的各个功能模块,这部分内容对Unity程序员、美工和策划都有帮助。第2~4章是3个不同特色的3D游&&
经过前面的步骤,我们会发现Unity提供了可视化工具,在编辑器中甚至不用编写代码便可以自由装配Prefab,快速实现游戏中需要的某些功能。但这种方式也有缺点,当一个Prefab比较复杂时,重新装配或修改Prefab需要较多的工作。比如我们要再创建10个敌人,就需要手动重复前面的步骤10次,工作量很大,也容易出错。
实际上,所有在Editor中的手动操作都可以使用代码完成。这样,只需要编写一次代码,很多重复的工作就省掉了。以Enemy2b的Prefab制作为例,我们将完全使用代码来创建它。
首先,我们要编写一个脚本,它的作用是在当模型被导入到Unity工程中时自动将这个模型创建为Prefab。在工程目录内创建一个名为Editor的文件夹,在里面创建脚本ProcessModel.cs。这个脚本是一个编辑器脚本,它在游戏运行时没有作用,只能在Editor文件夹中创建。
编辑脚本ProcessModel.cs,添加using UnityEditor,这样就能使用Unity的编辑器相关API。这里定义的ProcessModel类继承自AssetPostprocessor,它专门用来处理资源导入。OnPostprocessModel方法在导入模型时会被自动调用,其中的参数GameObject即是导入的模型。我们在ProcessModel方法中将Enemy2b.fbx直接制作为一个Prefab,并命名为Enemy2c.Prefab,代码如下:
using UnityE
using UnityE
using System.C
class ProcessModel : AssetPostprocessor
& & void OnPostprocessModel( GameObject input )
& & & & // 只处理名为&Enemy2b&的模型
& & & & if (!input.name.Contains(&Enemy2b&))
& & & & & &
& & & & // 设置导入模型的tag
& & & & input.tag = &Enemy&;
& & & & // 查找碰撞模型
& & & & foreach (Transform obj in input.GetComponentsInChildren&Transform&())
& & & & & & if (pareTo(&col&) == 0)
& & & & & & {
& & & & & & & & // 取消碰撞模型的显示
& & & & & & & & MeshRenderer r = obj.GetComponent&MeshRenderer&();
& & & & & & & & r.enabled =
& & & & & & & & // 添加Mesh碰撞体
& & & & & & & & obj.gameObject.AddComponent&MeshCollider&();
& & & & & & & & // 设置碰撞体的tag
& & & & & & & & obj.tag = &Enemy&;
& & & & & & }
& & & & // 设置刚体
& & & & Rigidbody rigid = input.AddComponent&Rigidbody&();
& & & & rigid.useGravity =
& & & & rigid.isKinematic =
& & & & // 取得导入模型的相关信息
& & & & ModelImporter importer = assetImporter as ModelI
& & & & // 从工程中将该模型读出来
& & & & GameObject tar =(GameObject)AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(GameObject));
& & & & // 将这个模型创建为Prefab
& & & & GameObject prefab = (GameObject)PrefabUtility.CreatePrefab
(&Assets/Prefabs/Enemy2c.Prefab&, tar );
& & & & // 为Prefab添加声音
& & & & prefab.AddComponent&AudioSource&();
& & & & &// 获得子弹的Prefab
& & & & GameObject rocket =(GameObject)AssetDatabase.LoadAssetAtPath
(&Assets/Prefabs/EnemyRocket.Prefab&, typeof(GameObject));
& & & & // 获得爆炸效果的Prefab
& & & & GameObject fx =(GameObject)AssetDatabase.LoadAssetAtPath
(&Assets/FX/Explosion.Prefab&, typeof(GameObject));
& & & & // 为Prefab添加脚本
& & & & SuperEnemy enemy=Prefab.AddComponent&SuperEnemy&();
& & & & // 设置脚本的默认参数
& & & & enemy.m_life = 50;
& & & & enemy.m_point = 50;
& & & & enemy.m_rocket= rocket.
& & & & enemy.m_explosionFX = fx.
重新导入Enemy2b.fbx,ProcessModel.cs会被自动调用,并自动创建Enemy2c.Prefab,它的所有功能和设置均与前面手工设置的Prefab相同。
您对本文章有什么意见或着疑问吗?请到您的关注和建议是我们前行的参考和动力&&
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
您的浏览器不支持嵌入式框架,或者当前配置为不显示嵌入式框架。
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'Unity3D(30)
下面是按顺序写的:
if (GUI.Button(new Rect(0, 150, position.width, 30), "SetTexture"))
Object[] textures = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
for (int i = 0; i & textures.L i++)
string path = AssetDatabase.GetAssetPath(textures[i]);
TextureImporter import = AssetImporter.GetAtPath(path) as TextureI
import.textureType = TextureImporterType.A
import.npotScale = TextureImporterNPOTScale.ToN
import.generateCubemap = TextureImporterGenerateCubemap.N
import.isReadable =
import.normalmap =
import.grayscaleToAlpha =
import.alphaIsTransparency =
import.linearTexture =
import.spriteImportMode = SpriteImportMode.N
import.mipmapEnabled =
import.wrapMode = TextureWrapMode.C
import.filterMode = FilterMode.B
import.anisoLevel = 2;
import.compressionQuality = (int)TextureCompressionQuality.N
import.SetPlatformTextureSettings("Standalone", 1024, TextureImporterFormat.AutomaticCompressed);
import.SetPlatformTextureSettings("iPhone", 1024, TextureImporterFormat.AutomaticCompressed, 1);
import.SetPlatformTextureSettings("Android", 1024, TextureImporterFormat.ETC2_RGBA8, 2);
AssetDatabase.ImportAsset(path);
上面是通过按钮把自己所选择的那些贴图进行设置,我们也可以重新导入这些贴图的时候进行自动设置(任何被导入的贴图都会自动设置),AssetPostprocessor这个类提供了当贴图,模型,动画,音频等在导入前后Unity调用的方法。
以在贴图导入前自动进行设置为例:
public class MyImportEditor : AssetPostprocessor {
public void OnPreprocessTexture() {
TextureImporter import = assetImporter as TextureI
import.textureType = TextureImporterType.A
import.SetPlatformTextureSettings("Android", 1024, TextureImporterFormat.ETC2_RGBA8, 2);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:33802次
排名:千里之外
原创:48篇
转载:40篇
(1)(2)(1)(3)(3)(3)(1)(1)(2)(1)(4)(4)(2)(2)(5)(5)(7)(10)(10)(11)(1)(2)(1)AssetBundle官方文档(3. 在Unity 5.X中创建AssetBundle) - 简书
下载简书移动应用
写了12242字,被14人关注,获得了3个喜欢
AssetBundle官方文档(3. 在Unity 5.X中创建AssetBundle)
Authoring AssetBundles
在Unity 4.x版本中,创建AssetBundle的过程是用脚本实现的。为了简化这个过程,在Unity5.x版本中包括AssetBundle创建工具。现在只需要在编辑器中选择Asset文件,在Inspector最下面就会出现一个选项,让你选择这个文件是否需要打包成AssetBundle。如果AssetBundle选项默认设置成为None,代表这个Asset文件不会被被打包成AssetBundle文件。可以创建新的AssetBundle,创建新的名字,并将这些名字作为Asset打包的目标地址。
选中编辑器中的Asset文件,会在Inspector下面出现选项
在上面的图片中,状态机Asset被添加到了scene1/animdata。这个AssetBundle可能会包含了之前被添加的其他Asset文件。 空的AssetBundle可以使用菜单选项中的"New"选项创建。当你创建了一个新的AssetBundle文件之后,它就会出现在添加列表中。AssetBundle的名字都是小写的,使用包含了大写字母的名字也会被转化成为小写。名字中包含分隔符“/”会自动创建文件夹,选中也会出现二级菜单(如上图所示)。 如果你创建了AssetBundle,但是未指定任何Asset文件,那么可以使用“Remove Unused Names”来删除空AssetBundle文件。Asset文件的.meta文件也会被写入选择的AssetBundle文件。
输出AssetBundle文件
AssetBundle文件是通过脚本输出。(和Unity 4.x相似)下面的脚本展示了如何输出:
using UnityE
public class CreateAssetBundles
[MenuItem ("Assets/Build AssetBundles")]
static void BuildAllAssetBundles ()
BuildPipeline.BuildAssetBundles ("AssetBundles");
上面的代码在Assets目录下创建了一个"Build AssetBundles"选项。当选择这个选项后,AssetBundles文件会被创建。这会创建一个带有进度条的创建对话框。BuildPipeLine.BuildAssetBundles将AssetBundle创建到一个“AssetBundles”的文件夹。这个文件夹必须在调用之前创建。AssetBundle将会被创建在这个文件夹内。每个输出的AssetBundle文件都会出现在AssetBundle菜单中。另外,每个AssetBundle文件都会有一个关联文件.manifest。这个manifest文件是文本类型,可以使用文本编辑器打开。这个文件提供了CRC和asset依赖的相关信息。下面是一个.manifest文件的例子:
ManifestFileVersion: 0
AssetFileHash:
serializedVersion: 2
Hash: 8b6db55aa9be0a662ba15
TypeTreeHash:
serializedVersion: 2
Hash: 37ad974993dbaa7c38f347a
HashAppended: 0
ClassTypes:
- Class: 91
Script: {instanceID: 0}
Asset_0: Assets/Mecanim/StateMachine.controller
Dependencies: {}
除了创建这两个文件,还有另外两个文件会被创建:另外一个AssetBundle和另外一个manifest文件。这两个文件只要任何AssetBundle被创建的时候都会被创建。这两个文件是为了放置AssetBundles的文件夹创建,所以你如果一直把AssetBundle放在同一个文件夹,只会得到两个额外的文件。额外的文件不仅会包含其他的manifest的信息,还会包含AssetBundle之间的引用关系。 在上面的例子中,因为我们只创建了一个AssetBundle文件,所以没有其他依赖关系。
ManifestFileVersion: 0
AssetBundleManifest:
AssetBundleInfos:
Name: scene1assetbundle
Dependencies: {}
AssetBundle编辑器工具
得到AssetBundle的名字
下面的脚本可以显示所以可以创建的AssetBundle的名字
using UnityE
using UnityE
public class GetAssetBundleNames
[MenuItem ("Assets/Get AssetBundle names")]
static void GetNames ()
var names = AssetDatabase.GetAllAssetBundleNames();
foreach (var name in names)
Debug.Log ("AssetBundle: " + name);
当重新打包文件改变了AssetBundle文件
你可以使用AssetPostprocessor类中的方法,当AssetBundle发生改变的时候得到回调函数。
using UnityE
using UnityE
public class GetAssetBundleNames
[MenuItem ("Assets/Get AssetBundle names")]
static void GetNames ()
var names = AssetDatabase.GetAllAssetBundleNames();
foreach (var name in names)
Debug.Log ("AssetBundle: " + name);
AssetBundle Variants
AssetBundle Variants 是Unity5.x新的特性。可以使用这个特性达到和虚拟的Assets类似的效果。例如,你可以创建AssetBundle的变体例如“MyAssets.hd”或者“MyAsset.sd”。确保这些文件精确匹配。这两个AssetBundle的变体文件拥有相同的内部ID,在Unity创建管道中使用。这两个AssetBundle在运行的过程中可以通过不同的后缀确定。 如何设立AssetBundle variants?
在编辑器中,在右边的标签中加上后缀名;
在代码中使用AssetImporter.assetBundleVariant选项。
AssetBundle variants
完整的AssetBundle的名字将由AssetBundle的名字和variant的名字共同确定。例如,如果For example, if you want to add “MyAssets.hd” as a variant AssetBundle,
将asset标记进AssetBundle的API接口
可以使用设置AssetBundle的名字。
简单的APIs
有一些非常简单的API可以用来创建AssetBundle。只需要提供:
AssetBundle的输出路径。
(将会在后面描述)
还有一个重载的版本提供AssetBundleBuild的数组,AssetBundleBuild包括asset与AssetBundle之间的映射关系。提供了更大的便利性,可以使用脚本控制映射关系。而且这个映射关系不会破坏或者代替数据库中已经存在的映射关系。操作asset Database里的AssetBundle名字的API
which returns all the AssetBundle names in the asset database. to return the asset paths marked in the given AssetBundle. which removes a given AssetBundle name in the asset database. which returns the unused AssetBundle names. which removes all the unused AssetBundle names in the asset database. callback which will be called if user change the AssetBundle name of an asset.
BuildAssetBundleOptions
CollectDependencies and DeterministicAssetBundle are always enabled.CompleteAssets is ingored as we always start from assets rather than objects, it should be complete by default.ForceRebuildAssetBundle is added. Even there is no change to the assets, you can force rebuild the AssetBundles by setting this flag.IngoreTypeTreeChanges is added. Even type tree changes, you can ignore the type tree changes with this flag.DisableWriteTypeTree conflicts with IngoreTypeTreeChanges. You can’t ignore type tree changes if you disable type tree.
Manifest fileA manifest file is created for every AssetBundle which contains the following information:The manifest file is next to the AssetBundle.CRCAsset file hash. A single hash for all the assets included in this AssetBundle, only used for incremental build check.Type tree hash. A single hash for all the types included in this AssetBundle, only used for incremental build check.Class types. All the class types included in this AssetBundle. These are used to get the new single hash when doing the type tree incremental build check.Asset names. All the assets explicitly included in this AssetBundle.Dependent AssetBundle names. All the AssetBundles which this AssetBundle depends on.This manifest file is only used for incremental build, not necessary for runtime.
Single manifest fileWe generate a single manifest file which includes:All the AssetBundles.All the AssetBundle dependencies.
Single manifest AssetBundleIt only contains an AssetBundleManifest object which has following APIs:GetAllAssetBundles() which returns all the AssetBundle names in this build.GetDirectDependencies() which returns the direct dependent AssetBundle names.GetAllDependencies() which returns all the dependent AssetBundle names.GetAssetBundleHash(string) which returns the hash for the specified AssetBundle.GetAllAssetBundlesWithVariant() which returns all the AssetBundles with variant.
AssetBundle loading APIs changedNow we have:AssetBundle.GetAllAssetNames(). Return all the asset names in the AssetBundle.AssetBundle.GetAllScenePaths(). Return all the scene asset paths if it’s a streamed scene AssetBundle.AssetBundle.LoadAsset(). Load asset from AssetBundle.AssetBundle.LoadAllAssets().AssetBundle.LoadAssetWithSubAssets().Asynchronous version are also provided.Component type are no longer returned. Instead load the GameObject first and then look up the component(s) on the object.
TypetreesA typetree is written to the AssetBundle by default. The only exception is Metro as it has different serialization solution.
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
被以下专题收入,发现更多相似内容:
Unity3D引擎技术讨论专题
· 447人关注
提供高质量的Unity教程,供大家学习和参考
· 382人关注
无论你是新手,还是老司机。都可以为新生代血液尽一份绵薄之力!
· 68人关注
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:Unity5的AssetBundle系统在mmo中的使用经验
Unity5的AssetBundle系统在mmo中的使用经验
Unity3D开发
先推荐三篇不错的文章
基本上核心的知识点上面的文章都涵盖了,讲述的非常清楚,这里我分享一下我的使用经验。
1、先说一个我遇到的坑,当大量(几百个)AssetBundle加载的时候(可能是WWW加载的时候,也可能是AssetBundle.LoadAsset的时候),Android手机上会闪退。看崩溃log是多线程文件访问的时候崩溃了。解决方法是减少同时加载的AB数量(这个是纯逻辑控制),使用AssetBundle.LoadFromFile接口。
2、打包AssetBundle使用LZ4压缩(BuildPipeline.BuildAssetBundles,第二个参数传递BuildAssetBundleOptions.ChunkBasedCompression),默认是LZMA压缩的,具有最高的压缩比。而替换为LZ4压缩,压缩比没有LZMA高,但是加载速度大幅提高。
& & & 加载AssetBundle使用AssetBundle.LoadFromFile(Async),在Unity4的时候,只能使用WWW的接口来加载AB,因为CreateFromFile不支持压缩的AB。而Unity5的LoadFromFile是支持任意压缩格式的AB的。所以没有太大必要使用WWW了,而且这个接口像WWW.LoadFromCacheOrDownload接口一样,加载不压缩或者LZ4压缩格式的AB的时候是不会有额外的内存开销的。具体关于内存、加载速度的细节可以参考上面第三篇文章里面的介绍。
3、资源规划好一个独立的资源工程。规划好一系列的文件夹,在导入相应资源的时候自动通过AssetImporter设置好AB的名字。监测资源导入可以用AssetPostprocessor
& & & 带动画的模型需要创建好prefab,而不带动画只是用于换装的模型可以直接导出,不需要创建prefab,因为这些模型我们只是取它的mesh数据。
& & & 如果有打包图集,需要注意它和AB的匹配关系,举例来说,如果三张图片指定了同一个图集,而又分别指定了不同的AB名,则三个AB里面都包含了此图集(三张图片),这样就会造成严重的资源浪费。
4、AssetBundle.LoadFromFile接口在Android平台下也是可以直接访问StreamingAssets文件夹里面的内容的。5.4版本可以直接使用Application.streamingAssetsPath。而之前的版本需要使用&Application.dataPath + &!assets/& + fileP
& & & 因为streamingAssetsPath带了jar://,这个是给WWW用的URL路径,而LoadFromFile接口需要的是实际路径(不带jar://也不带file://)。注意 !assets/ 这个地方叹号后面没有/。网上搜索到的各种写法都有,只有这个是正确的,注意此处细节。
我的热门文章
即使是一小步也想与你分享

我要回帖

更多关于 idiskk app 怎么调用 的文章

 

随机推荐