rhttps://www.youtube.com/watch?v=1BtSgFkrkY8

 

 

360도 회전가능하게 만들어진 영상을 다운로드

www. 다음에 앞에 ss를 붙이면 다운로드 사이트로 갈 수 있다.

 

 

https://gist.github.com/unity3dcollege/d059b376f7461d908107e97534ed9e04

 

InvertedSphere.cs

GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

이 사이트의 스크립트를 복사 한후 스크립트를 만들어준다.

 

 

 

InvertedSphere 스크립트는  Editor폴더에  넣어주어야 한다.

 

그 후 메뉴에서 GameObject/Create Other/Inverted Sphere 를 선택해 구체를 생성한다.

 

구체에 Video Player컴포넌트를  부착 하고 Source에 영상을 넣자

GvrEditorEmulator와  비슷한
Editor에서만 동작하는 마우스를 움직여 카메라를 조작하는 스크립트 작성

 

그 후 메인카메라의 좌표를 0, 0 , 0으로 맞춰주어야 한다.

 

새로운 메터리얼을 만들고 Shader를  Unlit/Texture로  변경한다

 

Sphere안에 카메라를 넣어주고 해당 메타리얼을 넣어준다.

 

 

1. 앞서 만들었던 HMDEmulator를  Main Camera에  컴포넌트로 추가

 

2. Main Camera에  Tracked Pose Driver컴포넌트를  부착

 

 

 

 

만들어진 프로그램은 간이식 장치(안드로이드)로 apk로 추출후 테스해볼 수 있다.

 

 

 

'산대특 > VRAR' 카테고리의 다른 글

Oculus Settings and Grab  (0) 2024.04.17
Reticle  (0) 2024.04.16
캐릭터 이동지점 변경시 VR시점 변경  (0) 2024.04.12
VR Setting 문제  (0) 2024.04.12
VR Setting 문제  (0) 2024.04.12

 

시점을 변경하고 자동차에 콜라이더를 넣어서

점의 레이캐스트가 닿을 시 인지할 수 있도록 하였다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.LowLevel;

public class Car : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IGvrPointerHoverHandler
{
    private Coroutine coroutine;

    public void OnGvrPointerHover(PointerEventData eventData)
    {
        //Debug.Log("Hover");
    }


    public void OnPointerEnter(PointerEventData eventData)
    {
        coroutine = StartCoroutine(CoClick());
        Debug.Log("Enter");
    }


    private IEnumerator CoClick()
    {
        float delta = 0f;
        while (true)
        {
            delta += Time.deltaTime;
            if(delta >= 3)
            {
                Debug.LogFormat("Clicked , {0}", delta);
                delta = 0f;
            }
            yield return null;
        }
    }
    public void OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("Exit");
        StopCoroutine(coroutine);
    }
}

 

 

플레이어가 지정한 지정한 위치에 도달하면 방향을 전환하여

다음 목적지를 향해 이동하고 그에 맞춰 VR의 시선이 달라진다.

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class Player : MonoBehaviour
{
    public Transform[] wayPoints;
    private int nextIdx = 0;
    private float speed = 2f;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        MoveWayPoint();
    }

    public void MoveWayPoint()
    {
        Vector3 dir = wayPoints[nextIdx].position - this.transform.position;
        // 회전 각도
        Quaternion rot = Quaternion.LookRotation(dir);

        this.transform.Translate(Vector3.forward * speed * Time.deltaTime);

        this.transform.rotation = Quaternion.Slerp(this.transform.rotation, rot, Time.deltaTime * speed);

    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("WayPoint"))
        {
            nextIdx++;
            if(nextIdx == 4)
            {
                nextIdx = 0;
            }
        }
    }



}

 

'산대특 > VRAR' 카테고리의 다른 글

Oculus Settings and Grab  (0) 2024.04.17
Reticle  (0) 2024.04.16
VR로 360도 동영상 다운로드 후 적용하기 + 오큘러스 적용  (0) 2024.04.16
VR Setting 문제  (0) 2024.04.12
VR Setting 문제  (0) 2024.04.12

VR 셋팅시 오류가 발생

 

 

 

Project Settings - Player - Other Settings

 

 

Publishing Settings

 

그 후 스크립트를 수정한다

 

 

 

//-----------------------------------------------------------------------
// <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
    }
}

CardboardStartup.cs

 

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-vision:15.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.protobuf:protobuf-javalite:3.8.0'
    


**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**

mainTemplate

 

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

gradleTemplate

 

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools">
    <application android:requestLegacyExternalStorage="true">
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:theme="@style/UnityThemeSelector">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
</manifest>
​

AndroidManifest

 

 

그 후 수정이 다 되었으면

씬을 올리고 (단, 씬이 많으면 빌드되야 할 부분이 맨 위로 올라가야 함)플랫폼 확인하고 build를 한 후저장 위치를 정하면 apk가 만들어진다.

 

'산대특 > VRAR' 카테고리의 다른 글

Oculus Settings and Grab  (0) 2024.04.17
Reticle  (0) 2024.04.16
VR로 360도 동영상 다운로드 후 적용하기 + 오큘러스 적용  (0) 2024.04.16
캐릭터 이동지점 변경시 VR시점 변경  (0) 2024.04.12
VR Setting 문제  (0) 2024.04.12

+ Recent posts