60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using BNG;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.XR;
|
|
|
|
public class DeviceDisconnectController : MonoBehaviour
|
|
{
|
|
public UnityEvent OnTotalDisconnect;
|
|
|
|
private Coroutine coroutine;
|
|
private InputBridge inputBridge;
|
|
|
|
private void Awake()
|
|
{
|
|
inputBridge = GetComponent<InputBridge>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
inputBridge.OnConnected.AddListener(OnDeviceConnected);
|
|
inputBridge.OnDisconnected.AddListener(OnDeviceDisconnected);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
inputBridge.OnConnected.RemoveListener(OnDeviceConnected);
|
|
inputBridge.OnDisconnected.RemoveListener(OnDeviceDisconnected);
|
|
}
|
|
|
|
private void OnDeviceConnected()
|
|
{
|
|
if (coroutine != null)
|
|
{
|
|
StopCoroutine(coroutine);
|
|
coroutine = null;
|
|
UIInfoDisplay.Instance.HideInfo(DisplayMessageType.DeviceLost);
|
|
}
|
|
}
|
|
|
|
private void OnDeviceDisconnected()
|
|
{
|
|
if (coroutine != null)
|
|
return;
|
|
|
|
coroutine = StartCoroutine(DisconnectTime());
|
|
}
|
|
|
|
private IEnumerator DisconnectTime()
|
|
{
|
|
UIInfoDisplay.Instance.ShowInfo(DisplayMessageType.DeviceLost);
|
|
Debug.Log("Наденьте шлем");
|
|
yield return new WaitForSeconds(15);
|
|
SceneLoader.Instance.LoadStartScene();
|
|
OnTotalDisconnect?.Invoke();
|
|
}
|
|
}
|