250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- touchdesinger
- 터치디자이너 인터페이스
- touchdesigner GPU
- 파이썬
- ableton live 10
- particleGPU
- 터치디자이너 list
- 터치디자이너 함수
- 터치디자이너
- TDableton
- 터치디자이너 reference
- 터치디자이너 timeline
- 파이썬reference
- displace
- 파이썬 if
- 터치디자이너 Instancing
- 터치디자이너 파이썬
- 터치디자이너 python
- 터치디자이너 튜토리얼
- touchdesigner displace
- 터치디자이너 강의
- touchdesigner particle
- 터치디자이너 if
- 터치디자이너 interface
- 터치디자이너 참조
- 터치디자이너 replicator
- 터치디자이너 에이블톤
- TouchDesigner
- 터치디자이너 클론
- 터치디자이너 오퍼레이터
Archives
- Today
- Total
caLAB
[유니티 VR 네트워크 개발] PC와 VR 플레이어 동기화 본문
728x90
PC와 VR 장비로 접속하여 position과 rotation을 동기화시키는 것을 구현하였다.
다른 게임에서 생긴 캐릭터 동기화시키는 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using Photon.Pun;
using UnityEngine.XR.Interaction.Toolkit;
public class networkPlayer : MonoBehaviour
{
public Transform head;
public Transform leftHand;
public Transform rightHand;
private PhotonView photonView;
private Transform headRig;
private Transform leftHandRig;
private Transform rightHandRig;
private void Start()
{
photonView = GetComponent<PhotonView>();
XRRig rig = FindObjectOfType<XRRig>();
if (networkMgr.Instance.currentPlayer == networkMgr.PlayerState.pcPlayer && photonView.IsMine)
{
headRig = GameObject.Find("pcPlayer/Camera").transform;
leftHandRig = GameObject.Find("pcPlayer/leftHand").transform;
rightHandRig = GameObject.Find("pcPlayer/rightHand").transform;
}
if(networkMgr.Instance.currentPlayer == networkMgr.PlayerState.vrPlayer && photonView.IsMine)
{
headRig = rig.transform.Find("Camera Offset/Main Camera");
leftHandRig = rig.transform.Find("Camera Offset/LeftHand Controller");
rightHandRig = rig.transform.Find("Camera Offset/RightHand Controller");
}
}
private void Update()
{
if(photonView.IsMine)
{
rightHand.gameObject.SetActive(false);
leftHand.gameObject.SetActive(false);
head.gameObject.SetActive(false);
MapPosition(head, headRig);
MapPosition(leftHand, leftHandRig);
MapPosition(rightHand, rightHandRig);
}
}
void MapPosition(Transform target, Transform rigTransform)
{
target.position = rigTransform.position;
target.rotation = rigTransform.rotation;
}
}
네트워크 매니저 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class networkMgr : MonoBehaviourPunCallbacks
{
public enum PlayerState
{
pcPlayer, vrPlayer
}
public PlayerState currentPlayer;
public GameObject vrPlayer;
public GameObject pcPlayer;
public GameObject mainCam;
public GameObject selectUI;
private GameObject spawnedPlayerPrefab;
private static networkMgr _instace;
public static networkMgr Instance { get { return _instace; } }
public delegate void playerSelectDele();
public event playerSelectDele playerselect;
private void Awake()
{
if(_instace == null)
{
_instace = this;
}
}
private void Start()
{
PhotonNetwork.AutomaticallySyncScene = false;
startConnectServer();
}
public void startConnectServer()
{
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Try to connecting...");
}
public void ConnectToServer()
{
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Try connect to server....");
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected To server. Success");
base.OnConnectedToMaster();
PhotonNetwork.JoinLobby();
PhotonNetwork.JoinOrCreateRoom("room", new RoomOptions()
{
MaxPlayers = 10,
IsOpen = true,
IsVisible = true
},
TypedLobby.Default);
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
Debug.Log("joined lobby");
}
public override void OnJoinedRoom()
{
Debug.Log("Joined a Room");
base.OnJoinedRoom();
selectUI.SetActive(true);
}
public void pcPlayerSelect()
{
mainCam.SetActive(false);
selectUI.SetActive(false);
pcPlayer.SetActive(true);
currentPlayer = PlayerState.pcPlayer;
spawnedPlayerPrefab = PhotonNetwork.Instantiate("spawnedPCplayer", transform.position, transform.rotation);
}
public void vrPlayerSelect()
{
mainCam.SetActive(false);
selectUI.SetActive(false);
vrPlayer.SetActive(true);
currentPlayer = PlayerState.vrPlayer;
spawnedPlayerPrefab = PhotonNetwork.Instantiate("spawnedVRplayer", transform.position, transform.rotation);
}
public override void OnLeftRoom()
{
base.OnLeftRoom();
PhotonNetwork.Destroy(spawnedPlayerPrefab);
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
Debug.Log("a new player joined the room.");
base.OnPlayerEnteredRoom(newPlayer);
}
public override void OnPlayerLeftRoom(Player otherPlayer)
{
Debug.Log("a player left the room");
base.OnPlayerLeftRoom(otherPlayer);
}
public void Disconnect()
{
base.OnLeftRoom();
PhotonNetwork.Disconnect();
PhotonNetwork.LoadLevel("Lobby");
}
public override void OnDisconnected(DisconnectCause cause)
{
base.OnDisconnected(cause);
Debug.Log("Disconnected");
}
}
728x90
반응형
'Unity > 유니티VR' 카테고리의 다른 글
[유니티 VR] VR 캐릭터 리깅하기 (0) | 2021.11.04 |
---|---|
[유니티 VR] 장치 인식 코드 (0) | 2021.10.27 |
[유니티 VR] 컨트롤러 인터렉션 (0) | 2021.10.05 |
[유니티 VR 네트워크 개발] 유니티 VR클럽 개발기(feat. XR toolkit 세팅) (0) | 2021.09.26 |
전시 관리자를 위한 Oculus Quest Link사용방법(feat. 구글 원격데스크탑, Sidequest) (0) | 2020.12.21 |
Comments