UpdateModule.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. namespace IFramework
  2. {
  3. /// <summary>
  4. /// OnUpdate OnEnable OnDisable
  5. /// </summary>
  6. public abstract class UpdateModule: Module
  7. {
  8. private bool _enable;
  9. /// <summary>
  10. /// 开启关闭 Update
  11. /// </summary>
  12. public bool enable
  13. {
  14. get { return _enable; }
  15. set
  16. {
  17. if (_enable != value)
  18. _enable = value;
  19. if (_enable)
  20. OnEnable();
  21. else
  22. OnDisable();
  23. }
  24. }
  25. /// <summary>
  26. /// 改变 enable
  27. /// </summary>
  28. /// <param name="enable"></param>
  29. public void SetActive(bool enable) { this.enable = enable; }
  30. /// <summary>
  31. /// 释放
  32. /// </summary>
  33. public override void Dispose()
  34. {
  35. enable = false;
  36. base.Dispose();
  37. }
  38. /// <summary>
  39. /// 刷新
  40. /// </summary>
  41. public void Update()
  42. {
  43. if (!enable || disposed) return;
  44. OnUpdate();
  45. }
  46. #pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
  47. protected abstract void OnUpdate();
  48. protected virtual void OnEnable() { }
  49. protected virtual void OnDisable() { }
  50. #pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
  51. }
  52. }