IEnumerator SaveAssetImage() { byte[] bytes = texture.EncodeToPNG(); string path = Application.persistentDataPath + "/MyImage.png"; File.WriteAllBytes(path, bytes); yield return(new WaitForEndOfFrame()); StartCoroutine(ScreenshotManager.SaveExisting(path, true)); }
IEnumerator saveScreenShot() { Camera[] cameras = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[]; LayerMask nothingLayerMask = 0; GameState oldState = PropertiesSingleton.instance.gameState; PropertiesSingleton.instance.gameState = GameState.SAVE_PIC; Dictionary <Camera, Color32> camColors = new Dictionary <Camera, Color32>(); Dictionary <Camera, LayerMask> camMask = new Dictionary <Camera, LayerMask>(); foreach (Camera cam in cameras) { camColors.Add(cam, cam.backgroundColor); cam.backgroundColor = PropertiesSingleton.instance.screenShotInProgressColor; camMask.Add(cam, cam.cullingMask); cam.cullingMask = nothingLayerMask; } yield return(null); #if UNITY_EDITOR string path = "Temp/" + ScreenshotManager.getName(PropertiesSingleton.instance.activeSheet.name.Localized()); #else string path = Application.persistentDataPath + "/" + ScreenshotManager.getName(PropertiesSingleton.instance.activeSheet.name.Localized()); #endif Texture2D texture = PropertiesSingleton.instance.canvasWorkspaceController.canvas.getResultTexture(); System.IO.File.WriteAllBytes(path, texture.EncodeToPNG()); yield return(StartCoroutine(ScreenshotManager.SaveExisting(path))); yield return(new WaitForSeconds(PropertiesSingleton.instance.screenShotTimeout)); UnityEngine.Object.DestroyImmediate(texture); Resources.UnloadUnusedAssets(); System.GC.Collect(); yield return(null); foreach (Camera cam in cameras) { cam.backgroundColor = camColors[cam]; cam.cullingMask = camMask[cam]; } PropertiesSingleton.instance.gameState = oldState; }