rabidus-test/Assets/Scripts/DeviceDisconnectController.cs

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.LoadScene("StartScene");
OnTotalDisconnect?.Invoke();
}
}