怎么使用Unity5.x1366x768壁纸打包下载与发布Unity3D游戏

礼品网提供商务礼品,创意礼品,小礼品,开业礼品,促销礼品,工艺礼品,广告礼品等礼物礼品定制批发采购服务
市 场 价:190.80 元折 扣 价:142.90 元
所 在 地:上海
店铺掌柜: (点击可查看店铺所有商品)
礼品推荐: [丨]
为您提供礼品包邮 Unity 5.x创造2D手机游戏+ Unity 5.x完全自学手册+Unity5.X游戏开发技术与实例 unity3D游戏开发教程书籍 unity游戏引擎开发的详细介绍,
淘宝售价:元。
礼品网为您提供淘宝网网上热销礼品,让您更快找到热门以及合适自己的礼品,
特别提供礼品的详细参数、介绍以及报价等信息,挑选礼品更方便。
包邮 Unity 5.x创造2D手机游戏+ Unity 5.x完全自学手册+Unity5.X游戏开发技术与实例 unity3D游戏开发教程书籍 unity游戏引擎开发评价
Copyright &
All Rights Reserved.Unity5.x版本AssetBundle打包研究 | 是幻觉
我的图书馆
Unity5.x版本AssetBundle打包研究 | 是幻觉
Unity5的AssetBundle打包机制和以前版本不太一样。简单的说就是,只要给你要打包的资源设置一个AssetBundleName ,Unity自身会对这些设置了名字的资源进行打包,如果一个资源依赖了另一个资源。Unity自己会处理依赖关系,AssetBundleManifest文件就保存着这些资源的依赖关系。
比如一个UI面板.Prefab,依赖了一个图集Atlas,一个字体文件
做个测试:
只给UI面板3.prefab设置AssetBundleName。
打出包来看,别看只有371KB,那是因为我拿得面板不是很复杂,依赖的图集,字体,本身就不是很大。
要是项目中的话,你不处理依赖打包的话,几M都是有的。
要是有其它的UI面板,设置AssetBundleName,打出包,都是这么大的
依赖文件显示资源没依赖,这是因为每一个面板里面都单独打包了一份图集资源,字体资源。显然这是不可取的。
对于同类型的UI面板来说,这些图集和字体文件,大家用的都是同一份,只要打包出一份,大家共享就好了。
接下给图集资源,字体文件都设置AssetBundleName,再进行打包,可以看到变小了。
在看.manifest文件,有了依赖关系。
项目中,资源辣么多,总不能在编辑器里一个一个给资源进行设置AssetBundleName吧,那会蛋疼死的,是吧。
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
/// &summary&
/// 把Resource下的资源打包成.unity3d 到StreamingAssets目录下
/// &/summary&
public class Builder : Editor
public static string sourcePath = Application.dataPath + "/Resources";
const string AssetBundlesOutputPath = "Assets/StreamingAssets";
[MenuItem("Tools/AssetBundle/Build")]
public static void BuildAssetBundle()
ClearAssetBundlesName ();
Pack (sourcePath);
string outputPath = Path.Combine (AssetBundlesOutputPath,Platform.GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget));
if (!Directory.Exists (outputPath))
Directory.CreateDirectory(outputPath);
//根据BuildSetting里面所激活的平台进行打包
BuildPipeline.BuildAssetBundles (outputPath,0,EditorUserBuildSettings.activeBuildTarget);
AssetDatabase.Refresh ();
Debug.Log ("打包完成");
/// &summary&
/// 清除之前设置过的AssetBundleName,避免产生不必要的资源也打包
/// 之前说过,只要设置了AssetBundleName的,都会进行打包,不论在什么目录下
/// &/summary&
static void ClearAssetBundlesName()
int length = AssetDatabase.GetAllAssetBundleNames ().Length;
Debug.Log (length);
string[] oldAssetBundleNames = new string[length];
for (int i = 0; i & length; i++)
oldAssetBundleNames[i] = AssetDatabase.GetAllAssetBundleNames()[i];
for (int j = 0; j & oldAssetBundleNames.Length; j++)
AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j],true);
length = AssetDatabase.GetAllAssetBundleNames ().Length;
Debug.Log (length);
static void Pack(string source)
DirectoryInfo folder = new DirectoryInfo (source);
FileSystemInfo[] files = folder.GetFileSystemInfos ();
int length = files.Length;
for (int i = 0; i & length; i++) {
if(files[i] is DirectoryInfo)
Pack(files[i].FullName);
if(!files[i].Name.EndsWith(".meta"))
file (files[i].FullName);
static void file(string source)
string _source = Replace (source);
string _assetPath = "Assets" + _source.Substring (Application.dataPath.Length);
string _assetPath2 = _source.Substring (Application.dataPath.Length + 1);
//Debug.Log (_assetPath);
//在代码中给资源设置AssetBundleName
AssetImporter assetImporter = AssetImporter.GetAtPath (_assetPath);
string assetName = _assetPath2.Substring (_assetPath2.IndexOf("/") + 1);
assetName = assetName.Replace(Path.GetExtension(assetName),".unity3d");
//Debug.Log (assetName);
assetImporter.assetBundleName = assetName;
static string Replace(string s)
return s.Replace("\\","/");
public class Platform
public static string GetPlatformFolder(BuildTarget target)
switch (target)
case BuildTarget.Android:
return "Android";
case BuildTarget.iOS:
return "IOS";
case BuildTarget.WebPlayer:
return "WebPlayer";
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
return "Windows";
case BuildTarget.StandaloneOSXIntel:
case BuildTarget.StandaloneOSXIntel64:
case BuildTarget.StandaloneOSXUniversal:
return "OSX";
return null;
有了这个包含所有资源的依赖关系的.manifest文件,那么在加载使用一个资源的时候,就要根据这个文件,先去加载这个资源依赖的所有资源,然后再加载这个资源,然后就可以使用啦。加载这块,下次再整理。
代码都在这了,工程我就不上传了。
拜了个拜!
TA的推荐TA的最新馆藏[转]&
喜欢该文的人也喜欢温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
& &打包和原来一样:在Editor下创建.CS脚本
const string outputDir = "Assets/StreamingAssets";
[MenuItem("AssetBundlePre/Build")]
static void BuildAssetResource()
string plat = GetPlat(EditorUserBuildSettings.activeBuildTarget);
string outputPath = bine(outputDir,plat);
Debug.Log(outputPath);
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
BuildPipeline.BuildAssetBundles(outputPath, 0, EditorUserBuildSettings.activeBuildTarget);
static string GetPlat(BuildTarget tag)
switch (tag)
case BuildTarget.Android:
return "Android";
case BuildTarget.StandaloneWindows:
return "Windows";
case BuildTarget.StandaloneWindows64:
return "Windows";
case BuildTarget.iOS:
return "IOS";
return "Windows";
}加载: #region variable
string manisfeas=#if UNITY_ANDROID "Android";#elif UNITY_IPHONE
"IOS";#elif UNITY_STANDALONE_WIN||UNITY_EDITOR
"Windows";#else
"Windows";#endif
public static readonly string PathURL =#if UNITY_ANDROID
"jar:file://"+Application.dataPath+"!/assets/Android/";#elif UNITY_IPHONE
Application.dataPath+"/Raw/IOS/";#elif UNITY_STANDALONE_WIN||UNITY_EDITOR "file://" + Application.streamingAssetsPath + "/Windows/";#else
string.E#endif
Dictionary&string, WWW& DicAllBundle = new Dictionary&string, WWW&();
# endregion这个是按平台获取,貌似写的有点二,不过不要在意这些细节!!WWW加载AssetBundle我这边是先是预加载的Bundle,当然也可以用的时候加载,这个随便,我就随便写下。 void Awake()
StartCoroutine(LoadAssetsInit());
}IEnumerator LoadAssetsInit()
//获得总的Asste
WWW mwww = WWW.LoadFromCacheOrDownload(PathURL + manisfeas, 0);
if (!string.IsNullOrEmpty(mwww.error))
Debug.LogError(mwww.error);
AssetBundle map = mwww.assetB
//拿到AssetBundleManifest
AssetBundleManifest mainifest = (AssetBundleManifest)map.LoadAsset("AssetBundleManifest");
map.Unload(false);
//从总的集合里面寻找要加载的BUNDLE的所有资源名字
string[] allBundelename = mainifest.GetAllAssetBundles();
for (int i = 0; i & allBundelename.L i++)
string dUrl = PathURL + allBundelename[i];
//开大所有资源路径的bundle添加到临时数组内
将所有bundle打开
WWW dwww = WWW.LoadFromCacheOrDownload(dUrl, mainifest.GetAssetBundleHash(allBundelename[i]));
if (!string.IsNullOrEmpty(dwww.error))
Debug.Log(dwww.error);
if (!DicAllBundle.ContainsKey(allBundelename[i]))
DicAllBundle.Add(allBundelename[i], dwww);
好了该加载的先加载好了,下载去拿里面的东西 void Update()
if (Input.GetMouseButtonDown(0))
Load("2.unity3d", "2");
}我是放在Update里面这样方便点。因为我是先加载了WWW public bool Load(string assetBundleName, string assetName)
bool isDone=
StartCoroutine(LoadAsset(assetBundleName, assetName, isDone));
return isD
} IEnumerator LoadAsset(string assetBundleName, string assetName,bool isDone)
while (!IsDone)
yield return 0;
//异步加载需要BUNDLE
if (DicAllBundle.ContainsKey(assetBundleName))
WWW www = DicAllBundle[assetBundleName];
AssetBundle asstbundle = www.assetB
GameObject obj = asstbundle.LoadAsset(assetName) as GameO
if (obj != null)
Instantiate(obj);
asstbundle.Unload(false);
Debug.Log("this assetname is error");
yield return isDone =
//CloseOneBundle(assetBundleName);
}我这边是没有进行关闭的;所有关闭我也是调用的; public
void CloseAllAssetBundle()
List&string& a = new List&string&(DicAllBundle.Keys);
for (int i = 0; i & a.C i++)
if(DicAllBundle[a[i]].assetBundle!=null)
DicAllBundle[a[i]].assetBundle.Unload(false);
public void CloseOneBundle(string assetBundleName)
if (DicAllBundle.ContainsKey(assetBundleName) && DicAllBundle[assetBundleName].assetBundle != null)
DicAllBundle[assetBundleName].assetBundle.Unload(false);
Debug.Log("this assetname is inexistence or this asser is close");
void Clear()
StopAllCoroutines();
}So &这样就完成了一套加载。自己完善吧;
阅读(953)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'Unity_AssetBundle 5.x 打包和加载(简化)',
blogAbstract:'& & 在开始的时候也写过人家的一个加载打包的工具,不过感觉太多了。而且要求也有。所又写了个简单的。& &打包和原来一样:在Editor下创建.CS脚本
const string outputDir = \"Assets/StreamingAssets\";
[MenuItem(\"AssetBundlePre/Build\")]
static void BuildAssetResource()
string plat = GetPlat(EditorUserBuildSettings.activeBuildTarget);
string outputPath = bine(outputDir,plat);
Debug.Log(outputPath);',
blogTag:'unity',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:7,
publishTime:7,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}这里应该注意几点:
1.Player Settings..里面的Bundle Identifier* 必须填写为跟Android工程一致的包名,注意是包名,(若有多个包时)
2.在eclipse中把Anroid工程,先project-&clean一下,再build project(需要去掉build automatically的勾),然后到Android工程目录的bin目录的classes目录,进行把Anroid工程打包成jar包,注意Unity5.x需要把带R的.class全删掉走,不然会出现下面第4点的发布错误,然后可以在cmd下面输入如下指令
jar -cvf 包名 *如图:
导出的包结构
3.导出的jar包要放在Unity项目的Assets/Plugins/Android下面就即可,具体的存放文件结构取决于实际需要
4.如果出现类似下面的错误java.lang.IllegalArgumentException: already added: Lxxx/xxx/R$x;这就意味着你打包android工程包含重复的跟R相关的class,解决方法为第2点
CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
D:/jdk-8u60\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir=&E:/Android-tools/sdk\tools& -Dfile.encoding=UTF8 -jar &F:\Unity3D\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar& -
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R$
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/example/unitytest/R;
9 aborting
这里原Android工程的R相关的class文件不需要放进jar的原因估计是,Unity5会根据res文件下面的各个xml文件与他自身的各种xml一同写入到一个R.java,然后编译成一些与R相关的class文件。(可以查看发布时Unity工程目录下的Temp/StagingArea/gen/包名/R.java)
5.若打包成功,启动却有问题,可能是Android代码部分或者AndroidManifest配置的问题
本文已收录于以下专栏:
相关文章推荐
unity3d-配置sdk,jdk
Android环境,打包发布Apk流程详解
unity 5.x 下载可到unity官网下载:点击打开链接
unity 5.3.5f1的下载器只需要200多M,下载好了只好,启动下载器,它会自动去下载需要的基础组件,还会自动帮我们下载...
1.有童鞋在安装完Unity软件后可能出现在选择平台打包(Android/iOS)的时候没有可打包的选项如下图
这时候有两种解决方法
(1).点击OpenDownloadPage,进去下载然后安装,然...
如果不设置的话
system.data.dll 无法找到 或者无法读取
每个Unity场景都对应有NavMesh和LightMap数据。当使用 SceneManager.LoadScene 的时候,会自动载入LightMap 和 NavMesh的数据。然后再对MeshRe...
CommandInvokationFailure: Unable to list target platforms. Please make sure the android sd...
转自:/p/fe4c334ee9fe
在用 Unity 编译 Android 平台的应用时,遇到 Unable to list target pl...
Unity4.x 项目升级Unity5.0 过程中出现的各种常见问题
Unity5.x AssetBundle依赖项打包详解在这段时间一直在研究AssetBundle,从什么都不懂到今天算是研究透了,特写下这边文章来记录下。并且也给后面的学习者一个学习的机会,让他们少花...
导入《google android开发入门与实战》书中自带的豆瓣网客户端源程序时eclipse出现以下错误:java.lang.IllegalArgumentException: already ad...
他的最新文章
讲师:王哲涵
讲师:韦玮
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 cocos2d x打包ios 的文章

 

随机推荐