Script de capture d’écran
Voici un script qui vous permet de faire une capture de votre scène lors d’un jeu. Il suffit d’intégrer le code qui est fournit ici en C# et en JS et d’appuyer sur la touche « k » pour qu’une image au format png soit générée dans le dossier relatif « /screenshots/screen ».
Vous pouvez bien sur changer ces paramètres cibles à votre convenance.
C# :
using UnityEngine;
using System.Collections;
public class HiResScreenShots : MonoBehaviour {
public int resWidth = 4096;
public int resHeight = 2232;
void Update () {
if (Input.GetKeyDown("k")) {
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight,
TextureFormat.RGB24, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
camera.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string filename = Application.dataPath + "/screenshots/screen"
+ System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png";
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("Took screenshot to: {0}", filename));
}
}
}
JavaScript :
var resWidth : int = 4096;
var resHeight : int = 2232;
function Update()
{
if (Input.GetKeyDown ("k"))
{
var rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
var screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(Rect(0, 0, resWidth, resHeight), 0, 0);
RenderTexture.active = null; // JC: added to avoid errors
camera.targetTexture = null;
Destroy(rt);
var bytes = screenShot.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.dataPath + "/screenshots/screen" + System.DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".png", bytes);
}
}
Mais c’est nul comme truc…. ca plombe les perf…
🙁
a) La résolution est de 4096*2232. Tu peux faire moins.
b) Si tu as une autre solution, le site est preneur. En attendant….
JP
Hé bah personnellement je viens de tomber dessus et merci bien, c’est simple, pratique et exactement ce que je cherchais
Super je cherchais ça merci