有什么网站可以做设计兼职,wordpress上传视频慢,怎样能创建一个网站,百度一下你就知道123使用Unity编辑器扩展技术实现快速截图功能
效果#xff1a;
里面没有什么太难的技术#xff0c;直接上源码吧
注意#xff01;代码需要放在Editor文件下才能正常运行
using System;
using UnityEditor;
using UnityEngine;[ExecuteInEditMode]
public class Screenshot …使用Unity编辑器扩展技术实现快速截图功能
效果
里面没有什么太难的技术直接上源码吧
注意代码需要放在Editor文件下才能正常运行
using System;
using UnityEditor;
using UnityEngine;[ExecuteInEditMode]
public class Screenshot : EditorWindow
{int MaxShowSelectGo 5;//最多显示选中的物体int resWidth Screen.width * 4;int resHeight Screen.height * 4;public Camera myCamera;int scale 1;float delayCreateTime 0.5f;string path ;bool showPreview true;RenderTexture renderTexture;GameObject[] selectGOs;bool isTransparent true;bool isCaptureMultiple false;// Add menu item named My Window to the Window menu[MenuItem(Tools/图片生成器)]public static void ShowWindow(){//Show existing window instance. If one doesnt exist, make one.EditorWindow editorWindow EditorWindow.GetWindow(typeof(Screenshot));editorWindow.autoRepaintOnSceneChange true;editorWindow.Show();editorWindow.title 图片生成器;}float lastTime;void OnGUI(){EditorGUILayout.LabelField(分辨率, EditorStyles.boldLabel);resWidth EditorGUILayout.IntField(宽, resWidth);resHeight EditorGUILayout.IntField(高, resHeight);EditorGUILayout.Space();EditorGUILayout.BeginHorizontal();EditorGUILayout.LabelField(默认设置, EditorStyles.boldLabel);if (GUILayout.Button(使用Game视图的分辨率)){resHeight (int)Handles.GetMainGameViewSize().y;resWidth (int)Handles.GetMainGameViewSize().x;}if (GUILayout.Button(使用默认大小。H1440W2560)){resHeight 1440;resWidth 2560;scale 1;}EditorGUILayout.EndHorizontal();EditorGUILayout.Space();scale EditorGUILayout.IntSlider(尺寸, scale, 1, 15);EditorGUILayout.HelpBox(截图的默认模式是裁剪所以选择合适的宽度和高度。比例是在不损失质量的情况下倍增或放大渲染的一个因素., MessageType.None);EditorGUILayout.Space();EditorGUILayout.LabelField(截图分辨率为 resWidth * scale x resHeight * scale p, EditorStyles.boldLabel);EditorGUILayout.Space();EditorGUILayout.BeginHorizontal();GUILayout.Label(选择相机, EditorStyles.boldLabel);myCamera EditorGUILayout.ObjectField(myCamera, typeof(Camera), true, null) as Camera;if (myCamera null) myCamera Camera.main;if (myCamera ! null) myCamera.clearFlags CameraClearFlags.SolidColor;isTransparent EditorGUILayout.Toggle(透明背景, isTransparent);EditorGUILayout.EndHorizontal();EditorGUILayout.HelpBox(选择要捕捉渲染的相机。勾选则背景透明, MessageType.None);EditorGUILayout.Space();isCaptureMultiple EditorGUILayout.Toggle(一次性捕捉多个物体, isCaptureMultiple);if (isCaptureMultiple){selectGOs Selection.gameObjects;GUILayout.Label((selectGOs.Length 0 ? 你还什么都没有选。使用鼠标选中场景中的物体用Shift或者Ctrl多选。 : 当前选择物体数量 selectGOs.Length), EditorStyles.boldLabel);int ShowSelectGo 0;foreach (var item in selectGOs){if (ShowSelectGoMaxShowSelectGo MaxShowSelectGo selectGOs.Length){GUILayout.Label(......, EditorStyles.boldLabel);break;}GUILayout.Label(item.name, EditorStyles.boldLabel);ShowSelectGo;}}EditorGUILayout.Space();GUILayout.Label(保存路径, EditorStyles.boldLabel);EditorGUILayout.BeginHorizontal();EditorGUILayout.TextField(path, GUILayout.ExpandWidth(false));if (GUILayout.Button(选择路径, GUILayout.ExpandWidth(false)))path EditorUtility.SaveFolderPanel(保存图片的路径, path, Application.dataPath);EditorGUILayout.EndHorizontal();EditorGUILayout.HelpBox(选择保存屏幕截图的文件夹, MessageType.None);EditorGUILayout.Space();delayCreateTime EditorGUILayout.Slider(延时生成时间, delayCreateTime, 0.5f, 5);EditorGUILayout.HelpBox(请注意时间越短生成图片出错的概率就越高。建议调整为1, MessageType.None);if (GUILayout.Button(生成, GUILayout.MinHeight(60))){if (path ) path EditorUtility.SaveFolderPanel(保存图片的路径, path, Application.dataPath);if (isCaptureMultiple){StartTakeHiResShot();}else{TakeHiResShot();Application.OpenURL(file:// path);}}EditorGUILayout.Space();EditorGUILayout.BeginHorizontal();if (GUILayout.Button(打开最后一个截图, GUILayout.MaxWidth(160), GUILayout.MinHeight(40))){if (lastScreenshot ! ){Application.OpenURL(file:// lastScreenshot);Debug.Log(Opening File lastScreenshot);}}if (GUILayout.Button(打开截图文件夹, GUILayout.MaxWidth(100), GUILayout.MinHeight(40))){Application.OpenURL(file:// path);}EditorGUILayout.EndHorizontal();}GameObject go null;void StartTakeHiResShot(){if (selectGOs.Length0){EditorUtility.DisplayDialog(提示, 请注意你没有选择任何物体这不会生成图片。\n\n请取消勾选一次性捕捉多个物体这个选项生成单张图片., 确定);return;}foreach (var item in selectGOs){item.SetActive(false);}go null;Take(0,0);//Take(0);}void Take(int index,float delayTime){if (index selectGOs.Length){if (go ! null) go.SetActive(false);selectGOs[index].SetActive(true);go selectGOs[index];if (delayTime delayCreateTime){delayTime 0;TakeHiResShot();index;}EditorApplication.delayCall () { Take(index, delayTime 0.1f); };}else{Application.OpenURL(file:// path);}}void Take(int index){if (index selectGOs.Length){if (go ! null) go.SetActive(false);selectGOs[index].SetActive(true);go selectGOs[index];//EditorApplication.delayCall () //{// TakeHiResShot(() { Take(index 1); });//};TakeHiResShot(() {Take(index 1);});}else{Application.OpenURL(file:// path);}}//private bool takeHiResShot false;public string lastScreenshot ;public string ScreenShotName(int width, int height){string strPath ;strPath string.Format({0}/screen_{1}x{2}_{3}.png,path,width, height,System.DateTime.Now.ToString(yyyy-MM-dd_HH-mm-ss));lastScreenshot strPath;return strPath;}public void TakeHiResShot(Action Callback null){Debug.Log(采取截图);int resWidthN resWidth * scale;int resHeightN resHeight * scale;RenderTexture rt new RenderTexture(resWidthN, resHeightN, 24);myCamera.targetTexture rt;TextureFormat tFormat;if (isTransparent)tFormat TextureFormat.ARGB32;elsetFormat TextureFormat.RGB24;Texture2D screenShot new Texture2D(resWidthN, resHeightN, tFormat, false);myCamera.Render();RenderTexture.active rt;screenShot.ReadPixels(new Rect(0, 0, resWidthN, resHeightN), 0, 0);myCamera.targetTexture null;RenderTexture.active null;byte[] bytes screenShot.EncodeToPNG();string filename ScreenShotName(resWidthN, resHeightN);System.IO.File.WriteAllBytes(filename, bytes);Debug.Log(string.Format(截图如下: {0}, filename));//Application.OpenURL(filename);Callback?.Invoke();}
}
点击下载Demo 文章转载自: http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.gqjqf.cn.gov.cn.gqjqf.cn http://www.morning.ghpld.cn.gov.cn.ghpld.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.hjjhjhj.com.gov.cn.hjjhjhj.com http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.nhgfz.cn.gov.cn.nhgfz.cn http://www.morning.xtrnx.cn.gov.cn.xtrnx.cn http://www.morning.dzqr.cn.gov.cn.dzqr.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.jxlnr.cn.gov.cn.jxlnr.cn http://www.morning.kyhnl.cn.gov.cn.kyhnl.cn http://www.morning.pqcsx.cn.gov.cn.pqcsx.cn http://www.morning.lxqyf.cn.gov.cn.lxqyf.cn http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.lcmhq.cn.gov.cn.lcmhq.cn http://www.morning.gychx.cn.gov.cn.gychx.cn http://www.morning.wpxfk.cn.gov.cn.wpxfk.cn http://www.morning.jcxgr.cn.gov.cn.jcxgr.cn http://www.morning.thnpj.cn.gov.cn.thnpj.cn http://www.morning.lmnbp.cn.gov.cn.lmnbp.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.jyfrz.cn.gov.cn.jyfrz.cn http://www.morning.fjptn.cn.gov.cn.fjptn.cn http://www.morning.qnsmk.cn.gov.cn.qnsmk.cn http://www.morning.lcbt.cn.gov.cn.lcbt.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.njqpg.cn.gov.cn.njqpg.cn http://www.morning.fjtnh.cn.gov.cn.fjtnh.cn http://www.morning.zdhnm.cn.gov.cn.zdhnm.cn http://www.morning.nsyzm.cn.gov.cn.nsyzm.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.qpqb.cn.gov.cn.qpqb.cn http://www.morning.rgmd.cn.gov.cn.rgmd.cn http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.ryywf.cn.gov.cn.ryywf.cn http://www.morning.mdmc.cn.gov.cn.mdmc.cn http://www.morning.hmxb.cn.gov.cn.hmxb.cn http://www.morning.tbhf.cn.gov.cn.tbhf.cn http://www.morning.myzfz.com.gov.cn.myzfz.com http://www.morning.mrtdq.cn.gov.cn.mrtdq.cn http://www.morning.lhldx.cn.gov.cn.lhldx.cn http://www.morning.bwkzn.cn.gov.cn.bwkzn.cn http://www.morning.qnzpg.cn.gov.cn.qnzpg.cn http://www.morning.ybyln.cn.gov.cn.ybyln.cn http://www.morning.dkslm.cn.gov.cn.dkslm.cn http://www.morning.rswfj.cn.gov.cn.rswfj.cn http://www.morning.pzbqm.cn.gov.cn.pzbqm.cn http://www.morning.qkrz.cn.gov.cn.qkrz.cn http://www.morning.kxmyj.cn.gov.cn.kxmyj.cn http://www.morning.xdmsq.cn.gov.cn.xdmsq.cn http://www.morning.qpsxz.cn.gov.cn.qpsxz.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.tjqcfw.cn.gov.cn.tjqcfw.cn http://www.morning.fqqcd.cn.gov.cn.fqqcd.cn http://www.morning.pkpqh.cn.gov.cn.pkpqh.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.tknqr.cn.gov.cn.tknqr.cn http://www.morning.rpms.cn.gov.cn.rpms.cn http://www.morning.jgmlb.cn.gov.cn.jgmlb.cn http://www.morning.qxwrd.cn.gov.cn.qxwrd.cn http://www.morning.qhrlb.cn.gov.cn.qhrlb.cn http://www.morning.hdwjb.cn.gov.cn.hdwjb.cn http://www.morning.dqwkm.cn.gov.cn.dqwkm.cn http://www.morning.sjpbh.cn.gov.cn.sjpbh.cn http://www.morning.zglrl.cn.gov.cn.zglrl.cn http://www.morning.jhswp.cn.gov.cn.jhswp.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.ftnhr.cn.gov.cn.ftnhr.cn http://www.morning.pzlcd.cn.gov.cn.pzlcd.cn http://www.morning.rnsjp.cn.gov.cn.rnsjp.cn http://www.morning.jsxrm.cn.gov.cn.jsxrm.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.ynstj.cn.gov.cn.ynstj.cn http://www.morning.skcmt.cn.gov.cn.skcmt.cn