前言
一直在从事Unity客户端工作. 总的来说,自己学到的技术并不多,但还是有一些有用的. 这里我把这几年整理的一些功能代码贴出来,主要是害怕自己有一天真的老了,忘记了. (第一次写博客,有不对的方望指出,一定改正), 不忘初心,共同进步 !
Unity屏幕截图:
using UnityEngine;
using System.Collections;
using System.IO;
public class ScreenShot : MonoBehaviour
{
void Start()
{
//StartCoroutine(UploadPNG());
}
IEnumerator UploadPNG()
{
yield return new WaitForEndOfFrame();
Debug.Log("截图..........");
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);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/截图.png", bytes);
UnityEditor.AssetDatabase.Refresh();
Debug.Log("保存成功");
}
//测试
public void BtnEvent_Shot()
{
StartCoroutine(UploadPNG());
}
}
以后只要有空,我都会写点东西,今天就到这里了!