我正在制作一个简单的应用程序,有两个场景,第一个有AR相机,我将截取并保存它。第二个场景它只会显示一个带有截图的GUI。
应用程序会截取屏幕截图并以不同的名称保存它,一切都很好我的问题是我在第二个场景中捕获后无法显示图像。
我正在使用3个脚本
第一个是sceneManager,我用来存储一个静态变量来保存在两个场景中使用的截图名称:
using UnityEngine;
using System.Collections;
public class sceneManeger : MonoBehaviour {
#region STATIC VARIABLES
public static string fileName;
#endregion
}
第二个脚本是screenshot.cs
using UnityEngine;
using System.Collections;
public class screenshot : MonoBehaviour {
public static string filename;
public Texture2D icon;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
if (GUI.Button (new Rect (Screen.width / 2, Screen.height - 100, 60, 60), icon, "lable")) {
Application.CaptureScreenshot("Screenshot" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png");
filename = "Screenshot" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png" ;
sceneManeger.fileName = filename;
Application.LoadLevel("normal");
}
}
}
3d是GUIscreenshot.cs,我想用它来显示捕获图像:
using UnityEngine;
using System.Collections;
public class GUIscreenShot : MonoBehaviour {
public Texture2D img;
private string path;
void Start () {
}
void Update () {
}
void OnGUI () {
if (GUI.Button (new Rect(0, 0, Screen.width, Screen.height),img, "lable")) {
Application.LoadLevel("AS");
}
}
}
我需要知道如何存储已经在texture2d img变量中捕获的屏幕截图,以便它将呈现为GUI纹理
好吧我把我的应用程序更改为一个场景,就像这个screenShot.cs:
using UnityEngine;
using System.Collections;
public class screenshot : MonoBehaviour {
public static string filename;
public Texture2D icon;
private Texture2D imgcap;
public bool showBox = false;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
if (showBox) {
GUI.Button (new Rect (0, 0, Screen.width, Screen.height), imgcap, "lable");
}
if (GUI.Button (new Rect (Screen.width / 2, Screen.height - 100, 60, 60), icon, "lable")) {
Application.CaptureScreenshot("Screenshot" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png");
filename = "Screenshot" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png" ;
imgcap = Resources.Load(filename) as Texture2D;
showBox = true;
}
}
}
但它仍然无效,当我按下GUI按钮获取屏幕截图时,它不会显示应该显示已经拍摄的图像的另一个GUI。