아래 예제 코드는 onAirXR Client에 대해 발생하는 이벤트를 처리하는 방법에 대해 설명하고 있습니다.
using onAirXR.Server;
public class App : MonoBehaviour, AXRServer.EventHandler {
private bool _registered;
private void Update() {
// AXRServer GameObject가 생성되는 시점은
// i) XR이 처음 활성화될 때, 또는
// ii) (initialize XR on startup이 체크되어 있는 경우) 첫번째 프레임 직후
// 참고로 한번 생성된 AXR Server GameObject는 프로그램 종료 전까지 소멸되지 않음
if (_registered == false && AXRServer.instance != null) {
AXRServer.instance.RegisterEventHandler(this);
_registered = true;
}
}
private void OnDestroy() {
if (AXRServer.instance != null) {
AXRServer.instance.UnregisterEventHandler(this);
}
}
void AXRServer.EventHandler.OnConnect(AXRPlayerConfig config) {
// Client가 접속 시 호출됨
Debug.Log($"OnConnect: UserID = {config.userID}, place = {config.place}");
}
void AXRServer.EventHandler.OnActivate() {
// 사용자가 VR 헤드셋을 쓸 때 호출됨
Debug.Log("OnActivate");
}
void AXRServer.EventHandler.OnDeactivate() {
// 사용자가 VR 헤드셋을 벗을 때 호출됨
Debug.Log("OnDeactivate");
}
void AXRServer.EventHandler.OnDisconnect() {
// Client 접속이 끊어질 때 호출됨
Debug.Log("OnDisconnect");
}
void AXRServer.EventHandler.OnUserdataReceived(byte[] data) {}
}