您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
42 行
1.2 KiB
42 行
1.2 KiB
using UnityEngine;
|
|
|
|
namespace Unity.Netcode.TestHelpers.Runtime
|
|
{
|
|
/// <summary>
|
|
/// Can be used independently or assigned to <see cref="NetcodeIntegrationTest.WaitForConditionOrTimeOut"></see> in the
|
|
/// event the default timeout period needs to be adjusted
|
|
/// </summary>
|
|
public class TimeoutHelper
|
|
{
|
|
private const float k_DefaultTimeOutWaitPeriod = 2.0f;
|
|
|
|
private float m_MaximumTimeBeforeTimeOut;
|
|
private float m_TimeOutPeriod;
|
|
|
|
private bool m_IsStarted;
|
|
public bool TimedOut { get; internal set; }
|
|
|
|
public void Start()
|
|
{
|
|
m_MaximumTimeBeforeTimeOut = Time.realtimeSinceStartup + m_TimeOutPeriod;
|
|
m_IsStarted = true;
|
|
TimedOut = false;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
TimedOut = HasTimedOut();
|
|
m_IsStarted = false;
|
|
}
|
|
|
|
public bool HasTimedOut()
|
|
{
|
|
return m_IsStarted ? m_MaximumTimeBeforeTimeOut < Time.realtimeSinceStartup : TimedOut;
|
|
}
|
|
|
|
public TimeoutHelper(float timeOutPeriod = k_DefaultTimeOutWaitPeriod)
|
|
{
|
|
m_TimeOutPeriod = timeOutPeriod;
|
|
}
|
|
}
|
|
}
|