Cov txheej txheem:

Cia Ua Ib Qhov Kev Pabcuam Ntxiv rau MEMES !: 8 Kauj Ruam
Cia Ua Ib Qhov Kev Pabcuam Ntxiv rau MEMES !: 8 Kauj Ruam

Video: Cia Ua Ib Qhov Kev Pabcuam Ntxiv rau MEMES !: 8 Kauj Ruam

Video: Cia Ua Ib Qhov Kev Pabcuam Ntxiv rau MEMES !: 8 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
Cia Ua Tus App Augmented Reality rau MEMES!
Cia Ua Tus App Augmented Reality rau MEMES!

Hauv Cov Lus Qhia no peb yuav ua kom muaj qhov tseeb app rau Android thiab IOS hauv Unity3D uas siv Google API los tshawb nrhiav memes. Peb yuav siv Vuforia lub dav hlau hauv av tshawb pom hauv Kev Sib Koom yog li lub app mobile no yuav ua haujlwm rau feem ntau Android thiab IOS cov neeg siv. Siv Vuforia tseem yuav tso cai rau peb kom muaj cov duab thau rau hauv ib qho chaw kom peb tuaj yeem taug kev hla daim duab no thiab cov khoom yuav nyob qhov twg lawv nyob.

Peb kuj tseem yuav sim tawm IBM Watson API tshiab yog li peb tuaj yeem ua cov kev tshawb fawb no nrog peb lub suab thiab txhawb nqa lawv cov lus ua haujlwm ib txwm muaj.

Yog li cov xov xwm tsis zoo tsis yog ib qho ntawm API no yog dawb kiag li, tab sis cov xov xwm zoo yog lawv ob leeg tau sim dawb. Google kev cai tshawb nrhiav API muab rau koj 100 qhov kev tshawb fawb dawb ib hnub, thiab IBM Watson API muab rau koj thawj lub hlis dawb.

Hauv ntej, qhov app no yuav tau txais peb cov lus hais los ntawm lub microphone hauv Kev Sib Koom, xa qhov ntawd mus rau IBM Watson servers, uas yuav xa rov tuaj rau peb cov ntawv. Peb yuav nqa cov ntawv ntawd thiab xa nws mus rau Google cov servers uas yuav xa peb cov npe cov duab URL hauv JSON daim ntawv.

Kauj Ruam 1: Teeb IBM Watson SDK hauv Kev Sib Koom

Teeb IBM Watson SDK hauv Kev Sib Koom
Teeb IBM Watson SDK hauv Kev Sib Koom

Txhawm rau kom Watson API mus koj yuav tsum xub tau txais koj daim ntawv pov thawj los ntawm lawv lub xaib. Mus rau Console.bluemix.net, tsim thiab account, thiab nkag mus. Mus rau koj li IBM tus lej nyiaj thiab mus rau huab foundry Orgs thiab tsim qhov chaw tshiab. Tam sim no mus rau koj lub dashboard thiab nyem rau xauj cov kev pabcuam, ntxiv cov lus hais rau cov ntawv pabcuam vim tias yog yam peb yuav siv. Xaiv koj cheeb tsam, koom haum, thiab chaw thiab tsim txoj haujlwm. Tam sim no koj yuav pom koj daim ntawv pov thawj API nyob hauv qab.

Rub tawm Kev Sib Koom yog tias koj tseem tsis tau muaj nws thiab import IBM Watson SDK los ntawm cov khoom muaj nqis hauv Unity. Peb tuaj yeem sim qhov no los ntawm kev tsim cov khoom ua si khoob thiab hu nws IBM Watson thiab ntxiv cov piv txwv streaming tsab ntawv. Tsab ntawv no twb tau teeb tsa los kaw suab los ntawm kev sib koom siab thiab xa nws mus rau Watson servers rau kev ua haujlwm.

Txog tam sim no peb tsuas yog yuav siv cov ntawv piv txwv no vim tias peb muaj ntau yam ntxiv los ua tab sis tej zaum lwm zaus peb tuaj yeem nkag mus tob rau hauv Watson cov khoom vim tias kuv xav ua qee yam nrog Vision API.

Kauj Ruam 2: Xeem Tawm IBM Watson Text to Speech

Xeem Tawm IBM Watson Text to Speech
Xeem Tawm IBM Watson Text to Speech

Tsab ntawv no tab tom nrhiav UI cov khoom ntawv yog li cia peb tsim lub pob UI tshiab qhov no yuav muab cov ntawv uas peb xav tau, peb yuav siv lub pob tom qab. Teem cov canvas kom ntsuas nrog lub vijtsam loj thiab hloov lub pob me ntsis. Thauj tog rau nkoj rau hauv qab sab laug. Luag cov ntawv ntawd rau hauv qhov khoob. Qhib tsab ntawv thiab cia ntxiv peb IBM Watson daim ntawv pov thawj, nrhiav qhov twg "cov txiaj ntsig tau" cov ntawv tau siv thiab teeb nws tsuas yog "alt.transcript" vim tias peb yuav siv cov ntawv no los tshawb hauv google. Tam sim no ua ntej peb tuaj yeem sim qhov no peb yuav tsum ua kom cov ntawv me me zoo li qub txawm li cas los xij peb hais yuav haum rau hauv lub thawv. Rov qab mus rau kab ntawv thiab teeb nws kom haum zoo tshaj plaws. Ntaus hauv qee cov ntawv los sim nws. Tam sim no thaum peb nyem ua si peb cov lus yuav raug xa mus rau cov ntawv los ntawm Watson Text to Speech API.

Kauj Ruam 3: Teeb Google Tus Kheej Tshawb Nrhiav API

Teem Google Google Custom Search API
Teem Google Google Custom Search API

Daim ntawv tom ntej peb yuav tsum tau ua yog tau txais Google kev cai tshawb fawb api teeb tsa los siv hauv Kev Sib Koom. Hauv qib siab peb yuav tau thov HTTP los ntawm Kev Sib Koom rau Google servers uas yuav xa peb cov lus teb hauv JSON hom.

Yog li mus rau Google Custom Search JSON API teeb tsa nplooj ntawv, nyem kom tau tus lej API thiab tsim ib qho app tshiab. Khaws qhov no qhib. Tam sim no peb tuaj yeem mus rau lub vaj huam sib luag tswj. Muab txhua yam rau cov vev xaib los tshawb, npe nws xijpeem, thiab nyem tsim.

Nyem tswj vaj huam sib luag thiab cia ua qee qhov kev hloov kho: peb xav tau tshawb fawb feem ntau, thiab qhib kev tshawb nrhiav duab. Hauv qab cov vev xaib los tshawb nrhiav hloov qhov ntawd rau tag nrho lub vev xaib. Nyem hloov tshiab kom txuag txhua yam.

Tam sim no nrhiav google api explorer thiab mus rau qhov kev cai tshawb fawb API. Qhov no yuav tso cai rau peb los teeb tsa JSON cov lus teb uas peb tau txais los ntawm Google. Yog li muab txhua yam rau cov lus nug tam sim no, muab tshuaj txhuam rau hauv koj daim ntawv tshawb fawb ID, tso 1 rau hauv lub lim dej kom peb tsis txhob rov ua dua, muab tso rau hauv 10 tus lej vim tias yog tus lej siab tshaj plaws ntawm cov txiaj ntsig peb tuaj yeem rov qab los ntawm lub sijhawm, muab tso rau hauv cov duab rau hom tshawb nrhiav vim tias yog txhua yam peb xav rov qab los. Muab 1 rau pib, thiab thaum kawg hauv qab teb muab tso rau hauv "cov khoom/txuas" vim tias rau txhua qhov khoom xa rov qab peb tsuas xav tau cov duab txuas. Tam sim no thaum koj nyem qhov ua tiav koj yuav pom tias peb tau txais 10 daim duab zoo txuas rov qab.

Tam sim no peb yuav tsum tau txais cov duab no rau hauv Unity.

Kauj Ruam 4: Teeb Vuforia hauv Kev Sib Koom

Teeb Vuforia hauv Kev Sib Koom
Teeb Vuforia hauv Kev Sib Koom

Cia peb tau txais Vuforia ua haujlwm yog li peb tuaj yeem siv lawv lub dav hlau tshawb pom hauv av. Txuag koj qhov xwm txheej tam sim no thiab mus rau qhov chaw teeb tsa. Hloov koj lub platform rau Android lossis IOS thiab yog tias koj nyob ntawm IOS tso qee yam rau hauv cov cim cim khoom, ntxiv lub koob yees duab thiab lub microphone siv cov lus piav qhia. Hauv XR teeb tsa kos Vuforia qhov kev txhawb nqa kev muaj tiag txhawb.

Tam sim no hauv qhov chaw tshem tawm lub koob yees duab tseem ceeb thiab ntxiv Vuforia ARCamera. Mus rau ntu teeb tsa thiab hloov hom kev taug qab mus rau qhov chaw. Uncheck tag nrho cov databases ua rau peb tsis xav tau lawv.

Tam sim no ntxiv lub dav hlau nrhiav thiab peb yuav tsum tau hla nws tus cwj pwm vim tias peb xav xa lub dav hlau dav hlau theem ib zaug yog li cia peb pom Kev Tso Tawm Ib Leeg ib zaug sau ntawv ntawm Vuforia lub vev xaib. Nqa tsab ntawv ntawd mus rau Kev Sib Koom thiab muab tso rau ntawm lub dav hlau nrhiav, tshem cov ntawv qub uas nyob ntawd. Hloov hom kev sib tham sib tham thiab xyuas kom tseeb tias "OnInteractiveHitTest" muaj nuj nqi tau hu rau qhov kev tshwm sim Unity. Thaum peb nyob ntawm no cia teeb lub pob uas peb tau ua dhau los ua haujlwm thaum peb tau pom lub dav hlau hauv av, teeb tsa nws lub xeev tsis raug rau qhov tsis ua haujlwm. Tam sim no muab lub dav hlau hauv av tso rau hauv qhov chaw thiab hloov nws mus rau nruab nrab cua vim tias peb xav kom txhua daim duab ntab hauv huab cua. Luag lub dav hlau av no rau hauv qhov khoob ntawm lub dav hlau nrhiav.

Kauj Ruam 5: Tsim Daim Duab Ua Ntej

Tsim ib daim duab Prefab
Tsim ib daim duab Prefab

Ua ntej peb pib muab txhua daim no ua ke peb xav tau los tsim cov khoom ua si ua ntej uas peb tuaj yeem hloov kho txhua lub sijhawm rub daim duab. Yog li tsim qhov khoom ua si khoob hauv qab theem dav hlau hauv av thiab hu nws "picPrefab". Tsim lub quad raws li menyuam yaus ntawm qhov ntawd thiab ntsuas nws los ntawm 2, tig nws y los ntawm 180 degrees kom cov niam txiv mus rau tom ntej vector uas tau qhia ua tus xub xiav yog lub hauv ntej ntawm plaub fab.

Tsim tsab ntawv tshiab hu ua "PictureBehavior" thiab ntxiv nws rau peb picPrefab.

Tam sim no rub daim duab no ua ntej rau hauv koj li khoom muaj nqis thiab qhov no yog qhov peb yuav muab txhua daim duab rau.

Peb tsab ntawv "PictureBehavior" yuav tsum zoo li no:

siv System. Collections;

siv System. Collections. Generic; siv UnityEngine; pej xeem chav PictureBehavior: MonoBehaviour {public Renderer quadRenderer; ntiag tug Vector3 xav tauPosition; void Pib () {// saib lub koob yees duab hloov pauv. LookAt (Camera.main.transform); Vector3 ntshawAngle = Vector3 tshiab (0, transform.localEulerAngles.y, 0); transform.rotation = Quaternion. Euler (xav tau Angle); // quab yuam rau hauv huab cua DesirePosition = transform.localPosition; transform.localPosition += tshiab Vector3 (0, 20, 0); } void Hloov tshiab () {transform.localPosition = Vector3. Lerp (transform.localPosition, xav tauPosition, Time.deltaTime * 4f); } pej xeem void LoadImage (hlua url) {StartCoroutine (LoadImageFromURL (url)); } IEnumerator LoadImageFromURL (hlua url) {WWW www = tshiab WWW (url); yield rov qab www; quadRenderer.material.mainTexture = www.texture; }}

Kauj Ruam 6: Tsim Tsab Ntawv rau Google API

Tsim Tsab Ntawv rau Google API
Tsim Tsab Ntawv rau Google API

Tam sim no cia rub hauv qhov siv rau plaub tus neeg ua haujlwm los ntawm peb "picPrefab".

Peb tsuas muaj ob tsab ntawv sau ua, yog li cia tsim C# tsab ntawv hu ua GoogleService.cs thiab PictureFactroy.cs.

Sab hauv "GoogleService" muab cov cai no uas ua rau peb thov:

siv System. Collections;

siv System. Collections. Generic; siv UnityEngine; siv UnityEngine. UI; pej xeem hauv GoogleService: MonoBehaviour {public PictureFactory pictureFactory; pej xeem ntawv khawmText; private const string API_KEY = "PUT API KEY NTAWM NO !!!!!"; pej xeem tsis muaj dab tsi GetPictures () {StartCoroutine (PictureRoutine ()); } IEnumerator PictureRoutine () {buttonText.transform.parent.gameObject. SetActive (cuav); txoj kab lus nug = buttonText.text; nug = WWW. EscapeURL (nug + "memes"); // rho tawm cov duab qub qub pictureFactory. DeleteOldPictures (); // txuag lub koob yees duab rau pem hauv ntej vector yog li peb tuaj yeem txav mus los thaum cov khoom raug tso Vector3 cameraForward = Camera.main.transform.forward; // peb tsuas tuaj yeem tau txais 10 qhov txiaj ntsig ntawm ib lub sijhawm yog li peb yuav tsum rov ua dua thiab txuag peb qhov kev hloov pauv tus lej pib tom qab txhua 10 int rowNum = 1; rau (int i = 1; i <= 60; i + = 10) {string url = "https://www.googleapis.com/customsearch/v1?q=" + query + "& cx = 011535004225295624669%3Afeb1gwic6bs & filter = 1 & num = 10 & searchType = image & start = " + i +" & fields = items%2Flink & key = " + API_KEY; WWW www = WWW tshiab (url); yield rov qab www; pictureFactory. CreateImages (ParseResponse (www.text), rowNum, cameraForward); rowNum ++; } tawm los rov qab WaitForSeconds tshiab (5f); buttonText.transform.parent.gameObject. SetActive (muaj tseeb); } Sau ParseResponse (kab ntawv kab lus) {Sau urlList = Tshiab Sau (); hlua urls = text. Split ('\ n'); foreach (txoj kab kab hauv urls) {yog (kab ntawv Kabontains ("txuas")) {hlua url = kab. Substring (12, kab. Length-13); // lim los ntawm png lossis jpg zoo li tsis ua haujlwm los ntawm Google yog li peb ua ntawm no: yog (url. Contains (".jpg") || url. Contains (".png")) {urlList. Add (url); }}} rov qab urlList; }}

Kauj Ruam 7: Tsim Peb Cov Duab Duab

Tsim Peb Lub Hoobkas Duab
Tsim Peb Lub Hoobkas Duab

Sab hauv PictureFactory.cs tso cov cai no los tsim txhua yam ntawm peb cov duab thiab thauj lawv cov ntawv los ntawm URL.

siv System. Collections;

siv System. Collections. Generic; siv UnityEngine; chav kawm pej xeem PictureFactory: MonoBehaviour {pej xeem GameObject picPrefab; pej xeem GoogleService googleService; pej xeem tsis muaj dab tsi DeleteOldPictures () {yog (transform.childCount> 0) {foreach (Hloov tus menyuam hauv qhov no.transform) {Ua kom puas (child.gameObject); }}} pej xeem void CreateImages (ListurlList, int resultNum, Vector3 camForward) {int picNum = 1; Vector3 chaw = Camera.main.transform.position; foreach (hlua url hauv urlList) {Vector3 pos = GetPosition (picNum, resultNum, camForward); GameObject pic = Instantiate (picPrefab, pos, Quaternion.identity, this.transform); pic. GetComponent (). LoadImage (url); picNum ++; }} Vector3 GetPosition (int picNum, int rowNum, Vector3 camForward) {Vector3 pos = Vector3.zero; yog (picNum <= 5) {pos = camForward + Vector3 tshiab (picNum * -3, 0, rowNum * 3.5f); } lwm {pos = camForward + Vector3 tshiab ((picNum % 5) * 3, 0, rowNum * 3.5f); } rov qab pos; }}

Kauj Ruam 8: Peb Ua Tiav

Peb Ua Tiav lawm!
Peb Ua Tiav lawm!
Peb Ua Tiav!
Peb Ua Tiav!

Tsim gameobject khoob hu ua GoogleService thiab muab cov ntawv "GoogleSerivice" rau nws.

Drag tsab ntawv "PictureFactory" mus rau theem dav hlau hauv av vim tias tag nrho peb cov duab yuav raug tsim los ua menyuam yaus ntawm cov khoom ua si no.

Luag cov ntaub ntawv tsim nyog hauv tus kws tshuaj xyuas, ua tib yam rau kev pabcuam google.

Qhov kawg uas peb yuav tsum tau ua yog ua kom ntseeg tau tias peb "GetPictures" muaj nuj nqi. Yog li cia mus rau "onClick" qhov xwm txheej ntawm peb lub pob thiab hu nws los ntawm qhov ntawd.

Tam sim no peb tuaj yeem nyem ua si thiab sim qhov no. Nco ntsoov qhib lub dav hlau theem theem thiab khawm. Hais ib lo lus, thiab nyem lub pob kom ua qhov kev tshawb fawb ntawm cov ntawv ntawd!

Tam sim no kom tau cov app no ntawm koj lub xov tooj, ntsaws nws thiab mus rau File-> Build Settings. Ntaus tsim thiab khiav!

Qhia rau kuv paub hauv cov lus yog tias koj muaj lus nug!

Pom zoo: