您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

87 行
2.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using SUISS.Storage;
  4. namespace SUISSEngine
  5. {
  6. public abstract class DailyAbstractState<T> : AbstractState<T> where T : DailyAbstractState<T>
  7. {
  8. protected override void Awake()
  9. {
  10. base.Awake();
  11. Daily.Day value = this.GetValue<Daily.Day>("Daily_SavedDay", null);
  12. if (!object.Equals(value, Singleton<Daily>.Instance.CurrentDay))
  13. {
  14. this.SaveDailyState();
  15. }
  16. Singleton<Daily>.Instance.CurrentDayChanged += this.OnCurrentDayChanged;
  17. }
  18. protected override void Start()
  19. {
  20. base.Start();
  21. }
  22. protected override void OnDestroy()
  23. {
  24. base.OnDestroy();
  25. if (Singleton<Daily>.IsAvailable)
  26. {
  27. Singleton<Daily>.Instance.CurrentDayChanged -= this.OnCurrentDayChanged;
  28. }
  29. }
  30. public virtual object GetStartOfDayValue(string key)
  31. {
  32. return this.GetStartOfDayValue(key, null);
  33. }
  34. public virtual object GetStartOfDayValue(string key, object defaultValue)
  35. {
  36. object result;
  37. if (!base.Persistent.TryGetValue("Daily_" + key, out result))
  38. {
  39. result = defaultValue;
  40. }
  41. return result;
  42. }
  43. private void OnCurrentDayChanged(Daily.Day previousDay, Daily.Day newDay)
  44. {
  45. this.SaveDailyState();
  46. }
  47. private void SaveDailyState()
  48. {
  49. Dictionary<string, object> persistent = base.Persistent;
  50. List<string> list = new List<string>(persistent.Keys);
  51. int i = 0;
  52. while (i < list.Count)
  53. {
  54. string text = list[i];
  55. if (text.StartsWith("Daily_"))
  56. {
  57. persistent.Remove(text);
  58. list.RemoveAt(i);
  59. }
  60. else
  61. {
  62. i++;
  63. }
  64. }
  65. foreach (string text2 in list)
  66. {
  67. object obj = persistent[text2];
  68. object value = Storage.CloneObject(obj);
  69. persistent["Daily_" + text2] = value;
  70. base.FireValueChangedHandler(text2, obj, obj);
  71. }
  72. persistent["Daily_SavedDay"] = Singleton<Daily>.Instance.CurrentDay;
  73. }
  74. public const string DailyKeyPrefix = "Daily_";
  75. public const string SavedDayKey = "Daily_SavedDay";
  76. }
  77. }