IEnumerator Download(string name) { string json = string.Empty; #if UNITY_EDITOR yield return(MapHttpTask.Download(kv_cache.Get("uuid"), (string json1) => { json = json1; }, () => { }, true)); #else yield return(MapHttpTask.Download(kv_cache.Get("uuid"), (string json1) => { json = json1; })); #endif if (!string.IsNullOrEmpty(json)) { yield return(SceneMgr.LoadLevelAdditiveAsync("MapGalleryRuntime")); // mgr.latestLoadedMap = GameObject.FindObjectOfType<MapInfo>(); var run = GameObject.FindObjectOfType <MapGalleryRuntimeRunner>(); run.LoadFromJson(json); this.StartCoroutine(StartWithIsNetworkFalse()); } }
IEnumerator Download(string name) { string json = string.Empty; yield return(MapHttpTask.Download(name, (string json1) => { json = json1; }, () => { //地图下载失败 直接回退 SceneMgr.LoadLevel("GameLogin"); }, true)); if (!string.IsNullOrEmpty(json)) { yield return(SceneMgr.LoadLevelAdditiveAsync("MapPreviewRuntime")); // mgr.latestLoadedMap = GameObject.FindObjectOfType<MapInfo>(); var run = GameObject.FindObjectOfType <MapPreviewRuntimeRunner>(); run.LoadFromJson(json); this.StartCoroutine(StartWithIsNetworkFalse()); mgr.topSceneLevelInfo.gameObject.SetActive(true); mgr.topSceneLevelInfo.GetComponent <MapSceneRoot>().AutoLoadSyncable(mgr); if (GameMgr.mode == BattleMode.Guide && GuideMgr.ins != null) { GuideMgr.ins.TriggerDrama(GuideTriggerType.MapCreate, null); GuideMgr.ins.HideBlackMask(); } } }
IEnumerator Download(string name) { string json = string.Empty; yield return(MapHttpTask.Download(name, (string json1) => { json = json1; })); if (!string.IsNullOrEmpty(json)) { yield return(Application.LoadLevelAdditiveAsync("MapMyGalleryRuntime")); // mgr.latestLoadedMap = GameObject.FindObjectOfType<MapInfo>(); var run = GameObject.FindObjectOfType <MapMyGalleryRuntimeRunner>(); run.LoadFromJson(json); this.StartCoroutine(StartWithIsNetworkFalse()); } }
IEnumerator AsyncCapture(string uuid, VoidFuncObject cb, int WIDTH, int HEIGHT, bool showWeapon = false) { //先检查缓存图片存在否 如果存在 优先加载缓存 string weaponExtension = showWeapon ? "_weapon" : ""; string file_name = LocalStorageMapCaptureImage.ins.GetRootDirectory() + "/" + uuid.ToString() + "_" + WIDTH + "_" + HEIGHT + weaponExtension + ".jpg"; bool load_local_ok = false; if (File.Exists(file_name)) { // throw new NullReferenceException(); Texture2D tex = null; //try load from disk var www_local = LocalStorageMapCaptureImage.ins.LoadFromDisk(uuid.ToString() + "_" + WIDTH + "_" + HEIGHT + ".jpg"); if (www_local != null) { using (www_local) { yield return(www_local); if (www_local.isDone && string.IsNullOrEmpty(www_local.error)) { tex = www_local.texture; } } } if (tex != null) { if (cb != null) { cb(tex); load_local_ok = true; } else { GameObject.DestroyImmediate(tex); } } tex = null; } if (load_local_ok == false) { download_ok = false; yield return(MapHttpTask.Download(uuid, (string json) => { this.download_ok = true; }, () => { this.download_ok = false; }, true)); if (download_ok) { if (showWeapon) { ShowWeaponSpawnPoints(); } var serializer = this.GetComponent <MapEditor.RuntimeSerialize>(); long luuid = 0; long.TryParse(uuid, out luuid); //先把地图加载出来 serializer.Load(luuid); transform.position = new Vector3(0f, 1000f, 1000f); //销毁所有MapObject脚本 防止以外情况 // yield return new WaitForEndOfFrame(); yield return(new WaitForEndOfFrame()); if (showWeapon) { CheckWeaponSpawnPoints(); } foreach (var p in this.GetComponentsInChildren <MonoBehaviour>()) { if (p != null) { if (p.gameObject == this.gameObject) { continue; } GameObject.Destroy(p); } } //开始捕捉图像 RenderTexture tex = new RenderTexture(WIDTH, HEIGHT, 20); camera.targetTexture = tex; camera.Render(); RenderTexture.active = tex; Texture2D tex2d = new Texture2D(WIDTH, HEIGHT); tex2d.ReadPixels(new Rect(0, 0, WIDTH, HEIGHT), 0, 0); tex2d.Apply(); byte[] save_data = tex2d.EncodeToJPG(); File.WriteAllBytes(file_name, save_data); RenderTexture.active = null; camera.targetTexture = null; if (cb != null) { cb(tex2d); } else { GameObject.DestroyImmediate(tex2d); } GameObject.DestroyImmediate(tex); tex2d = null; tex = null; } else { cb(null); } } Application.UnloadLevel("MapRuntimeCapture"); }