




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
Unity3D調用攝像頭加載到場景中代碼Postedon2013年04月10日byU3d/\o"查看Unity3D腳本/插件中的全部文章"Unity3D腳本/插件/被圍觀300次Unity3D調用攝像頭加載到場景中代碼如下:usingUnityEngine;
usingSystem.Collections;
usingSystem.IO;
publicclassCameraController:MonoBehaviour{
publicstringdeviceName;
publicWebCamTexturewebTex;
publicGameObjectobjCameraController;
publicGameObjectobjAvatar;
publicGameObjectImgAtlas;
publicstringstrTempTime="";
//Usethisforinitialization
voidStart(){}//Updateiscalledonceperframe
voidUpdate(){
if(strTempTime!="")
{
//GameObject.Find("pig5").GetComponent().mainTexture=Resources.Load(strTempTime.ToString(),typeof(Texture))asTexture;
//print("44444:"+strTempTime);
}}
///
///調用攝像機
///
///
IEnumeratorCallTheCamera()
{
yieldreturnApplication.RequestUserAuthorization(UserAuthorization.WebCam);
if(Application.HasUserAuthorization(UserAuthorization.WebCam))
{
WebCamDevice[]devices=WebCamTexture.devices;
deviceName=devices[0].name;
//攝像機攝像的區(qū)域
webTex=newWebCamTexture(deviceName,400,300,-112);
GameObject.Find("CameraTexture").GetComponent().mainTexture=webTex;
webTex.Play();
}
}
///
///獲取并保存texture
///
///
IEnumeratorGetTexture2D()
{
print(GameObject.Find("CameraTexture").transform.localPosition);
yieldreturnnewWaitForEndOfFrame();
Texture2Dt=newTexture2D(GameObject.Find("CameraTexture").GetComponent().mainTexture.width,GameObject.Find("CameraTexture").GetComponent().mainTexture.height);
t.ReadPixels(newRect(15,177,406.5f,281.6f),0,0,false);
t.Apply();
//把圖片數(shù)據(jù)轉換為byte數(shù)組
byte[]byt=t.EncodeToPNG();
//然后保存為圖片
strTempTime=Time.time.ToString();
print("11111:"+strTempTime);
File.WriteAllBytes(Application.dataPath+"/Resources/"+strTempTime+".jpg",byt);
print("22222"+strTempTime);
//GameObjectatlasPrefab=Resources.Load("TempAtlas")asGameObject;
//Instantiate(ImgAtlas)asGameObject;
//tempA.GetComponent().spriteList.Add(
//
UnityEditor.AssetDatabase.Refresh();
//yieldreturnnewWaitForSeconds(1);
GameObject.Find("pig5").GetComponent().mainTexture=Resources.Load(strTempTime.ToString(),typeof(Texture))asTexture;
print("33333"+strTempTime);
//NGUITools.AddSprite(tempA,tempA.GetComponent(),"tempSprite");
//UIAtlasatlas=(Instantiate(ImgAtlas)asGameObject).GetComponent();
//Texturetext=Resources.Load(Application.dataPath+"/Resources/"+strTempTime+".jpg",typeof(Texture))asTexture;
//print(atlas.ToString());
//UISlicedSpritessprite=NGUITools.AddWidget(Game);
//GameObject.Find("pig5").GetComponent().s
//UIAtlasatlas=Resources.Load(Application.dataPath+"/test/"+"CameraAtlas",typeof(UIAtlas))asUIAtlas;
//print(atlas.ToString());
//objAvatar.GetComponent().spriteName=;//this.gameObject.GetComponent().spriteName;
//objCameraController.SetActive(false);
}
voidCameraStart()
{
StartCoroutine("CallTheCamera");
}
voidCameraSStart()
{
StartCoroutine("GetTextur
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 班級班委會的建設與培養(yǎng)計劃
- 企業(yè)安全文化建設與保安工作關系計劃
- 工作計劃與目標達成的關系
- 生物催化過程優(yōu)化與控制的原則
- 2025年內(nèi)螺紋銅管項目合作計劃書
- 餐飲行業(yè)供應鏈優(yōu)化解決方案協(xié)議
- Soyasaponin-Aa-Standard-生命科學試劑-MCE
- 2-Hydroxy-atrazine-Standard-生命科學試劑-MCE
- 私人醫(yī)生健康管理服務合同
- 小學高年級語文寫作技巧征文
- 杭州市淳安縣國有企業(yè)招聘筆試真題2024
- 安徽省蕪湖市2024-2025學年第一學期期末考試七年級語文試卷(含答案)
- 2024年花盆市場分析現(xiàn)狀
- 2025山東省退役軍人事務廳所屬事業(yè)單位招聘人員歷年高頻重點提升(共500題)附帶答案詳解
- 2025年道路貨運駕駛員從業(yè)資格證模擬考試題
- 數(shù)學-安徽省皖南八校2025屆高三上學期12月第二次大聯(lián)考試題和答案
- 退市新規(guī)解讀-上海證券交易所、大同證券
- 教育部中國特色學徒制課題:現(xiàn)代職業(yè)教育體系建設背景下中國特色學徒制治理體系與資源配置研究
- 融資報告范文模板
- 桃李面包盈利能力探析案例11000字
- 護理工作十四五規(guī)劃
評論
0/150
提交評論