60 lines
984 BLFS
C#
60 lines
984 BLFS
C#
using UnityEngine;
|
|
|
|
public class IdleCheck : MonoBehaviour
|
|
{
|
|
#region Singleton
|
|
|
|
public static IdleCheck singleton;
|
|
|
|
private void Awake()
|
|
{
|
|
if (singleton == null)
|
|
{
|
|
singleton = this;
|
|
}
|
|
else if (singleton != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
public bool IsEnabled = false;
|
|
public int Timeout = 300;
|
|
|
|
private float lastAction;
|
|
public void ReportAction()
|
|
{
|
|
lastAction = Time.time;
|
|
}
|
|
|
|
public bool IsIdle
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (!IsEnabled) return;
|
|
if (Input.anyKey) ReportAction();
|
|
|
|
if (Time.time - lastAction < Timeout)
|
|
return;
|
|
|
|
|
|
if (!IsIdle)
|
|
{
|
|
IsIdle = true;
|
|
// only in expo mode and not in title screen
|
|
if (CanvasManager.singleton.optionsMenu.ExpoModeEnabled && !CanvasManager.singleton.titleScreen.activeSelf)
|
|
{
|
|
Debug.Log("Idle, restarting game...");
|
|
GameManager.singleton.RestartGame();
|
|
}
|
|
}
|
|
}
|
|
}
|