Unity 2022.3.5f1 Google VR Cardboard - 01

VR/Google Cardboard VR (GVR) 2023. 9. 15. 13:12
반응형

프로젝트 생성후 Android 플랫폼으로 변경 

 

 

2019버전에 있던 XR Settings는 제거 되었다 

 

XR Plug-in Management로 이동되었다고 함 

 

XR Plugin Management 설치 

 

 

2019에 있던 Virtual Reality SDKs 중 Cardboard선택하는 부분은 어디로 간걸까...?

 

https://developers.google.com/cardboard/develop/unity/quickstart?hl=ko 

 

Unity용 Google Cardboard 빠른 시작  |  Google for Developers

이 페이지는 Cloud Translation API를 통해 번역되었습니다. Switch to English Unity용 Google Cardboard 빠른 시작 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 이 가이드

developers.google.com

 

cardboard-xr-plugin sdk를 설치 해본다 

 

 

https://github.com/googlevr/cardboard-xr-plugin.git

 

1.21.0 버전이 설치 됨

 

샘플도 한번 받아 보자 

샘플씬 HelloCardboard를 열어본다 

 

일단 플레이 해보자 

 

스크립트 missing 난건 뭐였을까...?

 

Player Setting에 XR Plug-in Management에 가보면 Providers에 Cardboard XR Plugin이 추가 된걸 확인 할수 있다 

체크 해주자

 

 

다시 실행해도 문제는 계속 발생 한다 

Main Camera에 있는 missing 난 스크립트는 제거 했다 

(warning이라 상관없긴하지만)

https://stackoverflow.com/questions/71012488/please-initialize-cardboard-xr-loader-before-calling-this-function

//-----------------------------------------------------------------------
// <copyright file="CardboardStartup.cs" company="Google LLC">
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-----------------------------------------------------------------------

using Google.XR.Cardboard;
using UnityEngine;

/// <summary>
/// Initializes Cardboard XR Plugin.
/// </summary>
public class CardboardStartup : MonoBehaviour
{
    /// <summary>
    /// Start is called before the first frame update.
    /// </summary>
    public void Start()
    {
        // Configures the app to not shut down the screen and sets the brightness to maximum.
        // Brightness control is expected to work only in iOS, see:
        // https://docs.unity3d.com/ScriptReference/Screen-brightness.html.
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        Screen.brightness = 1.0f;

        // Checks if the device parameters are stored and scans them if not.
        if (!Api.HasDeviceParams())
        {
            Api.ScanDeviceParams();
        }
    }

    /// <summary>
    /// Update is called once per frame.
    /// </summary>
    public void Update()
    {
        if (Api.IsGearButtonPressed)
        {
            Api.ScanDeviceParams();
        }

        if (Api.IsCloseButtonPressed)
        {
            Application.Quit();
        }

        if (Api.IsTriggerHeldPressed)
        {
            Api.Recenter();
        }

        if (Api.HasNewDeviceParams())
        {
            Api.ReloadDeviceParams();
        }

#if !UNITY_EDITOR
        Api.UpdateScreenParams();
#endif
    }
}

 

 

에러 없이 잘 실행된다

 

예전에 에뮬레이터 있었던거 같은데 이제 없어진건가... Editor에서도 실행 해볼수 있었던거 같은데 

 

 

 

레이어 추가 

 

Treasure를 선택 하고 레이어를 Interactive로 변경한다 

이때 자식 오브젝트모두 변경 한다 (팝업 뜨면 yes선택)

 

 

CardboardReticlePointer를 선택후 

 

Reticle Interaction LayerMask를 Interactive로 설정 한다 

 

 

Project Settings > Player > Resolution and Presentation.

 

Disable Optimized Frame Pacing.

 

Auto Graphics API를 선택 해제 하고 Vulkan을 선택해 제거 한다 

 

Select Android 7.0 'Nougat' (API level 24) or higher in Minimum API Level.

Select API level 31 or higher in Target API Level.

 

 

Select IL2CPP in Scripting Backend.

 

 

Select desired architectures by choosing ARMv7, ARM64, or both in Target Architectures.

 

 

Select Require in Internet Access.

 

 

Specify your company domain under Package Name.

 

 

Navigate to Project Settings > Player > Publishing Settings.

In the Build section, select Custom Main Gradle Template and Custom Gradle Properties Template.

 


mainTemplate.gradle파일에 dependencies에 다음 추가 

  implementation 'androidx.appcompat:appcompat:1.4.2'
  implementation 'com.google.android.gms:play-services-vision:20.1.3'
  implementation 'com.google.android.material:material:1.6.1'
  implementation 'com.google.protobuf:protobuf-javalite:3.19.4'

 

 

전체 코드 

apply plugin: 'com.android.library'
**APPLY_PLUGINS**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.gms:play-services-vision:20.1.3'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'com.google.protobuf:protobuf-javalite:3.19.4'
**DEPS**}

android {
    ndkPath "**NDKPATH**"

    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**PACKAGING_OPTIONS**
}
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**

gradleTemplate.properties파일에 다음 추가 

android.enableJetifier=true
android.useAndroidX=true

 

전체 코드 

org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
unityStreamingAssets=**STREAMING_ASSETS**
**ADDITIONAL_PROPERTIES**
android.enableJetifier=true
android.useAndroidX=true

빌드 


녹스 또는 기기 테스트 

(녹스에서는 실행은 되나 플레이 못함)

 

반응형
: