IndieGame/client/Packages/UnityTimer-1.1.0/Source/TimerExtensions.cs
DOBEST\zhaoyingjie f242607587 初始化工程
2024-10-11 10:12:15 +08:00

29 lines
1.3 KiB
C#

using System;
using UnityEngine;
/// <summary>
/// Contains extension methods related to <see cref="Timer"/>s.
/// </summary>
namespace UnityTimer {
public static class TimerExtensions
{
/// <summary>
/// Attach a timer on to the behaviour. If the behaviour is destroyed before the timer is completed,
/// e.g. through a scene change, the timer callback will not execute.
/// </summary>
/// <param name="behaviour">The behaviour to attach this timer to.</param>
/// <param name="duration">The duration to wait before the timer fires.</param>
/// <param name="onComplete">The action to run when the timer elapses.</param>
/// <param name="onUpdate">A function to call each tick of the timer. Takes the number of seconds elapsed since
/// the start of the current cycle.</param>
/// <param name="isLooped">Whether the timer should restart after executing.</param>
/// <param name="useRealTime">Whether the timer uses real-time(not affected by slow-mo or pausing) or
/// game-time(affected by time scale changes).</param>
public static Timer AttachTimer(this MonoBehaviour behaviour, float duration, Action onComplete,
Action<float> onUpdate = null, bool isLooped = false, bool useRealTime = false)
{
return Timer.Register(duration, onComplete, onUpdate, isLooped, useRealTime, behaviour);
}
}
}