public void StartLoadAssetBundle(ProjectAssetBundlesInfo p) { #if UNITY_IPHONE || UNITY_IOS commonAssetBundlesInfo = commonAssetBundlesIOS; #elif UNITY_ANDROID commonAssetBundlesInfo = commonAssetBundlesAndriod; #endif countSceneOnDefault = 0; //由sceneType获取常规场景个数 if (p.sceneTypeSet != null) { foreach (int i in p.sceneTypeSet) { if (i != 8) { countSceneOnDefault++; } } } sceneAssetBundlesInfoTotalCount = p.needExportScenePath.Length; LoopLoadCommonAssetBundle(0); //加载总数显示,point的个数 circlePointCount = sceneAssetBundlesInfoTotalCount + commonAssetBundlesInfo.Length; loadingAssetBundleTotalInfo.OpenTotalInfo(circlePointCount); }
void LoadProjectAssetBundlesInfo() { if (File.Exists(filePath)) { needExportScenePath = new List <string>(); needExportSceneType = new List <SceneTypeSet>(); jsonString = File.ReadAllText(filePath); projectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(jsonString); addCommonAssetBundle = projectAssetBundlesInfo.addCommonAssetBundle; for (int i = 0; i < projectAssetBundlesInfo.sceneTypeSet.Length; i++) { needExportSceneType.Add((SceneTypeSet)projectAssetBundlesInfo.sceneTypeSet[i]); } // foreach() // { // needExportSceneType.AddRange(projectAssetBundlesInfo.sceneType); // } needExportScenePath.AddRange(projectAssetBundlesInfo.needExportScenePath); needExportScene = new List <SceneAsset>(); foreach (string p in needExportScenePath) { SceneAsset s = AssetDatabase.LoadAssetAtPath <SceneAsset>(p); if (s != null) { needExportScene.Add(s); } else { // needExportScene.Add(new sc); } // AssetImporter assetImporter = AssetImporter.GetAtPath(p); //得到Asset } // AssetDatabase.GetAssetPath(sceneAsset.GetInstanceID()) } else { projectAssetBundlesInfo = new ProjectAssetBundlesInfo(); projectAssetBundlesInfo.addCommonAssetBundle = new string[1]; projectAssetBundlesInfo.addCommonAssetBundle[0] = "basesource"; jsonString = JsonUtility.ToJson(projectAssetBundlesInfo); File.WriteAllText(filePath, jsonString); AssetDatabase.Refresh(); LoadProjectAssetBundlesInfo(); } // XmlWriter writer = XmlWriter.Create(Application.dataPath + "/WJMFramework/Editor/MaterialsEditor/prefabXML/" + xmlName + ".xml", settings); }
/* * void LoadCommonAssetBundles() * { * //commonPath + commonAssetBundlesInfo[i].name 这个是Caching的路径名 * for (int i = 0; i < commonAssetBundlesInfo.Length; i++) * { * //检测currentLoadedAssetBundles中是否已含有将要装载的AssetBundle * if (currentLoadedAssetBundles.FindIndex(x => x.name == commonAssetBundlesInfo[i].name) == -1) * { * Caching.ClearOtherCachedVersions(pathAndURL.commonPath + commonAssetBundlesInfo[i].name, Hash128.Parse(commonAssetBundlesInfo[i].hash)); * * Loading loading = loadingManager.AddALoading(2); * * netCtrlManager.WebRequest( * "下载基础资源包", * pathAndURL.serverCommonAssetBundlePath + commonAssetBundlesInfo[i].name + "?" + pathAndURL.commonPath + commonAssetBundlesInfo[i].name + "," + commonAssetBundlesInfo[i].hash + "," + commonAssetBundlesInfo[i].CRC, * loading.LoadingAnimation, * (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a,string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, * null, * null, * (DownloadHandlerAssetBundle t) => * { * commonAssetBundlesInfoHasLoadedCount++; * currentLoadedAssetBundles.Add(t.assetBundle); * AllCommonAssetBundleLoaded(); * } * ); * } * * } * } * * void AllCommonAssetBundleLoaded() * { * if (commonAssetBundlesInfoHasLoadedCount == commonAssetBundlesInfo.Length) * { * Debug.Log("AllCommonAssetbundleLoaded!"); * LoadFirstSceneAssetBundle(true); * } * } */ void LoopLoadSceneAssetBundle(int currentID) { Loading loading = loadingManager.AddALoading(2); ProjectAssetBundlesInfo p = serverProjectAssetBundlesInfo; string sceneName = p.needExportScenePath[currentID].Split('.')[0]; string[] splitStr = sceneName.Split('/'); sceneName = splitStr[splitStr.Length - 1]; sceneName = sceneName.ToUpper(); if (sceneName == "OUTDOOR") { sceneName = "大场景"; } else { sceneName += "户型"; } //index的 netCtrlManager.WebRequest( "下载 " + (sceneName), pathAndURL.serverAssetBundlePath + p.sceneAssetBundle[currentID] + "^" + pathAndURL.projectPath + p.sceneAssetBundle[currentID] + "," + p.sceneAssetBundleHash[currentID] + "," + p.sceneAssetBundleCRC[currentID], loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, null, null, (DownloadHandlerAssetBundle t) => { //改变加载场景数圆点的颜色 loadingAssetBundleTotalInfo.SetCirclePointOkColor(commonAssetBundlesInfo.Length + sceneAssetBundlesInfoHasLoadedCount); Debug.Log(t.assetBundle.name); sceneAssetBundlesInfoHasLoadedCount++; currentLoadedAssetBundles.Add(t.assetBundle); if (sceneAssetBundlesInfoHasLoadedCount < sceneAssetBundlesInfoTotalCount) { LoopLoadSceneAssetBundle(sceneAssetBundlesInfoHasLoadedCount); } else if (sceneAssetBundlesInfoHasLoadedCount == sceneAssetBundlesInfoTotalCount) { // Debug.Log("AllSceneAssetbundleLoaded!"); loadingAssetBundleTotalInfo.CloseTotalInfo(); //sceneInteractiveManger.finishLoadAssetBundle = true; sceneInteractiveManger.OnAllAssetBundleLoaded(); } } ); }
public void StartLoadAssetBundle(ProjectAssetBundlesInfo p) { #if UNITY_IPHONE || UNITY_IOS commonAssetBundlesInfo = commonAssetBundlesIOS; #elif UNITY_ANDROID commonAssetBundlesInfo = commonAssetBundlesAndriod; #endif sceneAssetBundlesInfoTotalCount = p.needExportScenePath.Length; LoopLoadCommonAssetBundle(0); //加载总数显示,point的个数 circlePointCount = sceneAssetBundlesInfoTotalCount + commonAssetBundlesInfo.Length; loadingAssetBundleTotalInfo.OpenTotalInfo(circlePointCount); }
//for 360 point public void LoadAddSingerScene(string sceneName) { Loading loading = loadingManager.AddALoading(5); loadingAssetBundleTotalInfo.OpenTotalInfo(1); circlePointCurrent = 0; ProjectAssetBundlesInfo p = serverProjectAssetBundlesInfo; int targetID = -1; for (int i = 0; i < p.sceneAssetBundle.Length; i++) { if (GetUTF16(sceneName).ToLower() == p.sceneAssetBundle[i]) { targetID = i; } } netCtrlManager.WebRequest( "下载 " + (sceneName), pathAndURL.serverAssetBundlePath + p.sceneAssetBundle[targetID] + "^" + pathAndURL.projectPath + p.sceneAssetBundle[targetID] + "," + p.sceneAssetBundleHash[targetID] + "," + p.sceneAssetBundleCRC[targetID], loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("LoadAddSingerScene Failed!"); }, null, null, (DownloadHandlerAssetBundle t) => { currentLoadedSceneAssetBundles.Add(t.assetBundle); Loading loadingScene2 = loadingManager.AddALoading(5); foreach (Transform tr in loadingScene2.GetComponentsInChildren <Transform>()) { if (tr.name == "BG") { tr.gameObject.SetActive(false); } } loadingAssetBundleTotalInfo.CloseTotalInfo(); loadingScene2.LoadingAnimation(SceneManager.LoadSceneAsync(serverProjectAssetBundlesInfo.needExportScenePath[targetID], LoadSceneMode.Additive), "正在加载"); loadingScene2.OnLoadedEvent.AddListener(() => { sceneInteractiveManger.ChangeInteractiveScene(sceneInteractiveManger.senceInteractiveInfoGroup[0], true); }); } ); }
void OnLoadProjectAssetBundlesInfo(ProjectAssetBundlesInfo a, string projectID, string hxAssetBundleName) { projectAssetBundlesInfo = a; for (int i = 0; i < projectAssetBundlesInfo.sceneAssetBundle.Length; i++) { if (projectAssetBundlesInfo.sceneAssetBundle[i] == hxAssetBundleName) { HXInfo newHXInfo = new HXInfo(); newHXInfo.hxSenePath = projectAssetBundlesInfo.needExportScenePath[i]; newHXInfo.hash = projectAssetBundlesInfo.sceneAssetBundleHash[i]; newHXInfo.crc = projectAssetBundlesInfo.sceneAssetBundleCRC[i]; newHXInfo.hxAssetBundleName = hxAssetBundleName; newHXInfo.projectID = projectID; assetBundleManager.LoadAssetBundleAndAddToSceneInARMode(projectID, newHXInfo); } } }
public void LoadProjcetAssetBundles(string inProjectID) { // Debug.Log("PersistentDataPath: "+Application.persistentDataPath); // SetProjectPath(inProjectID); Loading loading = loadingManager.AddALoading(0); bool checkFile = false; if (checkFile = File.Exists(pathAndURL.localProjectAssetBundlesInfoPath)) { string jsonStr = File.ReadAllText(pathAndURL.localProjectAssetBundlesInfoPath); localProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(jsonStr); netCtrlManager.WebRequest( "同步服务器", pathAndURL.serverProjectAssetBundlesInfoPath, loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); // if (globalDebug) GlobalDebug.ReplaceLine(t.text, 15); //判断两个资源的生成时间,如果时间不一样表示资源以过期,要删去旧的资源以便重新下载 if (serverProjectAssetBundlesInfo.buildTime != localProjectAssetBundlesInfo.buildTime) { File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); for (int i = 0; i < serverProjectAssetBundlesInfo.sceneAssetBundle.Length; i++) { Caching.ClearOtherCachedVersions(pathAndURL.projectPath + serverProjectAssetBundlesInfo.sceneAssetBundle[i], Hash128.Parse(serverProjectAssetBundlesInfo.sceneAssetBundleHash[i])); } } StartLoadAssetBundle(serverProjectAssetBundlesInfo); }, null, null ); } else { netCtrlManager.WebRequest( "同步服务器", pathAndURL.serverProjectAssetBundlesInfoPath, loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { // if (globalDebug) GlobalDebug.ReplaceLine(t.text, 15); serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); StartLoadAssetBundle(serverProjectAssetBundlesInfo); }, null, null ); } // if(globalDebug) GlobalDebug.ReplaceLine("HasLoaclInfo.txt:" + checkFile.ToString(), 16); }
public void LoadHXinARmode(string projectID, string hxAssetBundleName) { projectAssetBundlesInfo = null; pathAndURL.SetProjectPath(projectID); LoadProjectAssetBundlesInfo(projectID, hxAssetBundleName); }
//如果OnCached非空,只会缓存AssetBundles,且调用OnCached public void LoadProjcetAssetBundlesCache(string inProjectID, UnityAction <ProjectAssetBundlesInfo, string, string> OnCached = null, string hxAssetBundleName = null) { //Debug.Log("PersistentDataPath: "+Application.persistentDataPath); Loading loading = loadingManager.AddALoading(0); bool checkFile = false; if (checkFile = File.Exists(pathAndURL.localProjectAssetBundlesInfoPath)) { string log = "有本地ProjectAssetBundlesInfo.txt"; GlobalDebug.Addline(log); Debug.Log(log); string jsonStr = File.ReadAllText(pathAndURL.localProjectAssetBundlesInfoPath); localProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(jsonStr); Debug.Log(pathAndURL.serverProjectAssetBundlesInfoPath); GlobalDebug.Addline(pathAndURL.serverProjectAssetBundlesInfoPath); Debug.Log(netCtrlManager); //"?"+DateTime.Now.ToString() 添加时间防止ios读取http缓存 netCtrlManager.WebRequest( "同步AssetBundle服务器", pathAndURL.serverProjectAssetBundlesInfoPath + "?" + DateTime.Now.ToString(), loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); // if (globalDebug) GlobalDebug.ReplaceLine(t.text, 15); Debug.Log(t.text); string log2 = "ServerTime:" + serverProjectAssetBundlesInfo.buildTime + " LocalTime:" + localProjectAssetBundlesInfo.buildTime; GlobalDebug.Addline(log2); Debug.Log(log2); //判断两个资源的生成时间,如果时间不一样表示资源以过期,要删去旧的资源以便重新下载 if (serverProjectAssetBundlesInfo.buildTime != localProjectAssetBundlesInfo.buildTime) { string log3 = "删除老资源,替换新资源"; GlobalDebug.Addline(log3); Debug.Log(log3); File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); for (int i = 0; i < serverProjectAssetBundlesInfo.sceneAssetBundle.Length; i++) { Caching.ClearOtherCachedVersions(pathAndURL.projectPath + serverProjectAssetBundlesInfo.sceneAssetBundle[i], Hash128.Parse(serverProjectAssetBundlesInfo.sceneAssetBundleHash[i])); } } if (OnCached != null) { OnCached.Invoke(serverProjectAssetBundlesInfo, inProjectID, hxAssetBundleName); } else { StartLoadAssetBundle(serverProjectAssetBundlesInfo); } }, null, null ); } else { string log = "无本地ProjectAssetBundlesInfo.txt"; GlobalDebug.Addline(log); Debug.Log(log); netCtrlManager.WebRequest( "同步AssetBundle服务器", pathAndURL.serverProjectAssetBundlesInfoPath, loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { string log2 = "获取到Server的ProjectAssetBundlesInfo.txt"; GlobalDebug.Addline(log2); Debug.Log(log2); GlobalDebug.ReplaceLine(t.text, 15); serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); if (OnCached != null) { OnCached.Invoke(serverProjectAssetBundlesInfo, inProjectID, hxAssetBundleName); } else { StartLoadAssetBundle(serverProjectAssetBundlesInfo); } }, null, null ); } // if(globalDebug) GlobalDebug.ReplaceLine("HasLoaclInfo.txt:" + checkFile.ToString(), 16); }
public void LoopLoadSceneAssetBundle(int currentID, int loadingType) { Loading loading = loadingManager.AddALoading(loadingType); ProjectAssetBundlesInfo p = serverProjectAssetBundlesInfo; string sceneName = p.needExportScenePath[currentID].Split('.')[0]; string[] splitStr = sceneName.Split('/'); sceneName = splitStr[splitStr.Length - 1]; sceneName = sceneName.ToUpper(); if (sceneName == "OUTDOOR") { sceneName = "大场景"; } else { sceneName += "户型"; } //index的 netCtrlManager.WebRequest( "下载 " + (sceneName), pathAndURL.serverAssetBundlePath + p.sceneAssetBundle[currentID] + "^" + pathAndURL.projectPath + p.sceneAssetBundle[currentID] + "," + p.sceneAssetBundleHash[currentID] + "," + p.sceneAssetBundleCRC[currentID], loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, null, null, (DownloadHandlerAssetBundle t) => { //改变加载场景数圆点的颜色 circlePointCurrent++; loadingAssetBundleTotalInfo.SetCirclePointOkColor(circlePointCurrent); // if (p.sceneTypeSet != null && p.sceneTypeSet.Length == p.needExportScenePath.Length && p.sceneTypeSet[sceneAssetBundlesInfoHasLoadedCount] == 8) // { //定点360不加载 // } // else // { currentLoadedSceneAssetBundles.Add(t.assetBundle); // } if (p.sceneTypeSet != null && p.sceneTypeSet.Length == p.needExportScenePath.Length && p.sceneTypeSet[sceneAssetBundlesInfoHasLoadedCount] == 8) { string[] spiltStrGroup = p.needExportScenePath[currentID].Split('/'); string[] spiltStrGroup2 = spiltStrGroup[spiltStrGroup.Length - 1].Split('.'); string point360SceneName = spiltStrGroup2[0]; if (!point360SceneNameGroup.Contains(point360SceneName)) { point360SceneNameGroup.Add(point360SceneName); //如果有Point360,就显示360按钮 defaultGUI.point360PointButton_Trigger.AlphaPlayForward(); } } sceneAssetBundlesInfoHasLoadedCount++; if (sceneAssetBundlesInfoHasLoadedCount < sceneAssetBundlesInfoTotalCount) { LoopLoadSceneAssetBundle(sceneAssetBundlesInfoHasLoadedCount, loadingType); } else if (sceneAssetBundlesInfoHasLoadedCount == sceneAssetBundlesInfoTotalCount) { // Debug.Log("AllSceneAssetbundleLoaded!"); loadingAssetBundleTotalInfo.CloseTotalInfo(); //sceneInteractiveManger.finishLoadAssetBundle = true; sceneInteractiveManger.OnAllAssetBundleLoaded(); sceneAssetBundlesInfoHasLoadedCount = 0; } } ); }