Player의 Body Mesh Renderer 끄기 - 360도 돌 때 내 몸이 보임
카페에 있는 GoogleVRForUnity Import하기
메인카메라에 부착
대리자 사용 X
일단 구현을 해봤고, 잘되었다.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Car : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IGvrPointerHoverHandler
{
[SerializeField] private PlayerAI playerAi;
[SerializeField] private GameObject infomation;
[SerializeField] private GameObject popUp;
[SerializeField] private Infomation info;
private float elapsedTime = 0f;
public void OnLookAt(bool isLookAt)
{
//Debug.LogFormat("isLookAt: {0}", isLookAt);
}
public void OnGvrPointerHover(PointerEventData eventData)
{
Debug.Log("Hover");
this.playerAi.MovePause();
if (eventData.pointerEnter.gameObject.CompareTag("btnYes"))
{
this.CheckTime();
//PopUp창 띄우기
if (this.elapsedTime >= 3f)
{
this.popUp.SetActive(true);
this.infomation.SetActive(false);
this.elapsedTime = 0f;
}
}
else if (eventData.pointerEnter.gameObject.CompareTag("btnNo"))
{
this.CheckTime();
//PopUp창 끄기
if (this.elapsedTime >= 3f)
{
this.popUp.SetActive(false);
this.infomation.SetActive(false);
this.elapsedTime = 0f;
}
}
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("Enter");
this.infomation.SetActive(true);
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("Exit");
this.playerAi.MovePlay();
this.popUp.SetActive(false);
}
private void CheckTime()
{
this.elapsedTime += Time.deltaTime;
Debug.Log(elapsedTime);
}
}
대리자 사용
너무 지저분해서 Car.cs에 enum을 추가해 대리자로 Main에다가 쓰려고 만들어주었다.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Car : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IGvrPointerHoverHandler
{
public enum eInteractionType
{
Hover, Enter, Exit
}
public Action<eInteractionType, GameObject> onInteractionType;
public void OnGvrPointerHover(PointerEventData eventData)
{
this.onInteractionType(eInteractionType.Hover, eventData.pointerEnter);
}
public void OnPointerEnter(PointerEventData eventData)
{
this.onInteractionType(eInteractionType.Enter, eventData.pointerEnter);
}
public void OnPointerExit(PointerEventData eventData)
{
this.onInteractionType(eInteractionType.Exit, eventData.pointerEnter);
}
}
Main에서 내가 메뉴, 정보, 플레이어, 차를 알아서 메인에서 처리하게 만들었다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestMain : MonoBehaviour
{
[SerializeField] private Car car;
[SerializeField] private PlayerAI playerAi;
[SerializeField] private UIMenu menu;
[SerializeField] private UIInfomation info;
private float elapsedTime = 0f;
// Start is called before the first frame update
void Start()
{
this.car.onInteractionType = (interactionType, go) => {
if(interactionType == Car.eInteractionType.Hover)
{
if(go.gameObject.tag == "btnYes")
{
this.CheckTime();
if(elapsedTime >= 3f)
{
this.menu.Hide();
this.info.Show();
this.elapsedTime = 0f;
}
}
else if(go.gameObject.tag == "btnNo")
{
this.CheckTime();
if (elapsedTime >= 3f)
{
this.menu.Hide();
this.elapsedTime = 0f;
}
}
//info창 띄우기, Player 멈추기
this.playerAi.MovePause();
}
else if(interactionType == Car.eInteractionType.Enter)
{
this.menu.Show();
}
else
{
//Exit
this.playerAi.MovePlay();
this.info.Hide();
}
};
}
private void CheckTime()
{
Debug.Log(elapsedTime);
this.elapsedTime += Time.deltaTime;
}
}
메뉴와 정보 스크립트에서 Show, Hide로 게임오브젝트를 키거나 끄는 메서드를 만들었다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIMenu : MonoBehaviour
{
public void Show()
{
this.gameObject.SetActive(true);
}
public void Hide()
{
this.gameObject.SetActive(false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIInfomation : MonoBehaviour
{
public void Show()
{
this.gameObject.SetActive(true);
}
public void Hide()
{
this.gameObject.SetActive(false);
}
}
결과
'VR 콘텐츠 기초' 카테고리의 다른 글
[Meta Quest, VR, Oculus] 잡기(Create Grab Interactions) - 초기설정 (0) | 2023.10.20 |
---|---|
[Meta Quest, VR, Oculus] OVRCameraRig 설정, Interaction SDK 시작하기 (0) | 2023.10.20 |
OculusVR - 큐브 만지면 가운데 있는 큐브 색 변경 (0) | 2023.10.20 |
OVRCameraRig, OVRHandPrefab, OVRHands - 초기설정 (0) | 2023.10.19 |
InMindVR - AI Navigation, NavMeshAgent, NavMeshSurface, WayPoint 이동 (0) | 2023.10.18 |