我正在为Android和Android制作游戏iOS并使用此脚本截取屏幕截图,并在达到高分时将其应用于精灵图像。调用getScreenshot()
进行初始化。它在使用Application.persistentDataPath + "/" + screenshotFilename;
的Windows上的播放器中工作正常,但我猜测iOS可能需要\
,但我仍然在Xcode中收到函数LoadPNG();
public static string screenshotFilename = "MM_Screenshot.png";
string pathToImage;
public void getScreenshot() {
pathToImage = Application.persistentDataPath + "\\" + screenshotFilename;
Application.CaptureScreenshot (pathToImage);
StartCoroutine("LoadScreenshot");
}
IEnumerator LoadScreenshot() {
Sprite NewSprite = new Sprite();
Texture2D SpriteTexture = LoadPNG(pathToImage);
GameObject.Find("CaptureImage").GetComponent<Image>().sprite = Sprite.Create(SpriteTexture,new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0.5f, 0.8f));
yield return null;
}
public static Texture2D LoadPNG(string filePath) {
Texture2D tex = null;
byte[] fileData;
if (File.Exists(filePath)) {
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
}
return tex;
}