You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Runtime.InteropServices; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class ScreenCapture : MonoBehaviour |
|
{ |
|
[DllImport("__Internal")] |
|
public static extern void ScreenShotData(string data); |
|
int number; |
|
string filename; |
|
public void onValueChanged(bool isOn) |
|
{ |
|
if (isOn) |
|
{ |
|
StartCoroutine(GetShot()); |
|
} |
|
} |
|
public void DisableToggle() |
|
{ |
|
GetComponent<Toggle>().isOn = false; |
|
} |
|
private void Awake() |
|
{ |
|
filename = Application.streamingAssetsPath + "/ScreenShot"; |
|
GetComponent<Toggle>().onValueChanged.AddListener(onValueChanged); |
|
} |
|
IEnumerator GetShot() |
|
{ |
|
yield return new WaitForEndOfFrame(); |
|
int width = Screen.width; |
|
int height = Screen.height; |
|
|
|
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); |
|
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, true); |
|
tex.Apply(); |
|
byte[] imagebytes = tex.EncodeToPNG(); |
|
System.IO.File.WriteAllBytes(filename + number++.ToString() + ".png", imagebytes); |
|
yield return new WaitForSeconds(1f); |
|
|
|
DisableToggle(); |
|
ResourceLoadWindow.Instance.LoadTextHintWindow("截图已保存", 2); |
|
yield return new WaitForSeconds(30.0F); |
|
} |
|
} |