Cov txheej txheem:

AR Portal mus rau Qhov Tseeb Los Ntawm Cov Neeg Tsis Txaus Ntseeg: 10 Kauj Ruam (nrog Duab)
AR Portal mus rau Qhov Tseeb Los Ntawm Cov Neeg Tsis Txaus Ntseeg: 10 Kauj Ruam (nrog Duab)

Video: AR Portal mus rau Qhov Tseeb Los Ntawm Cov Neeg Tsis Txaus Ntseeg: 10 Kauj Ruam (nrog Duab)

Video: AR Portal mus rau Qhov Tseeb Los Ntawm Cov Neeg Tsis Txaus Ntseeg: 10 Kauj Ruam (nrog Duab)
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Kaum ib hlis
Anonim
AR Portal mus rau Upside Down Los Ntawm Yam Tsis Zoo
AR Portal mus rau Upside Down Los Ntawm Yam Tsis Zoo
AR Portal mus rau Upside Down Los Ntawm Yam Tsis Zoo
AR Portal mus rau Upside Down Los Ntawm Yam Tsis Zoo

Cov Lus Qhia no yuav dhau los ntawm kev tsim qhov kev hloov pauv tiag tiag mobile app rau iPhone nrog lub portal uas coj mus rau qhov rov qab los ntawm Cov Neeg Tsis Txaus Siab. Koj tuaj yeem nkag mus hauv lub portal, taug kev ncig, thiab rov qab los. Txhua yam hauv lub portal tsuas tuaj yeem pom dhau ntawm lub portal kom txog thaum koj taug kev sab hauv. Ib zaug sab hauv, txhua yam yuav ua rau txhua qhov chaw, kom txog thaum koj rov qab los rau hauv lub ntiaj teb tiag. Peb yuav siv Unity 3D video game engine nrog Apple ARKit plugin. Txhua qhov software peb yuav siv tuaj yeem rub tawm thiab siv tau dawb. Koj tsis tas yuav yog tus kws tshaj lij los ua raws, peb yuav hla txhua kauj ruam!

Kauj Ruam 1: Pib Txoj Haujlwm Kev Sib Koom Tshiab

Pib Txoj Haujlwm Kev Sib Koom Tshiab
Pib Txoj Haujlwm Kev Sib Koom Tshiab

Ua ntej tshaj, rub tawm Unity3D thiab nco ntsoov teeb tsa cov ntawv tsim rau IOS platform. Koj kuj tseem yuav tsum rub tawm Xcode thiab tso npe rau tus tsim kua dawb tsim tus lej. Koj lub iPhone tseem yuav tsum tau khiav IOS 11 lossis siab dua. Raws li hnub no Lub Ob Hlis 5, 2018, iOS 11.3 tau tawm tab sis xCode 9.2 tseem tsis tau muaj cov ntaub ntawv txhawb nqa rau nws. Yog li yog tias koj tab tom ua haujlwm iOS tshiab tshaj plaws nco ntsoov rub tawm Xcode beta tshiab kawg los ntawm Apple. Developer.com.

Thaum koj muaj tag nrho cov phiaj xwm tsim nyog, qhib Unity thiab pib qhov haujlwm tshiab, hu nws txhua yam koj xav tau. Peb yuav xav tau Apple ARKit plugin kom peb tuaj yeem siv peb lub xov tooj lub koob yees duab txhawm rau txheeb xyuas hauv av ib qho khoom siv rau hauv pem teb. Wb ntshuam tam sim no los ntawm kev mus rau Cov Khoom Khw tab thiab tshawb "ARKit". Koj yuav tsum tsim kom tau nyiaj Unity dawb yog tias koj tsis muaj ib qho, tom qab ntawd nyem ntshuam kom tau txais lub plugin.

Nkag mus rau cov piv txwv hauv daim nplaub tshev ARKit thiab nrhiav "UnityARKitScene." Ob npaug nias qhov ntawd qhib nws. Peb yuav siv qhov xwm txheej no los ua qhov pib thiab tsim tawm los ntawm no. Qhov xwm txheej no los ntawm lub hauv paus yuav tso cai rau koj txheeb xyuas hauv av thiab thaum koj coj mus rhaub qhov screen, lub voos xwmfab yuav muab tso rau hauv txoj haujlwm ntawd.

Thawj zaug tau txais peb cov kev teeb tsa ua ke sib nrug deb yog li peb tsis txhob hnov qab ua nws tom qab. Nyem cov ntaub ntawv, tsim teeb tsa thiab tshem tawm txhua qhov xwm txheej los ntawm cov npe ntawd. Nyem ntxiv qhib qhov xwm txheej ntxiv rau peb tam sim no. Qhov kawg uas peb xav tau teeb tsa ntawm no yog nyob hauv cov neeg ua si teeb tsa mus rau tus lej cim thiab hom rau txoj hlua no yog com. YourCompanyName. YourAppName, yog li hauv kuv qhov xwm txheej kuv ua qee yam xws li com. MatthewHallberg. PortalTest.

Kauj ruam 2: Teeb Scene

Teeb Scene
Teeb Scene

Ua ntej saib mus rau sab laug thiab pom cov khoom ua si hu ua "GeneratePlanes". Nrog qhov tau hais tseg, saib mus rau tam sim no thiab nyem rau ntawm lub npov kom xiam nws. Txoj hauv kev no peb tsis muaj cov xwm txheej xiav uas tsim los thaum ARKit pom lub dav hlau hauv av. Tom ntej tshem tawm qhov "RandomCube" qhov khoom ua si vim tias peb tsis xav pom qhov ntawd hauv peb qhov xwm txheej.

Tam sim no peb yuav tsum xub tsim peb lub qhov rooj nkag. Rho tawm lub voos xwmfab uas yog menyuam "HitCubeParent". Txoj cai nyem thiab xaiv tsim cov khoom ua si khoob. Rename nws "Portal". Tam sim no nyem rau ntawm yam khoom ntawd thiab tsim lub voos xwmfab, qhov no yuav ua rau nws yog menyuam yaus ntawm lub portal. Hloov nws "PostLeft" thiab qhov no yuav yog sab laug ntawm peb lub portal. Nplai nws kom x yog 1 y yog 28 thiab z yog ib qho. Ua tib yam rau txoj cai tshaj tawm. Tam sim no tsim cov ncej saum toj kawg nkaus thiab ntsuas y rau 14. Tig qhov no ib sab thiab txav nws xws li nws txuas rau lwm cov ntawv. Ua kom tag nrho cov portal nplai 1.3 x 1.4 x 1.

Mus rau google thiab ntaus ntoo lossis tawv ntoo. Rub tawm ib qho ntawm cov duab no thiab rub nws mus rau hauv koj li khoom muaj nqis hauv Unity. Tam sim no rub daim duab ntawd mus rau tag nrho koj cov ntawv tshaj tawm.

Nyem rau ntawm "Portal" yam khoom dua thiab nyem ntxiv tivthaiv ntawm sab xis. Ntxiv cov ntawv "UnityARHitTestExample" rau nws. Muaj qhov tsis muaj qhov nyob rau "Hit Transform", rub lub "HitCubeParent" cov khoom mus rau hauv qhov ntawd.

Kauj Ruam 3: Cia Ua Qee Yam

Cia Ua Qee Yam
Cia Ua Qee Yam

Tam sim no peb tab tom siv Unity Particle system los ua kom muaj pa luam yeeb thiab cov nplaim dej ua rau sab hauv peb lub portal. Mus rau Cov Khoom ntawm lub tshuab raj saum toj kawg nkaus, cov cuab yeej siv tau zoo, thiab cov txheej txheem ntshuam.

Tsim ob qho khoom ua si khoob hauv koj lub portal thiab hu rau ib qho "SmokeParticles" thiab lwm qhov "FloatingParticles."

Ntxiv cov txheej txheem txheej txheem rau cov pa luam yeeb.

Cov khoom siv no muaj ntau txoj kev xaiv tab sis peb tsuas yog xav hloov ob peb leeg.

Hloov cov xim pib rau qee yam tsaus nti xiav nrog kwv yees li 50% pob tshab. Ua kom tus pa tawm tus nqi 100. Sab hauv lub cev, ua lub vojvoog.01. Hauv qhov ua yeeb yaj kiab hauv qab hloov qhov me me rau.8 thiab qhov loj me rau 5. Ntawm cov khoom siv tsuas yog xaiv cov pa luam yeeb los ntawm daim ntawv, tab sis peb yuav hloov qhov no tom qab.

Ntxiv cov txheej txheem me me rau cov khoom ua si ntab tam sim no thiab teeb cov pa tawm mus rau 500. Teem pib lub neej mus rau 2, lub vojvoog mus rau 10, qhov me me me me rau.01, thiab qhov loj me me rau.015. Teem cov khoom siv rau cov khoom me me tam sim no.

Thaum kawg coj ob qho khoom ua si thiab tig lawv los ntawm 90 degrees ntawm x thiab tsa lawv mus rau saum huab cua yog li lawv tawm mus rau ntawm lub qhov rooj ntawm lub qhov rooj.

Kauj Ruam 4: Qhib Cov Particle

Qhib Cov Particle
Qhib Cov Particle

Txij li thaum peb xav kom cov khoom no npog thaj tsam loj tab sis tseem txav qeeb peb xav tau los tsim peb tus kheej cov qauv ua haujlwm. Yog li txoj nyem rau hauv cov khoom muaj nqis thiab tsim tsab ntawv C# tshiab thiab hu nws "ParticleSample." Luam thiab muab tso rau hauv tus lej no:

siv System. Collections;

siv System. Collections. Generic; siv UnityEngine; pej xeem chav kawm ParticleSample: MonoBehaviour {ntiag tug ParticleSystem ps; // Siv qhov no rau qhov pib tsis muaj dab tsi Pib () {ps = GetComponent (); StartCoroutine (SampleParticleRoutine ()); } IEnumerator SampleParticleRoutine () {var main = ps.main; main.simulationSpeed = 1000f; ps. Play (); tawm tshiab rov WaitForSeconds (.1f); main.simulationSpeed =.05f; }}

Tam sim no luag cov ntawv no mus rau txhua qhov ntawm koj cov khoom ua si qhov system.

Kauj ruam 5: Tsim Portal

Tsim lub Portal!
Tsim lub Portal!

Tam sim no peb xav tau los tsim lub portal yog li nyem rau ntawm lub portal game object thiab tsim plaub fab. Nplai lub quad kom nws npog tag nrho lub portal, qhov no yuav dhau los ua peb lub qhov rooj portal. Thawj qhov peb yuav tsum tau ntxiv rau nws yog lub portal shader, qhov no tsuas yog ua cov khoom nrog lwm qhov tshwj xeeb ntxoov ntxoo ntawm lawv. Txoj cai nyem rau hauv cov cuab yeej nplaub tshev thiab tsim qhov tshiab tsis pom qhov ntxoov ntxoo. Tshem tawm txhua yam nyob ntawd thiab muab tshuaj txhuam rau hauv cov cai no:

Shader "Portal/portalWindow"

{SubShader {Zwrite tawm Colormask 0 tshem tawm Stencil {Ref 1 Pass hloov} Dhau {}}}

Txoj cai nyem rau hauv lub hierarchy thiab tsim cov ntaub ntawv tshiab, hu nws PortalWindowMat, hauv qhov nco tseg rau cov khoom no nrhiav ntu ntu, thiab xaiv lub qhov rooj portal. Luag cov ntaub ntawv no mus rau koj lub portal quad.

Kauj Ruam 6: Particle Shaders

Particle Shaders
Particle Shaders

Txoj cai nyem rau hauv cov cuab yeej nplaub tshev dua thiab tsim tus duab ntxoov ntxoo tshiab. Peb yuav tsum ua cov duab ntxoov ntxoo rau cov khoom uas nkag mus sab hauv. Hloov tag nrho cov cai nrog qhov no:

Shader "Portal/Particles" {

Cov khoom {_TintColor ("Tint Xim", Xim) = (0.5, 0.5, 0.5, 0.5) _MainTex ("Particle Texture", 2D) = "dawb" {} _InvFade ("Qhov Zoo Tshaj Plaws", Ntau (0.01, 3.0)) = 1.0 _Stencil ("stencil", int) = 6} Qeb {Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane"} Blend SrcAlpha OneMinusSrcAlpha ColorMask RGB Cull Off Lighting Off ZWrite Off SubShader {Stencil {Ref 1 Comp [_Stencil]} Pass {CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 2.0 #pragma multi_compile_particles #pragma multi_compile_fog #include "UnityCGcpler2" tsau4 _TintColor; struct appdata_t {float4 vertex: POSITION; tsau 4 xim: COLOR; float2 texcoord: TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID}; struct v2f {float4 vertex: SV_POSITION; tsau 4 xim: 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); rov o; } UNITY_DECLARE_DEPTH_TEXTURE (_CameraDepthTexture); ntab _InvFade; fix4 frag (v2f i): SV_Target {#ifdef SOFTPARTICLES_ON ntab sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ (_CameraDepthTexture, UNITY_PROJ_COORD (i.projPos))); ntab partZ = i.projPos.z; ntab fade = saturate (_InvFade * (sceneZ-partZ)); i.color.a *= ploj; #endif fixed4 col = 2.0f * i.color * tex2D (_MainTex, i.texcoord); UNITY_APPLY_FOG (i.fogCoord, col); rov qab col; {ENDCG}}}}}

Tsim ob yam khoom siv tshiab, ib qho hu ua portalSmoke, thiab ib qho hu ua portalParticles.

Rau txhua tus xaiv qhov ntxoov ntxoo no, los ntawm qhov nco cia, hauv portals, cov ntsiab lus. Rau cov pa luam yeeb hais txog xaiv cov pa luam yeeb thiab rau cov lus xaiv cov khoom me me. Hloov cov xim ntawm cov pa luam yeeb mus rau qhov tsaus ntuj nti xiav nrog txog 50% kev hloov pauv. Mus rau tus muab kev tiv thaiv ntawm txhua qhov system hauv koj lub portal thiab xaiv lawv cov khoom siv uas peb nyuam qhuav tsim.

Kauj Ruam 7: Tsim Skybox

Tsim Skybox
Tsim Skybox

Tam sim no los tsim tiag tiag hom kev saib zoo peb yuav tsum tint txhua yam tsaus ntuj nti. Rau qhov no peb yuav siv pob tshab skybox yog li ua tus tshiab shader thiab muab tshuaj txhuam rau hauv cov cai no:

Shader "Portal/portalSkybox" {

Cov khoom {_Tint ("Tint Xim", Xim) = (.5,.5,.5,.5) [Gamma] _ Kev raug ("Raug", Ntau yam (0, 8)) = 1.0 _Rotation ("Kev Hloov", Ntau Yam (0, 360)) = 0 [NoScaleOffset] _Tex ("Cubemap (HDR)", Cube) = "grey" {} _Stencil ("StencilNum", int) = 6} SubShader {Tags {"Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox"} Cull Off ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Stencil {Ref 1 Comp [_Stencil]} Pass {CGPROGRAM #pragma vertex vert #pragma fragment fragment #pragma target 2.0 #Cua.cginc "samplerCUBE _Tex; half4 _Tex_HDR; ib nrab4 _Tint; ib nrab _ Raug; ntab _Rotation; float3 RotateAroundYInDegrees (float3 vertex, ntab degrees) {ntab alpha = degrees * UNITY_PI / 180.0; ntab sina, cosa; sincos (alpha, sina, cosa); float2x2 m = float2x2 (cosa, -sina, sina, cosa); rov float3 (mul (m, vertex.xz), vertex.y).xzy; } struct appdata_t {float4 vertex: POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID}; struct v2f {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 (tig); o.texcoord = v.vertex.xyz; rov o; } fixed4 frag (v2f i): SV_Target {half4 tex = texCUBE (_Tex, i.texcoord); half3 c = DecodeHDR (tex, _Tex_HDR); c = c * _Tint.rgb * sib koom_ColorSpaceDouble.rgb; c *= _ Kev raug; rov qab ib nrab 4 (c,.5); } ENDCG}} Rov Qab Tawm}

Tam sim no tsim cov khoom skybox tshiab, hu nws "PortalSkybox" thiab xaiv qhov portalSkybox shader los ntawm cov ntawv qhia zaub mov. Mus rau Qhov rai, Teeb pom kev zoo, nyob rau saum toj thiab xaiv lub skybox no peb nyuam qhuav tsim. Mus rau lub koob yees duab tseem ceeb thiab teeb tsa tus chij meej rau skybox. Thaum peb nyob ntawm no cia ntxiv qee qhov ntawm peb lub koob yees duab kom peb tuaj yeem tshawb pom kev sib tsoo. Ntxiv cov khoom tiv thaiv nruj rau lub koob yees duab thiab tsis siv lub ntiajteb txawj nqus. Ntxiv ib lub thawv collider thiab kos rau yog txhais. Ua lub thawv colliders loj.5 x 1 x 4. Teeb lub dav hlau clipping ntawm lub koob yees duab rau.01.

Kauj Ruam 8: Portal Logic

Portal Logic
Portal Logic

Qhov kawg peb yuav tsum tau ua yog tsim cov laj thawj uas tswj hwm peb lub portal. Tsim tsab ntawv C# tshiab thiab hu nws PortalController.

siv System. Collections;

siv System. Collections. Generic; siv UnityEngine; namespace UnityEngine. XR.iOS {pej xeem chav kawm PortalController: MonoBehaviour {public Material khoom siv; pej xeem MeshRenderer meshRenderer; pej xeem UnityARVideo UnityARVideo; ntiag tug bool isInside = tsis tseeb; ntiag tug bool isOutside = muaj tseeb; // Siv qhov no rau qhov pib tsis muaj dabtsis Pib () {Sab nraumPortal (); } void OnTriggerStay (Collider col) {Vector3 playerPos = Camera.main.transform.position + Camera.main.transform.forward * (Camera.main.nearClipPlane * 4); yog (transformInverseTransformPoint (playerPos).z <= 0) {yog (isOutside) {isOutside = cuav; isInside = muaj tseeb; InsidePortal (); }} lwm {yog (isInside) {isInside = cuav; isOutside = muaj tseeb; Sab nraum Portal (); }}} tsis muaj dabtsis Sab Nraud () {StartCoroutine (DelayChangeMat (3))); } void InsidePortal () {StartCoroutine (DelayChangeMat (6)); } IEnumerator DelayChangeMat (int stencilNum) {UnityARVideo.shouldRender = tsis tseeb; tawm tshiab rov WaitForEndOfFrame (); meshRenderer.enabled = cuav; foreach (Cov ntaub pua plag hauv cov ntaub ntawv) {mat. SetInt ("_Stencil", stencilNum); } tawm los rov qab tshiab WaitForEndOfFrame (); meshRenderer.enabled = muaj tseeb; UnityARVideo.shouldRender = muaj tseeb; }}}

Luag tsab ntawv tshiab no mus rau koj lub qhov rooj portal. Qhov no yuav hloov peb hauv thiab tawm ntawm lub portal thaum twg tus neeg sib tsoo ntawm peb lub koob yees duab tau sib tsoo nrog lub qhov rooj portal. Tam sim no hauv txoj haujlwm uas hloov pauv txhua yam ntaub ntawv peb qhia rau ARkit plugin kom tsis ua tus ncej, yog li mus rau lub koob yees duab tseem ceeb thiab qhib UnityARVideo tsab ntawv. Tsim cov pej xeem bool shouldRender rau saum thiab teeb tsa kom sib npaug rau qhov tseeb. Hauv qhov OnPreRender () ua haujlwm qhwv txhua yam hauv ib qho yog tias nqe lus uas txhua yam hauv yuav tsuas yog khiav yog shouldRender yog qhov tseeb. Tag nrho tsab ntawv yuav tsum zoo li no:

siv System;

siv System. Runtime. InteropServices; siv UnityEngine; siv UnityEngine. Rendering; namespace UnityEngine. XR.iOS {public class UnityARVideo: MonoBehaviour {public Material m_ClearMaterial; [HideInInspector] pej xeem bool shouldRender = muaj tseeb; ntiag tug CommandBuffer m_VideoCommandBuffer; ntiag tug Texture2D _videoTextureY; ntiag tug Texture2D _videoTextureCbCr; ntiag tug Matrix4x4 _displayTransform; ntiag tug bool bCommandBufferInitialized; pej xeem void Pib () {UnityARSessionNativeInterface. ARFrameUpdatedEvent += UpdateFrame; bCommandBufferInitialized = cuav; } void UpdateFrame (UnityARCamera cam) {_displayTransform = tshiab 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 = CommandBuffer tshiab (); m_VideoCommandBuffer. Blit (tsis muaj, BuiltinRenderTextureType. CurrentActive, m_ClearMaterial); GetComponent (). AddCommandBuffer (CameraEvent. BeforeForwardOpaque, m_VideoCommandBuffer); bCommandBufferInitialized = muaj tseeb; } void OnDestroy () {GetComponent (). RemoveCommandBuffer (CameraEvent. BeforeForwardOpaque, m_VideoCommandBuffer); UnityARSessionNativeInterface. ARFrameUpdatedEvent -= UpdateFrame; bCommandBufferInitialized = cuav; } #if! UNITY_EDITOR pej xeem void OnPreRender () {if (shouldRender) {ARTextureHandles tuav = UnityARSessionNativeInterface. GetARSessionNativeInterface (). GetARVideoTextureHandles (); yog (handles.textureY == System. IntPtr. Zero || handles.textureCbCr == System. IntPtr. Zero) {rov qab; } yog (! bCommandBufferInitialized) {InitializeCommandBuffer (); } Kev daws teeb meem tam sim noResolution = Screen.currentResolution; // Texture Y yog (_videoTextureY == null) {_videoTextureY = Texture2D. CreateExternalTexture (currentResolution.width, currentResolution.height, TextureFormat. R8, cuav, cuav, (System. IntPtr) ua haujlwm.textureY); _videoTextureY.filterMode = FilterMode. Bilinear; _videoTextureY.wrapMode = TextureWrapMode. Repeat; m_ClearMaterial. SetTexture ("_ textureY", _videoTextureY); } // Texture CbCr yog (_videoTextureCbCr == null) {_videoTextureCbCr = Texture2D. CreateExternalTexture (currentResolution.width, currentResolution.height, TextureFormat. RG16, cuav, cuav, (System. IntPtr) ua haujlwm.textureCbCrr) _videoTextureCbCr.filterMode = FilterMode. Bilinear; _videoTextureCbCr.wrapMode = TextureWrapMode. Repeat; m_ClearMaterial. SetTexture ("_ textureCbCr", _videoTextureCbCr); } _videoTextureY. UpdateExternalTexture (tes tuav.textureY); _videoTextureCbCr. UpdateExternalTexture (tes tuav.textureCbCr); m_ClearMaterial. SetMatrix ("_ DisplayTransform", _displayTransform); }} #else pej xeem void SetYTexure (Texture2D YTex) {_videoTextureY = YTex; } pej xeem void SetUVTexure (Texture2D UVTex) {_videoTextureCbCr = UVTex; } pej xeem void OnPreRender () {yog (! bCommandBufferInitialized) {InitializeCommandBuffer (); } m_ClearMaterial. SetTexture ("_ textureY", _videoTextureY); m_ClearMaterial. SetTexture ("_ textureCbCr", _videoTextureCbCr); m_ClearMaterial. SetMatrix ("_ DisplayTransform", _displayTransform); } #endif}}

Kauj ruam 9: Yuav luag tiav

Yuav luag tiav!
Yuav luag tiav!

Thaum kawg thaum peb nyem qhov screen thiab tso lub portal peb xav kom nws ib txwm fim rau peb. Txhawm rau ua qhov no mus rau "UnityARHitTestExample" tsab ntawv ntawm lub portal. Hloov txhua yam sab hauv nrog qhov no:

siv System;

siv System. Collections. Generic; namespace UnityEngine. XR.iOS {pej xeem chav kawm UnityARHitTestExample: MonoBehaviour {pej xeem Hloov m_HitTransform; pej xeem ntab maxRayDistance = 30.0f; pej xeem LayerMask collisionLayer = 1 <0) {foreach (var hitResult hauv hitResults) {Debug. Log ("Tau ntaus!"); 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; hloov. LookAt (Camera.main.transform); transform.eulerAngles = tshiab Vector3 (currAngle.x, transform.eulerAngles.y, currAngle.z); rov muaj tseeb; }} rov tsis tseeb; } // Hloov tshiab yog hu ua ib zaug ib kab ntawv tsis muaj qhov hloov tshiab () {#if UNITY_EDITOR // peb tsuas yog siv cov ntawv no ntawm tus kws kho mob sab, txawm hais tias tsis muaj ib yam uas yuav tiv thaiv nws los ntawm kev ua haujlwm ntawm lub cuab yeej yog (Input. GetMouseButtonDown (0)) {Cov duab hluav taws xob = Camera.main. ScreenPointToRay (Input.mousePosition); RaycastHit ntaus; // peb yuav sim ntaus ib qho ntawm lub dav hlau sib tsoo gameobjects uas tau tsim los ntawm lub plugin // zoo ib yam li hu rau HitTest nrog ARHitTestResultType. ARHitTestResultTypeExistingPlaneUsingExtent yog (Physics. Raycast (hluav taws xob, ntaus tawm, maxRayDistance, collisionLayer)) {// peb yuav tau txais txoj haujlwm los ntawm qhov chaw sib cuag m_HitTransform.position = hit.point; 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)); // thiab kev sib hloov los ntawm kev hloov pauv ntawm lub dav hlau sib tsoo m_HitTransform.rotation = hit.transform.rotation; }} #else yog (Input.touchCount> 0 && m_HitTransform! = null) {var kov = Input. GetTouch (0); yog (touch.phase == TouchPhase. Began || touch.phase == TouchPhase. Moved) {var screenPosition = Camera.main. ScreenToViewportPoint (touch.position); ARPoint point = tshiab ARPoint {x = screenPosition.x, y = screenPosition.y}; // prioritize reults hom ARHitTestResultType resultTypes = {ARHitTestResultType. ARHitTestResultTypeExistingPlaneUsingExtent, // hais tias koj xav mus siv infinite dav hlau siv no: //ARHitTestResultType. ARHitTestResultTypeExistingPlane, ARHitTestResultType. ARHitTestResultTypeHorizontalPlane, ARHitTestResultType. ARHitTestResultTypeFeaturePoint}; foreach (ARHitTestResultType resultType hauv resultTypes) {yog (HitTestWithResultType (taw tes, resultType)) {rov; }}}} #endif}}}

Kauj ruam 10: Tso App rau Koj Lub Xov Tooj

Tso App rau Koj Lub Xov Tooj!
Tso App rau Koj Lub Xov Tooj!

Thaum kawg peb ua tiav. Mus rau cov ntawv, tsim chaw thiab nyem tsim. Qhib Xcode thiab xaiv daim nplaub tshev uas tau tsim los ntawm kev tsim. Xaiv koj pab pawg txhim kho thiab muab lub app tso rau hauv koj lub xov tooj! Koj yuav xav hloov xim ntawm cov khoom me me thiab skybox kom haum rau koj cov kev xav tau. Qhia rau kuv paub hauv cov lus yog tias koj muaj lus nug thiab ua tsaug rau kev saib!

Pom zoo: