81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using Boo.Lang.Runtime;
|
|
using UnityEngine;
|
|
using UnityScript.Lang;
|
|
|
|
[Serializable]
|
|
public class ScreenshotTakerPro : MonoBehaviour
|
|
{
|
|
public virtual void Update()
|
|
{
|
|
if (!Input.GetKeyDown("p") && !Input.GetKeyDown("o"))
|
|
{
|
|
return;
|
|
}
|
|
bool keyDown = Input.GetKeyDown("o");
|
|
int num = 4300;
|
|
int num2 = 2200;
|
|
if (!keyDown)
|
|
{
|
|
num = Screen.width;
|
|
num2 = Screen.height;
|
|
}
|
|
Camera[] array = ((Camera[])UnityEngine.Object.FindObjectsOfType(typeof(Camera))) as Camera[];
|
|
int num3 = 1;
|
|
UnityScript.Lang.Array array2 = array;
|
|
for (int i = 0; i < array2.length; i++)
|
|
{
|
|
if (RuntimeServices.ToBool(RuntimeServices.InvokeBinaryOperator("op_LessThanOrEqual", UnityRuntimeServices.GetProperty(array2[i], "depth"), UnityRuntimeServices.GetProperty(array2[0], "depth"))))
|
|
{
|
|
array2.Unshift(array2[i]);
|
|
array2.RemoveAt(i + 1);
|
|
}
|
|
}
|
|
array = (Camera[])array2.ToBuiltin(typeof(Camera));
|
|
int j = 0;
|
|
Camera[] array3 = array;
|
|
RenderTexture renderTexture = default(RenderTexture);
|
|
for (int length = array3.Length; j < length; j++)
|
|
{
|
|
if (keyDown)
|
|
{
|
|
renderTexture = new RenderTexture(num, num2, 24, RenderTextureFormat.RGB565);
|
|
array3[j].targetTexture = renderTexture;
|
|
array3[j].Render();
|
|
}
|
|
Texture2D texture2D = null;
|
|
texture2D = new Texture2D(num, num2, TextureFormat.RGB24, false);
|
|
if (keyDown)
|
|
{
|
|
RenderTexture.active = renderTexture;
|
|
}
|
|
texture2D.ReadPixels(new Rect(0f, 0f, num, num2), 0, 0, false);
|
|
if (keyDown)
|
|
{
|
|
RenderTexture.active = null;
|
|
}
|
|
array3[j].targetTexture = null;
|
|
if (keyDown)
|
|
{
|
|
UnityEngine.Object.Destroy(renderTexture);
|
|
}
|
|
byte[] bytes = texture2D.EncodeToPNG();
|
|
if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor)
|
|
{
|
|
File.WriteAllBytes(Application.dataPath + "/screenshots/screen" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + " " + num3 + ".png", bytes);
|
|
}
|
|
else
|
|
{
|
|
File.WriteAllBytes(Application.dataPath + "/../screenshots/screen" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + " " + num3 + ".png", bytes);
|
|
}
|
|
num3++;
|
|
UnityEngine.Object.DestroyImmediate(texture2D);
|
|
}
|
|
}
|
|
|
|
public virtual void Main()
|
|
{
|
|
}
|
|
}
|