using UnityEngine;
using System.Collections;
public class jietu : MonoBehaviour {
int w, h;
Vector3 v1, v2;
void Update()
{
//按下鼠标拖动直至松开鼠标划定范围,截图
if (Input.GetMouseButtonDown(0))
{
v1 = Input.mousePosition;//鼠标按下位置~
}
if (Input.GetMouseButtonUp(0))
{
v2 = Input.mousePosition; //鼠标抬起位置~
//计算鼠标划定范围的长和宽~~
w = int.Parse(Mathf.Abs(v1.x - v2.x).ToString());
h = int.Parse(Mathf.Abs(v1.y - v2.y).ToString());
StartCoroutine(GetCapture());
}
}
IEnumerator GetCapture()
{
//等待所有的摄像机跟GUI渲染完成
yield return new WaitForEndOfFrame();
Texture2D tex = new Texture2D(w, h, TextureFormat.RGB24, false);
//计算区域
float vx = (v1.x > v2.x) ? v2.x : v1.x; //取较小的x,y作为起始点
float vy = (v1.y > v2.y) ? v2.y : v1
unity中鼠标划定范围截图
最新推荐文章于 2022-05-12 15:58:30 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)