unity实现按住鼠标选取区域截图
本文实例为大家分享了unity按住鼠标选取区域截图的具体代码,供大家参考,具体内容如下
privateintcapBeginX;
privateintcapBeginY;
privateintcapFinishX;
privateintcapFinishY;
publicImageshowImg;
//Usethisforinitialization
voidStart(){
}
//Updateiscalledonceperframe
voidUpdate(){
if(Input.GetMouseButtonDown(0)){
Vector3mousePos=Input.mousePosition;
Vector2beginPos=newVector2(mousePos.x,mousePos.y);
capBeginX=(int)mousePos.x;
capBeginY=(int)mousePos.y;
}
if(Input.GetMouseButtonUp(0)){
Vector3mousePos=Input.mousePosition;
Vector2finishPos=newVector2(mousePos.x,mousePos.y);
capFinishX=(int)mousePos.x;
capFinishY=(int)mousePos.y;
//重新计算截取的位置
intcapLeftX=(capBeginX
小编为大家分享一段Unity实现截屏功能的代码,供大家参考:
publicclassScreenShot:MonoBehaviour
{
voidOnScreenShotClick()
{
//得到当前系统时间
System.DateTimenow=System.DateTime.Now;
stringtimes=now.ToString();
//去掉前后空格
times=times.Trim();
//将斜杠替换成横杠
times=times.Replace("/","-");
stringfileName="ARScreenShot"+times+".png";
//判断该平台是否为安卓平台
if(Application.platform==RuntimePlatform.Android)
{
//参数依次为屏幕宽度屏幕高度纹理格式是否使用映射
Texture2Dtexture=newTexture2D(Screen.width,Screen.height,TextureFormat.RGB24,false);
//读取贴图
texture.ReadPixels(newRect(0,0,Screen.width,Screen.height),0,0);
//应用截屏
texture.Apply();
//将对象序列化
byte[]bytes=texture.EncodeToPNG();
//设定存储到的手机文件夹路径
stringdestination="/sdcard/DCIM/Screenshots";
//如果不存在该文件夹
if(!Directory.Exists(destination))
{
//创建该文件夹
Directory.CreateDirectory(destination);
}
stringpathSave=destination+"/"+fileName;
File.WriteAllBytes(pathSave,bytes);
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短