checkVersionUpdate
local Http=CS.util.Http; local JsonDataLua=CS.util.JsonDataLua; local LoadFactory=CS.util.LoadFactory; local AssetBundle=CS.UnityEngine.AssetBundle; local PlayerPrefs=CS.UnityEngine.PlayerPrefs; VersionUpdate={}; local this=VersionUpdate; local localVersion=2.0; local version=nil; this.Awake=function() if(PlayerPrefs.HasKey("localVersion")) then localVersion=PlayerPrefs.GetFloat("localVersion"); else PlayerPrefs.SetFloat("localVersion",localVersion); end end this.Start=function() Http.doGet(CS.util.net.IP.ip.."/version.json",this.self,function(str) local json=JsonDataLua.Parse(str); version=json:getDouble("version"); print("当前版本为"..localVersion); if(version==localVersion) then print("当前为最新版本,无需更新"); this.transform.parent:Find("checkVersion"):GetComponent("Text").text="当前为最新版本.."..version..",无需更新"; this.transform.parent:Find("Img_person/Button").gameObject:SetActive(true); else local files=json:getArray("files"); local index=0; updateABundle(index,files); end end ); end function updateABundle(index,files) if(index<files.Length) then local type1=files[index]:getString("type"); local serverDownpath=files[index]:getString("serverDownpath"); local name=files[index]:getString("name"); local ext=files[index]:getString("ext"); local path=CS.util.net.IP.ip.."/"..serverDownpath.."/"..name..ext; print(path); LoadFactory.LoadAsset(path,this.self,function(a,b) print(a); print(b); print("------------"); local clientSavepath=files[index]:getString("clientSavepath"); LoadFactory.WriteToLocal(CS.UnityEngine.Application.dataPath.."/GameAssets/"..clientSavepath.."/"..name..ext,b); index=index+1; updateABundle(index,files);--递归调用 end ,false,CS.System.Enum.Parse(typeof(CS.util.loadType),type1)); else print("加载完成"); PlayerPrefs.SetFloat("localVersion",version); this.transform.parent:Find("checkVersion"):GetComponent("Text").text="更新完成,当前版本为"..version; this.transform.parent:Find("Img_person/Button").gameObject:SetActive(true); end end function getABundleByWWW() Http.doGet("http://192.168.1.103/version.json",this.self,function(str) --str=string.sub(str,4); print(str); local json=JsonDataLua.Parse(str); local value=json:getDouble("version"); print(value); local files=json:getArray("files"); local s="http://192.168.1.103/"; s=s..files[0]:getString("serverDownpath").."/"..files[0]:getString("name")..files[0]:getString("ext"); local name=files[0]:getString("name")..files[0]:getString("ext"); local savePath=files[0]:getString("clientSavepath"); print(s); print(savePath); LoadFactory.DownLoadTest(this.self,s,savePath); --[[local ab=LoadFactory.LoadAssetBundle(s,this.self,function(ab) print(ab); end );]] --local ab=CS.UnityEngine.AssetBundle.LoadFromFile(s); --CS.System.IO.File.WriteAllText(CS.UnityEngine.Application.dataPath.."/GameAssets/GameHall/Resources/",luastr.text); end ); end
评论