void grabCheckPointCameraData()//2016-12-06: grabs image data from the camera designated for checkpoints { if (checkpointCamera == null) { checkpointCamera = GameObject.Find("CP BG Camera").GetComponent <Camera>(); checkpointCamera.gameObject.SetActive(false); } checkpointCamera.gameObject.SetActive(true); checkpointCamera.gameObject.transform.position = gameObject.transform.position + new Vector3(0, 0, -10); //2016-12-06: The following code copied from an answer by jashan: http://answers.unity3d.com/questions/22954/how-to-save-a-picture-take-screenshot-from-a-camer.html int resWidth = 300; int resHeight = 300; RenderTexture rt = new RenderTexture(resWidth, resHeight, 24); checkpointCamera.targetTexture = rt; Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); checkpointCamera.Render(); RenderTexture.active = rt; screenShot.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); screenShot.Apply(); checkpointCamera.targetTexture = null; RenderTexture.active = null; // JC: added to avoid errors Destroy(rt); gsr.sprite = Sprite.Create(screenShot, new Rect(0, 0, screenShot.width, screenShot.height), new Vector2(0.5f, 0.5f)); checkpointCamera.gameObject.SetActive(false); string filename = gameObject.name + ".png"; ES2.SaveImage(screenShot, filename); }
void SaveMapTexture() { //var tex = new UnityEngine.Texture2D(fogTexture.width, fogTexture.height); //tex = fogTexture; ES2.SaveImage(fogTexture, "savedFogTexture.png"); }