长时间无操作返回待机
方式一、使用框架内置事件
using UnityEngine;
using UNIHper;
using UniRx;
public class SceneEntryScript : SceneScriptBase
{
// Called once after scene is loaded
private void Start()
{
// 设置长时间无操作超时时间
Managements.Framework.SetLongTimeNoOperationTimeout(300);
// 监听长时间无操作事件
Managements.Framework
.OnLongTimeNoOperationAsObservable()
.Subscribe(_ =>
{
Debug.LogWarning("LongTimeNoOperation");
});
// 手动重置超时计时器, 默认对鼠标、键盘、触摸屏事件均进行了监听所以不需要手动调用
Managements.Framework.ResetLongTimeNoOperation();
}
// Called per frame after Start
private void Update() { }
}
方式二、自定义实现
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UNIHper;
public class SceneEntryScript : SceneScriptBase
{
/* 默认情况下鼠标键盘、触摸屏输入将会自动重置操作,无需主动调用。
你可以在其他有互动的地方主动调用Managements.SceneScript<SceneEntryScript>().ResetOperation();
来重置操作时间
*/
LongTimeNoOperation longTimeNoOperation = new LongTimeNoOperation(60,() =>
{
// 60秒没有操作时,会调用这个回调函数
Debug.Log("LongTimeNoOperation");
});
public void ResetOperation()=>longTimeNoOperation.ResetOperation();
private void Start() {
// 也可以在后续逻辑重置超时时间
longTimeNoOperation.SetTimeout(60);
}
}
Last updated