电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

调用摄像头加载到场景中代码

调用摄像头加载到场景中代码_第1页
1/4
调用摄像头加载到场景中代码_第2页
2/4
调用摄像头加载到场景中代码_第3页
3/4
Unity3D 调用摄像头加载到场景中代码 Posted on 2025 年 04 月 10 日 by U3d / Unity3D 脚本/插件/被围观 300 次 Unity3D 调用摄像头加载到场景中代码如下:using UnityEngine;using System.Collections;using System.IO;public class CameraController : MonoBehaviour {public string deviceName;public WebCamTexture webTex;public GameObject objCameraController;public GameObject objAvatar;public GameObject ImgAtlas;public string strTempTime="";// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {if(strTempTime!=""){// GameObject.Find("pig5").GetComponent().mainTexture = Resources.Load(strTempTime.ToString(), typeof(Texture)) as Texture;// print("44444:"+strTempTime);}}////// 调用摄像机//////IEnumerator CallTheCamera(){yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);if(Application.HasUserAuthorization(UserAuthorization.WebCam)){WebCamDevice[] devices = WebCamTexture.devices;deviceName = devices[0].name;//摄像机摄像的区域webTex = new WebCamTexture(deviceName, 400, 300, -112);GameObject.Find("CameraTexture").GetComponent().mainTexture = webTex;webTex.Play();}}////// 猎取并保存 texture//////IEnumerator GetTexture2D(){print(GameObject.Find("CameraTexture").transform.localPosition);yield return new WaitForEndOfFrame();Texture2D t = new Texture2D(GameObject.Find("CameraTexture").GetComponent().mainTexture.width, GameObject.Find("CameraTexture").GetComponent().mainTexture.height);t.ReadPixels(new Rect(15, 177, 406.5f, 281.6f), 0, 0, false);t.Apply();//把图片数据转换为 byte 数组byte[] byt = t.EncodeToPNG();//然后保存为图片strTempTime = Time.time.ToString();print("11111:"+strTempTime);File.WriteAllBytes(Application.dataPath + "/Resources/" + strTempTime + ".jpg", byt);print("22222"+strTempTime);//GameObject atlasPrefab = Resources.Load("TempAtlas") as GameObject;// Instantiate(ImgAtlas) as GameObject;// tem...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

调用摄像头加载到场景中代码

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部