Mundarija:
- 1 -qadam: Yangi birlik loyihasini boshlang
- 2 -qadam: sahnani sozlash
- 3 -qadam: Keling, bir nechta zarrachalar tayyorlaylik
- 4 -qadam: zarrachalarni sekinlashtirish
- 5 -qadam: Portal yaratish
- 6 -qadam: zarrachalar shaderlari
- 7 -qadam: Skybox -ni yarating
- 8 -qadam: Portal mantig'i
- 9 -qadam: deyarli bajarildi
- 10 -qadam: Ilovani telefoningizga qo'ying
Video: AR portali notanish narsalardan tepaga: 10 qadam (rasmlar bilan)
2025 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2025-01-13 06:58
Bu ko'rsatma iPhone uchun kengaytirilgan reallik mobil ilovasini yaratish orqali o'tadi, u portali begona narsalarning teskarisiga olib keladi. Siz portalning ichiga kirishingiz, aylanib chiqishingiz va orqaga qaytishingiz mumkin. Portal ichidagi hamma narsani faqat siz kirmaguningizcha portal orqali ko'rish mumkin. Haqiqiy dunyoga qaytmaguningizcha, hamma narsa hamma joyda bo'ladi. Biz Apple ARKit plaginli Unity 3D video o'yin dvigatelidan foydalanamiz. Biz ishlatadigan barcha dasturiy ta'minotni bepul yuklab olish va ishlatish mumkin. Sizni kuzatib borish uchun mutaxassis bo'lish shart emas, biz har qadamni bosib o'tamiz!
1 -qadam: Yangi birlik loyihasini boshlang
Birinchidan, Unity3D -ni yuklab oling va IOS platformasi uchun tuzilgan fayllarni o'rnatganingizga ishonch hosil qiling. Bundan tashqari, Xcode -ni yuklab olishingiz va bepul olma ishlab chiqaruvchisi hisobiga ro'yxatdan o'tishingiz kerak bo'ladi. Sizning iPhone -da IOS 11 yoki undan yuqori versiyasi bo'lishi kerak. 2018 yil 5 -fevraldan boshlab IOS 11.3 ishlamayapti, lekin xCode 9.2 -da hali qo'llab -quvvatlovchi fayllar yo'q. Agar siz IOS -ning eng yangi versiyasini ishlatayotgan bo'lsangiz, Apple. Developer.com saytidan Xcode -ning so'nggi beta -versiyasini yuklab oling.
Barcha kerakli dasturlarga ega bo'lgandan so'ng, Unity -ni oching va yangi loyihani boshlang, xohlagan narsangizga qo'ng'iroq qiling. Bizga Apple ARKit plagini kerak bo'ladi, shunda biz telefon kameramiz yordamida erdagi ob'ektlarni erga aniqlay olamiz. Keling, buni aktivlar do'koni yorlig'iga o'ting va "ARKit" ni qidirib import qilaylik. Agar sizda hali yo'q bo'lsa, Unity -ning bepul hisobini yaratishingiz kerak bo'ladi, keyin plaginni olish uchun import -ni bosing.
ARKit papkasidagi misollar papkasiga o'ting va "UnityARKitScene" ni toping. Uni ochish uchun uni ikki marta bosing. Biz bu sahnani boshlanish nuqtasi sifatida ishlatamiz va shu erdan quramiz. Odatiy bo'lib, bu sahna sizga erni aniqlash imkonini beradi va ekranga teginganda, o'sha joyga kub qo'yiladi.
Keling, avval tuzilish sozlamalarini to'rtburchaklar qilib olamiz, shuning uchun keyinroq qilishni unutmaymiz. Faylni bosing, sozlamalarni yarating va ro'yxatdagi barcha sahnalarni olib tashlang. Hozirgi sahnani qo'shish uchun ochiq sahnalarni qo'shish -ni bosing. Bu erda sozlashimiz kerak bo'lgan oxirgi narsa - bu o'yinchi sozlamalarida to'plam identifikatoriga o'ting va bu satrning formati com. YourCompanyName. YourAppName, shuning uchun men mening holimda com. MatthewHallberg. PortalTest kabi ish qilaman.
2 -qadam: sahnani sozlash
Avval chapga qarang va "GeneratePlanes" deb nomlangan o'yin ob'ektini toping. Belgilangan bo'lsa, hozir o'ng tomonga qarang va uni o'chirish uchun katakchani bosing. Shunday qilib, bizda ARKit quruqlikdagi samolyotni aniqlaganda, ko'k rangli kvadratchalar paydo bo'lmaydi. Keyin "RandomCube" o'yin ob'ektini o'chirib tashlang, chunki biz buni bizning sahnamizda ko'rishni xohlamaymiz.
Endi biz birinchi navbatda portalimiz eshigini yaratishimiz kerak. "HitCubeParent" bolasi bo'lgan kubni o'chirib tashlang. O'ng tugmachani bosing va bo'sh o'yin ob'ektini tanlang. Uning nomini "Portal" deb o'zgartiring. Endi sichqonchaning o'ng tugmachasini bosing va kub yarating, bu uni portalning bolasi qiladi. Uni "PostLeft" deb o'zgartiring va bu bizning portalimizning chap posti bo'ladi. X ni 1, y ni 28, z ni bitta qilib o'lchab ko'ring. To'g'ri post uchun ham xuddi shunday qiling. Endi ustki ustunni yarating va y ni 14 ga o'lchang. Bu tomonga burilib, boshqa ustunlarni bog'laydigan qilib harakatlantiring. Portalning butun o'lchamini 1,3 x 1,4 x 1 qilib qo'ying.
Google -ga kiring va yog'och yoki po'stloq to'qimasini kiriting. Ushbu rasmlardan birini yuklab oling va uni Unity -dagi aktivlar papkasiga torting. Endi bu rasmni portaldagi barcha postlarga suring.
"Portal" ob'ektini yana bosing va o'ngdagi komponentani qo'shish -ni bosing. Unga "UnityARHitTestExample" skriptini qo'shing. U erda "Hit Transform" uchun bo'sh uyasi bor, "HitCubeParent" ob'ektini bu uyaga torting.
3 -qadam: Keling, bir nechta zarrachalar tayyorlaylik
Endi biz portalning ichida tutun va suzuvchi zarracha effektini yaratish uchun "Birlik zarrachalari" tizimidan foydalanmoqchimiz. Yuqori menyu satridagi aktivlar, standart aktivlar va zarrachalar tizimini import qilish -ga o'ting.
Portalingizda ikkita bo'sh o'yin ob'ektini yarating va birini "SmokeParticles", ikkinchisini "FloatingParticles" deb nomlang.
Tutun zarralariga zarrachalar tizimi komponentini qo'shing.
Ushbu komponentda bir nechta variant bor, lekin biz faqat er -xotinni o'zgartirishimiz kerak.
Boshlanish rangini taxminan 50% shaffoflik bilan quyuq ko'k rangga o'zgartiring. Chiqarish tezligini 100. Ichki shaklda, radiusni hosil qiling.01. Pastki qismdagi renderer qismida min o'lchamini.8 ga, maksimal hajmini 5 ga o'zgartiring. Materiallar komponentidan faqat tutun materialini ro'yxatdan tanlang, lekin biz buni keyinroq o'zgartiramiz.
O'zgaruvchan zarrachalar o'yin ob'ektiga zarrachalar tizimini hozir qo'shing va emissiyani 500 ga o'rnating. Boshlanish muddatini 2 ga, radiusini 10 ga, zarrachalarning minimal hajmini.01 ga va maksimal zarracha hajmini.015 ga sozlang. Hozircha materialni asosiy zarrachaga o'rnating.
Oxir -oqibat ikkala o'yin ob'ektini oling va ularni x -ga 90 gradusga aylantiring va havoga ko'taring, shunda ular portal eshigiga tushadi.
4 -qadam: zarrachalarni sekinlashtirish
Biz bu zarrachalarning katta maydonni qamrab olishini xohlaganimiz uchun, lekin sekin harakat qilsak, biz o'z namunaviy funktsiyamizni yaratishimiz kerak. Shunday qilib, aktivlar papkasini o'ng tugmasini bosing va yangi C# skriptini yarating va uni "ParticleSample" deb nomlang. Ushbu kodni nusxalash va joylashtirish:
System. Collections -dan foydalanish;
System. Collections. Generic -dan foydalanish; UnityEngine -dan foydalanish; umumiy sinf ParticleSample: MonoBehaviour {private ParticleSystem ps; // Buni ishga tushirish uchun foydalaning void Start () {ps = GetComponent (); StartCoroutine (SampleParticleRoutine ()); } IEnumerator SampleParticleRoutine () {var main = ps.main; main.simulationSpeed = 1000f; ps. Play (); rentabellik yangi WaitForSeconds (.1f); main.simulationSpeed =.05f; }}
Endi bu skriptni zarrachalar tizimi o'yinlarining har bir ob'ektiga torting.
5 -qadam: Portal yaratish
Endi biz portalni yaratishimiz kerak, shuning uchun portali o'yin ob'ektini o'ng tugmasini bosing va to'rtburchak yarating. To'rtburchakni butun portalni qamrab oladigan qilib o'lchang, bu bizning portal oynamizga aylanadi. Biz qo'shishimiz kerak bo'lgan birinchi narsa bu portal shader, bu faqat ob'ektlarni boshqa maxsus shader bilan ko'rsatadi. Aktivlar papkasida sichqonchaning o'ng tugmachasini bosing va o'chmagan yangi shader yarating. U erda hamma narsani olib tashlang va ushbu kodga joylashtiring:
Shader "Portal/portal oynasi"
{SubShader {Colormask -dan Zwrite 0 Stencil o'chiriladi {Ref 1 Pass o'rniga} Pass {}}}
Ierarxiyada sichqonchaning o'ng tugmachasini bosing va yangi material yarating, uni PortalWindowMat deb nomlang, ochiladigan ro'yxatda portal bo'limini toping va portal oynasini tanlang. Ushbu materialni portalning to'rtburchagiga torting.
6 -qadam: zarrachalar shaderlari
Aktivlar papkasini yana o'ng tugmasini bosing va yangi shader yarating. Biz portal ichiga kiradigan zarrachalar uchun shaderlarni yasashimiz kerak. Barcha kodni shu bilan almashtiring:
Shader "Portal/zarrachalar" {
Xususiyatlari {_TintColor ("Rang rangi", Rang) = (0.5, 0.5, 0.5, 0.5) _MainTex ("Zarracha to'qimasi", 2D) = "oq" {} _InvFade ("Yumshoq zarrachalar omili", diapazoni (0.01, 3.0)) = 1.0 _Stencil ("stencil", int) = 6} Category {Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane"}) SrcAlpha OneMinusSrcAlpha aralashmasi ColorMask RGB yoritishni o'chiradi sobit4 _TintColor; struktura appdata_t {float4 vertex: POSITION; sobit4 rang: COLOR; float2 texcoord: TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID}; v2f strukturasi {float4 vertex: SV_POSITION; sobit4 rang: COLOR; float2 texcoord: TEXCOORD0; UNITY_FOG_COORDS (1) #ifdef SOFTPARTICLES_ON float4 projPos: TEXCOORD2; #endif UNITY_VERTEX_OUTPUT_STEREO}; float4 _MainTex_ST; v2f vert (appdata_t v) {v2f o; UNITY_SETUP_INSTANCE_ID (v); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO (o); o.vertex = UnityObjectToClipPos (v.vertex); #ifdef SOFTPARTICLES_ON o.projPos = ComputeScreenPos (o.vertex); COMPUTE_EYEDEPTH (o.projPos.z); #endif o.color = v.color * _TintColor; o.texcoord = TRANSFORM_TEX (v.texcoord, _MainTex); UNITY_TRANSFER_FOG (o, o. vertex); qaytish o; } UNITY_DECLARE_DEPTH_TEXTURE (_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i): SV_Target {#ifdef SOFTPARTICLES_ON float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ (_CameraDepthTexture, UNITY_PROJ_COORD (i.projPos)))); suzuvchi qismZ = i.projPos.z; float fade = to'yingan (_InvFade * (sceneZ-partZ)); i.color.a *= xira; #endif fixed4 col = 2.0f * i.color * tex2D (_MainTex, i.texcoord); UNITY_APPLY_FOG (i.fogCoord, col); qaytariladigan ustun; } ENDCG}}}}
Portalsmoke va portalParticles deb nomlangan ikkita yangi material yarating.
Har bir kishi uchun bu shaderni tanlang, ochiladigan qismdan, zarralardan. Tutun zarralari uchun tutun tuzilishi, zarrachalar uchun esa zarracha tuzilishi tanlanadi. Tutunning rangini taxminan 50% shaffoflik bilan quyuq ko'k rangga o'zgartiring. Portalingizdagi har bir zarracha tizimining render komponentasiga o'ting va biz yaratgan tegishli materiallarni tanlang.
7 -qadam: Skybox -ni yarating
Haqiqatan ham teskari ko'rinishni yaratish uchun biz hamma narsani quyuq ko'k rangga bo'yashimiz kerak. Buning uchun biz shaffof osmon qutisini ishlatamiz, shuning uchun yangi shader yarating va ushbu kodga joylashtiring:
Shader "Portal/portalSkybox" {
Xususiyatlari {_Tint ("Tint rangi", Rang) = (.5,.5,.5,.5) [Gamma] _Exposure ("Ta'sir qilish", diapazon (0, 8)) = 1.0 _Rotatsiya ("Burilish", Range) (0, 360)) = 0 [NoScaleOffset] _Tex ("Cubemap (HDR)", Cube) = "kulrang" {} _Stencil ("StencilNum", int) = 6} SubShader {Teglar {"Navbat" = "Fon" "RenderType" = "Orqa fon" "PreviewType" = "Skybox"} ZWrite o'chirilgan aralashmani o'chirib qo'ying SrcAlpha OneMinusSrcAlpha Stencil {Ref 1 Comp [_Stencil]} Pass {CGPROGRAM #pragma vertex vert #pragma fragment fragment #pragma "Ung 2.0Gince.cginc "samplerCUBE _Tex; yarim4 _Tex_HDR; half4 _Tint; yarim _ ta'sir qilish; float _Rotation; float3 RotateAroundYInDegrees (float3 tepa, suzuvchi darajalar) {float alfa = darajalar * UNITY_PI / 180.0; float sina, cosa; Sincos (alfa, sina, kosa); float2x2 m = float2x2 (cosa, -sina, sina, cosa); qaytish float3 (mul (m, vertex.xz), vertex.y).xzy; } appdata_t tuzilishi {float4 vertex: POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID}; v2f strukturasi {float4 vertex: SV_POSITION; float3 texcoord: TEXCOORD0; UNITY_VERTEX_OUTPUT_STEREO}; v2f vert (appdata_t v) {v2f o; UNITY_SETUP_INSTANCE_ID (v); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO (o); float3 rotated = RotateAroundYInDegrees (v.vertex, _Rotation); o.vertex = UnityObjectToClipPos (aylantirildi); o.texcoord = v.vertex.xyz; qaytish o; } fixed4 frag (v2f i): SV_Target {half4 tex = texCUBE (_Tex, i.texcoord); yarim3 c = DecodeHDR (tex, _Tex_HDR); c = c * _Tint.rgb * birlik_ColorSpaceDouble.rgb; c *= _ ta'sir qilish; yarimni qaytarish4 (c,.5); } ENDCG}} Orqaga qaytish}
Endi yangi Skybox materialini yarating, uni "PortalSkybox" deb nomlang va portal menyusidan portalSkybox shaderini tanlang. Yuqoridagi "Deraza, yorug'lik" bo'limiga o'ting va biz yaratgan osmon qutisini tanlang. Asosiy kameraga o'ting va osmon qutisiga aniq bayroqlarni o'rnating. Bu erda bo'lganimizda, biz to'qnashuvlarni aniqlash uchun kameramizga ba'zi komponentlarni qo'shishga ruxsat beramiz. Kameraga qattiq korpus komponentasini qo'shing va tortishish kuchi belgisini olib tashlang. Qutiga kollayder qo'shing va tetikni tekshiring. Qutini yig'uvchilarni o'lchami.5 x 1 x 4. Kameradagi kesish tekisligini.01 ga o'rnating.
8 -qadam: Portal mantig'i
Biz qilishimiz kerak bo'lgan oxirgi narsa - bu portalimizni boshqaradigan mantiqni yaratish. Yangi C# skriptini yarating va uni PortalController deb nomlang.
System. Collections -dan foydalanish;
System. Collections. Generic -dan foydalanish; UnityEngine -dan foydalanish; nomlar maydoni UnityEngine. XR.iOS {PortalController umumiy klassi: MonoBehaviour {Public Material materiallari; ommaviy MeshRenderer meshRenderer; ommaviy UnityARVideo UnityARVideo; private bool isInside = false; private bool isOutside = true; // Buni ishga tushirish uchun ishlating void Start () {OutsidePortal (); } void OnTriggerStay (Collider col) {Vector3 playerPos = Camera.main.transform.position + Camera.main.transform.forward * (Camera.main.nearClipPlane * 4); if (transform. InverseTransformPoint (playerPos).z <= 0) {if (isOutside) {isOutside = false; isInside = rost; InsidePortal (); }} else {if (isInside) {isInside = false; isOutside = rost; OutsidePortal (); }}} void OutsidePortal () {StartCoroutine (DelayChangeMat (3)); } void InsidePortal () {StartCoroutine (DelayChangeMat (6))); } IEnumerator DelayChangeMat (int stencilNum) {UnityARVideo.shouldRender = false; rentabellikni qaytarish yangi WaitForEndOfFrame (); meshRenderer.enabled = noto'g'ri; foreach (Materiallardagi material mat) {mat. SetInt ("_Stencil", stencilNum); } rentabellik qaytarish yangi WaitForEndOfFrame (); meshRenderer.enabled = rost; UnityARVideo.shouldRender = rost; }}}
Ushbu yangi skriptni portal oynasiga torting. Bu bizning kameramizdagi to'qnashuv portali oynasi bilan to'qnashganda, bizni portalga kirgizadi va chiqaradi. Endi barcha materiallarni o'zgartiradigan funktsiyada biz ARkit plaginiga ramkani ko'rsatmaslikni aytamiz, shuning uchun asosiy kameraga o'ting va UnityARVideo skriptini oching. Umumiy bool yaratish kerak OnPreRender () funktsiyasida hamma narsani if iborasiga o'rab qo'ying, u erda hamma narsa faqat shouldRender rost bo'lsa bajariladi. Butun skript shunday bo'lishi kerak:
tizimdan foydalanish;
System. Runtime. InteropServices -dan foydalanish; UnityEngine -dan foydalanish; UnityEngine. Rendering -dan foydalanish; nomlar maydoni UnityEngine. XR.iOS {umumiy sinf UnityARVideo: MonoBehaviour {ommaviy Materiallar m_ClearMaterial; [HideInInspector] public bool shouldRender = true; shaxsiy CommandBuffer m_VideoCommandBuffer; xususiy Texture2D _videoTextureY; xususiy Texture2D _videoTextureCbCr; Maxsus Matrix4x4 _displayTransform; private bool bCommandBufferInitialized; public void Start () {UnityARSessionNativeInterface. ARFrameUpdatedEvent += UpdateFrame; bCommandBufferInitialized = noto'g'ri; } UpdateFrame (UnityARCamera kamerasi) bekor qilingan {_displayTransform = yangi Matrix4x4 (); _displayTransform. SetColumn (0, cam.displayTransform.column0); _displayTransform. SetColumn (1, cam.displayTransform.column1); _displayTransform. SetColumn (2, cam.displayTransform.column2); _displayTransform. SetColumn (3, cam.displayTransform.column3); } void InitializeCommandBuffer () {m_VideoCommandBuffer = new CommandBuffer (); m_VideoCommandBuffer. Blit (null, BuiltinRenderTextureType. CurrentActive, m_ClearMaterial); GetComponent (). AddCommandBuffer (CameraEvent. BeforeForwardOpaque, m_VideoCommandBuffer); bCommandBufferInitialized = rost; } void OnDestroy () {GetComponent (). RemoveCommandBuffer (CameraEvent. BeforeForwardOpaque, m_VideoCommandBuffer); UnityARSessionNativeInterface. ARFrameUpdatedEvent -= UpdateFrame; bCommandBufferInitialized = noto'g'ri; } #if! UNITY_EDITOR public void OnPreRender () {if (shouldRender) {ARTextureHandles handles = UnityARSessionNativeInterface. GetARSessionNativeInterface (). GetARVideoTextureHandles (); if (handles.textureY == System. IntPtr. Zero || handles.textureCbCr == System. IntPtr. Zero) {qaytish; } if (! bCommandBufferInitialized) {InitializeCommandBuffer (); } Ruxsat berish currentResolution = Screen.currentResolution; // Y teksturasi, agar (_videoTextureY == null) {_videoTextureY = Texture2D. CreateExternalTexture (currentResolution.width, currentResolution.height, TextureFormat. R8, false, false, (System. IntPtr) handles.textureY); _videoTextureY.filterMode = FilterMode. Bilinear; _videoTextureY.wrapMode = TextureWrapMode. Repeat; m_ClearMaterial. SetTexture ("_ textureY", _videoTextureY); } // Tekstura CbCr if (_videoTextureCbCr == null) {_videoTextureCbCr = Texture2D. CreateExternalTexture (currentResolution.width, currentResolution.height, TextureFormat. RG16, false, false, (System. IntPtr) handles.textureCb) _videoTextureCbCr.filterMode = FilterMode. Bilinear; _videoTextureCbCr.wrapMode = TextureWrapMode. Repeat; m_ClearMaterial. SetTexture ("_ textureCbCr", _videoTextureCbCr); } _videoTextureY. UpdateExternalTexture (handles.textureY); _videoTextureCbCr. UpdateExternalTexture (handles.textureCbCr); m_ClearMaterial. SetMatrix ("_ DisplayTransform", _displayTransform); }} #else public void SetYTexure (Texture2D YTex) {_videoTextureY = YTex; } umumiy bo'sh joy SetUVTexure (Texture2D UVTex) {_videoTextureCbCr = UVTex; } public void OnPreRender () {if (! bCommandBufferInitialized) {InitializeCommandBuffer (); } m_ClearMaterial. SetTexture ("_ textureY", _videoTextureY); m_ClearMaterial. SetTexture ("_ textureCbCr", _videoTextureCbCr); m_ClearMaterial. SetMatrix ("_ DisplayTransform", _displayTransform); } #endif}}
9 -qadam: deyarli bajarildi
Nihoyat, biz ekranni bosganimizda va portalni joylashtirganimizda, biz doimo biz bilan yuzma -yuz bo'lishini xohlaymiz. Buning uchun portaldagi "UnityARHitTestExample" skriptiga o'ting. Ichidagi hamma narsani shu bilan almashtiring:
tizimdan foydalanish;
System. Collections. Generic -dan foydalanish; nomlar maydoni UnityEngine. XR.iOS {umumiy sinf UnityARHitTestExample: MonoBehaviour {ommaviy transform m_HitTransform; ommaviy float maxRayDistance = 30.0f; ommaviy LayerMask collisionLayer = 1 <0) {foreach (var hitResult in hitResults) {Debug. Log ("Git urildi!"); m_HitTransform.position = UnityARMatrixOps. GetPosition (hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps. GetRotation (hitResult.worldTransform); Debug. Log (string. Format ("x: {0: 0. ######} y: {1: 0. ######} z: {2: 0. ###### } ", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); Vector3 CurrAngle = transform.eulerAngles; transform. LookAt (Camera.main.transform); transform.eulerAngles = yangi Vector3 (CurrAngle.x, transform.eulerAngles.y, currAngle.z); haqiqatga qaytish; }} false qaytarish; } // Yangilanish har bir kvadrat uchun bir marta chaqiriladi void Update () {#if UNITY_EDITOR // biz bu skriptni faqat muharrir tomonida ishlatamiz, lekin agar qurilmada ishlashiga hech narsa to'sqinlik qilmasa (Input. GetMouseButtonDown (0)) {Ray ray = Camera.main. ScreenPointToRay (Input.mousePosition); RaycastHit zarbasi; // biz plagin tomonidan yaratilgan samolyot to'qnashuvi ob'ektlaridan birini urishga harakat qilamiz // samarali tarzda ARHitTestResultType. ARHitTestResultTypeExistingPlaneUsingExtent bilan HitTestni chaqirishga o'xshaydi, agar (Physics. Raycast (ray, out hit, maxRayDistance, collisionLayer)) {// biz pozitsiyani m_HitTransform.position = hit.point aloqa nuqtasidan olamiz; Debug. Log (string. Format ("x: {0: 0. ######} y: {1: 0. ######} z: {2: 0. ###### } ", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); // va m_HitTransform.rotation = hit.transform.rotation tekislik to'qnashuvining aylanishidan aylanish; }} #else if (Input.touchCount> 0 && m_HitTransform! = null) {var touch = Input. GetTouch (0); if (touch.phase == TouchPhase. Began || touch.phase == TouchPhase. Moved) {var screenPosition = Camera.main. ScreenToViewportPoint (touch.position); ARPoint nuqtasi = yangi ARPoint {x = screenPosition.x, y = screenPosition.y}; // birinchi o'ringa reults turlari ARHitTestResultType resultTypes = {ARHitTestResultType. ARHitTestResultTypeExistingPlaneUsingExtent, // foydalanmoqchi bo'lsangiz, cheksiz samolyotlari foydalanish, bu: //ARHitTestResultType. ARHitTestResultTypeExistingPlane, ARHitTestResultType. ARHitTestResultTypeHorizontalPlane, ARHitTestResultType. ARHitTestResultTypeFeaturePoint}; foreach (ARHitTestResultType resultType in resultTypes) {if (HitTestWithResultType (nuqta, resultType)) {qaytish; }}}} #endif}}}
10 -qadam: Ilovani telefoningizga qo'ying
Nihoyat, ishimiz tugadi. Faylga o'ting, sozlamalarni yarating va yaratish -ni bosing. Xcode -ni oching va tuzilmadan yaratilgan papkani tanlang. Rivojlanish guruhini tanlang va ilovani telefoningizga qo'ying! Sizning ehtiyojlaringizga mos ravishda zarrachalar va osmon qutisi ranglarini o'zgartirishni xohlashingiz mumkin. Agar sizda biron bir savol bo'lsa, izohlarda menga xabar bering va qaraganingiz uchun tashakkur!