IClock.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. namespace XGame.Framework.Time
  3. {
  4. /// <summary>
  5. /// 时钟,内置闹钟和定时器
  6. /// </summary>
  7. public interface IClock : ITimeUpdate, IDisposable
  8. {
  9. /// <summary>
  10. /// 设置时间戳,用于校准时间
  11. /// </summary>
  12. /// <param name="timestamp">时间戳,单位:毫秒</param>
  13. /// <param name="clockTyp">时钟类型(客户端时间or服务端时间,默认服务端时间)</param>
  14. void SetTime(long timestamp, ClockType clockTyp = ClockType.Server);
  15. /// <summary>
  16. /// 获取当前时间戳(毫秒)
  17. /// </summary>
  18. /// <param name="clockTyp">时钟类型(客户端时间or服务端时间,默认服务端时间)</param>
  19. /// <returns></returns>
  20. long GetNowTime(ClockType clockTyp = ClockType.Server);
  21. /// <summary>
  22. /// 添加闹钟
  23. /// </summary>
  24. /// <param name="triggerTimestamp">目标时间戳(毫秒)</param>
  25. /// <param name="action">回调</param>
  26. /// <param name="clockTyp">时钟类型(客户端时间or服务端时间,默认服务端时间)</param>
  27. /// <returns>此闹钟</returns>
  28. IAlarm AddAlarm(long triggerTimestamp, Action action, ClockType clockTyp = ClockType.Server);
  29. /// <summary>
  30. /// 添加计时器
  31. /// </summary>
  32. /// <param name="delay">延时(毫秒)</param>
  33. /// <param name="action">回调</param>
  34. /// <returns>此计时器</returns>
  35. ITimer AddDelayTimer(int delay, Action action);
  36. /// <summary>
  37. /// 添加循环定时器(使用客户端时间)
  38. /// </summary>
  39. /// <param name="interval">循环间隔,单位:毫秒</param>
  40. /// <param name="action">触发事件,参数为循环的次数</param>
  41. /// <param name="loopTime">循环次数, 默认-1(-1为无限,0和1都是1次)</param>
  42. /// <returns>定时器</returns>
  43. ITimer AddLooperTimer(int delay, int interval, Action<int> action, int loopTime = -1);
  44. }
  45. }