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.
52 lines
1.8 KiB
52 lines
1.8 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Screenshot : MonoBehaviour
|
|
{
|
|
public Sprite[] sprites;
|
|
public GameObject errtip;
|
|
List<int> arr = new List<int>();
|
|
int imgCount=-1;
|
|
void Start()
|
|
{
|
|
GetComponent<Button>().onClick.AddListener(() => {
|
|
addImages();
|
|
});
|
|
}
|
|
//截图
|
|
Texture2D ShotImg(Camera camera) {
|
|
RenderTexture.active = camera.activeTexture;
|
|
Texture2D texture = new Texture2D(camera.activeTexture.width, camera.activeTexture.height, TextureFormat.RGB24, false);
|
|
Rect rect = new Rect(0, 0, camera.activeTexture.width, camera.activeTexture.height);
|
|
texture.ReadPixels(rect, 0, 0);
|
|
texture.Apply();
|
|
return texture;
|
|
}
|
|
//添加到图片集
|
|
void addImages(Texture2D texture2D) {
|
|
Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));
|
|
GameObject img = new GameObject();
|
|
img.AddComponent<Image>();
|
|
img.GetComponent<Image>().sprite = sprite;
|
|
img.transform.SetParent(GameObject.FindWithTag("Images").transform);
|
|
}
|
|
|
|
void addImages()
|
|
{
|
|
if (arr.Contains(LevelBase.Instance.curArea)) {
|
|
errtip.SetActive(true);
|
|
errtip.transform.GetChild(0).GetComponent<Text>().text = "当前区域已经采集";
|
|
return;
|
|
}
|
|
arr.Add(LevelBase.Instance.curArea);
|
|
imgCount++;
|
|
if (imgCount >= sprites.Length) return;
|
|
GameObject img = new GameObject();
|
|
img.AddComponent<Image>();
|
|
img.GetComponent<Image>().sprite = sprites[imgCount];
|
|
img.transform.SetParent(GameObject.FindWithTag("Images").transform);
|
|
}
|
|
}
|