如何选择家用打印机的打印机 选哪种好

Unity3D 每次打包生成的AssetBundle Hash都不一样的原因 - 兜里
作者:切梦刀
热度:8044℃
用Unity3D做游戏开发,基本都会涉及到资源版本管理及更新,下面是做的过程中遇到的一小问题,记录一下以供参考。
而常用于标记资源版本的方法有计算文件Hash、VCS的版本等,进行文件Hash计算时发现同一个资源文件每次打包成AssetBundle后Hash都不一样,这不科学啊,这样基本是废了用Hash作版本标记的方法。
查了查资料,发现AssetBuildPipeline.BuildAssetBundle接口options参数,可以增加一项BuildAssetBundleOptions.DeterministicAssetBundle。这将保证AssetBundle使用唯一Hash进行标识,若不加这个参数AssetBundle每次构建时都生成不同ID
添加新评论
:有用~~,谢谢
:如何让svn diff命令输出英文而不是中文,比如工作空间输出为 wo...
:使用 file:///即可~
:也可以,但得重新设置导致引擎中的模型Scale Factor值
:设置成厘米,在引擎里显示0.01,就是缩小了100倍。MAX里按米导出...
:已经免费了,去官网下载
:为什么输入了key中内容还是显示Invalid License并且无法...前面我们研究了AssetBundle的打包与加载,现在我们来了解下如何在项目中根据版本号更新内容。
最最重要的一点,细心的朋友应该看到了在加载AssetBundle的MrcAssetManager类中,我们使用的WWW加载对象可以使用WWW.LoadFromCacheOrDownload方法,其中第一个参数是资源的url,第二个参数则是我们的要加载的版本号,我们将通过这个版本号决定是不是要重新从服务器上下载。因此,我们需要在本地和服务器上分别建立一个版本配置文件,里面包含了版本号、资源大小、更新时间、内容等一系列信息,至于存储方式可以是XML、JSON等合适你的格式,这里我用XML讲解。我们可以建立版本控制类VersionManager,在游戏开始时,读取本地的版本号并下载服务器的版本信息。读取本地版本信息:
1 private int GetLocalVersion()
Debug.Log(path);
if (!File.Exists(path))
XmlDocument doc = new XmlDocument();
XmlElement version = doc.CreateElement("version");
version.InnerText = "1";
doc.AppendChild(version);
doc.Save(path);
Debug.Log("created xmlVersion successfully!");
XmlDocument docRead = new XmlDocument();
docRead.Load(path);
XmlElement versionRead = docRead.SelectSingleNode("version") as XmlE
return int.Parse(versionRead.InnerText);
下载读取服务器的版本信息,如果不一致更新本地资源和版本信息:
1 private void CheckVersion()
string url = "http://.../UnityFiles/AssetBundlesForBlog/LOUnityAssetversion.xml";
StartCoroutine(GetServerVersion(url));
private IEnumerator GetServerVersion(string url)
WWW www = new WWW(url);
yield return
XmlDocument doc = new XmlDocument();
doc.InnerXml = www.
XmlElement version = doc.SelectSingleNode("version") as XmlE
ServerVersion = int.Parse(version.InnerText);
LocalVersion = GetLocalVersion();
if (LocalVersion & ServerVersion)
Debug.Log("need update");
//更新本地版本信息
OverrideLocalVersion();
TestScript.DefaultTest.StartLoad();
private void OverrideLocalVersion()
XmlDocument docWrite = new XmlDocument();
docWrite.Load(path);
XmlElement versionWrite = docWrite.SelectSingleNode("version") as XmlE
versionWrite.InnerText = ServerVersion.ToString();
docWrite.Save(path);
最后,将AssetBundle管理类MrCAssetManager中WWW对象的版本号改为使用我们的当前版本号,就可以啦。这样,当我们更新了服务器上的AssetBundle资源后,只要修改下服务器上的版本号,客户端就会因为对比版本不一致而重新下载,而如果一致,就会使用存在本地的AssetBundle资源而不重新下载。
阅读(...) 评论()温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
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 &这样就完成了一套加载。自己完善吧;
阅读(698)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在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}

我要回帖

更多关于 如何选择家用打印机 的文章

 

随机推荐