IGuideLogic.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using System;
  2. using System.Collections.Generic;
  3. using Excel2Json;
  4. using Fort23.UTool;
  5. using UnityEngine.Device;
  6. namespace Fort23.Mono
  7. {
  8. public abstract class IGuideLogic
  9. {
  10. // /// <summary>
  11. // /// 是否是软性引导(还需要等待一些特殊的条件才触发的引导)
  12. // /// </summary>
  13. // public virtual bool issoftGuide => false;
  14. /// <summary>
  15. /// 引导ID
  16. /// </summary>
  17. public int guideID;
  18. public int guideIdx = 0;
  19. protected List<Action<UnityEngine.Object>> actionList = new List<Action<UnityEngine.Object>>();
  20. protected int step;
  21. public UnlockConfig uLockConfig;
  22. public object ActionObject;
  23. public PlayerGuideManager pgm;
  24. // public IGuideLogic(PlayerGuideManager guideManager)
  25. // {
  26. // this.pgm = guideManager;
  27. // }
  28. /// <summary>
  29. /// 新手,引导吧...
  30. /// </summary>
  31. public virtual async void Guide()
  32. {
  33. }
  34. public void Redo(int idx)
  35. {
  36. actionList[idx](null);
  37. }
  38. public void ClearList()
  39. {
  40. actionList.Clear();
  41. }
  42. /// <summary>
  43. /// 是否全面屏
  44. /// </summary>
  45. /// <returns></returns>
  46. public bool IsFullScreen()
  47. {
  48. float bl = Screen.width * 1.0f / Screen.height;
  49. if (bl <= 0.5f)
  50. {
  51. return true;
  52. }
  53. return false;
  54. }
  55. /// <summary>
  56. /// 之前引导是否被中断?
  57. /// </summary>
  58. /// <param name="length">引导长度</param>
  59. /// <param name="key">当前步骤</param>
  60. /// <returns></returns>
  61. protected bool IsPhaseBreak(int length, int key)
  62. {
  63. step = GetPhaseStep(key);
  64. //new do
  65. if (step == -1)
  66. {
  67. return false;
  68. }
  69. else if (step != length - 1)
  70. {
  71. LogTool.Log("上次引导中断了: " + key + "-" + step);
  72. return true;
  73. }
  74. else
  75. {
  76. return false;
  77. }
  78. }
  79. protected bool IsPhaseDone(int length, int key)
  80. {
  81. step = GetPhaseStep(key);
  82. if (step != -1)
  83. {
  84. FinishTriggerGuide(key);
  85. return true;
  86. }
  87. return false;
  88. }
  89. protected void FinishTriggerGuide(int key)
  90. {
  91. PlayerGuideManager.Instance.ResetPlayerGuide();
  92. PlayerGuideManager.Instance.FinishATriggerGuide();
  93. LogTool.Log("已完成引导:" + key);
  94. }
  95. public int GetPhaseStep(int key)
  96. {
  97. if (AccountFileInfo.Instance.playerData.phaseKey.Contains(key))
  98. {
  99. int idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(key);
  100. return AccountFileInfo.Instance.playerData.phaseValue[idx];
  101. }
  102. else
  103. {
  104. return -1;
  105. }
  106. }
  107. protected void SaveStep(int s)
  108. {
  109. //影子引导不记录.
  110. if (PlayerGuideManager.Instance.curPhase == 66)
  111. {
  112. return;
  113. }
  114. PlayerGuideManager.Instance.curStep = s;
  115. var phase = PlayerGuideManager.Instance.curPhase;
  116. AccountFileInfo.Instance.playerData.curPhase = phase;
  117. AccountFileInfo.Instance.playerData.curStep = s;
  118. if (!AccountFileInfo.Instance.playerData.phaseKey.Contains(phase))
  119. {
  120. AccountFileInfo.Instance.playerData.phaseKey.Add(phase);
  121. AccountFileInfo.Instance.playerData.phaseValue.Add(s);
  122. }
  123. else
  124. {
  125. var idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(phase);
  126. if (AccountFileInfo.Instance.playerData.phaseValue[idx] < s)
  127. {
  128. AccountFileInfo.Instance.playerData.phaseValue[idx] = s;
  129. }
  130. }
  131. LogTool.Log("guide message:" + "Phase=" + phase + " Step=" + s);
  132. AccountFileInfo.Instance.SavePlayerData();
  133. }
  134. public void SavePhase(int phase, int step = -1)
  135. {
  136. AccountFileInfo.Instance.playerData.curPhase = phase;
  137. AccountFileInfo.Instance.playerData.curStep = step;
  138. if (!AccountFileInfo.Instance.playerData.phaseKey.Contains(phase))
  139. {
  140. AccountFileInfo.Instance.playerData.phaseKey.Add(phase);
  141. AccountFileInfo.Instance.playerData.phaseValue.Add(step);
  142. }
  143. else
  144. {
  145. // var idx = AccountFileInfo.Instance.playerSettingInfo.phaseKey.IndexOf(phase);
  146. // AccountFileInfo.Instance.playerSettingInfo.phaseValue[idx] = step;
  147. LogTool.Warning("已保存过该步骤:" + phase);
  148. }
  149. AccountFileInfo.Instance.SavePlayerData();
  150. }
  151. public void SaveForceDone()
  152. {
  153. AccountFileInfo.Instance.playerData.isForceDone = true;
  154. AccountFileInfo.Instance.SavePlayerData();
  155. }
  156. public void SaveTriggerDone()
  157. {
  158. AccountFileInfo.Instance.playerData.isTriggerDone = true;
  159. AccountFileInfo.Instance.SavePlayerData();
  160. }
  161. /// <summary>
  162. /// 激活
  163. /// </summary>
  164. public virtual void Active()
  165. {
  166. isSkipGuide = false;
  167. }
  168. /// <summary>
  169. /// 是否跳过本引导(一般是引导过期了)
  170. /// </summary>
  171. public bool isSkipGuide = false;
  172. /// <summary>
  173. /// 开始
  174. /// </summary>
  175. public virtual void Begin()
  176. {
  177. // if (uLockConfig.ulockCondition == 1)
  178. // {
  179. // if (PlayerManager.Instance.curGuideGroupId != uLockConfig.ulockValue)
  180. // {
  181. // isSkipGuide = true;
  182. // }
  183. // }
  184. // else if (uLockConfig.ulockCondition == 2)
  185. // {
  186. // if (PlayerManager.Instance.Level > uLockConfig.ulockValue)
  187. // {
  188. // isSkipGuide = true;
  189. // }
  190. // }
  191. //
  192. // if (!isSkipGuide)
  193. // {
  194. // if (IsPhaseDone(actionList.Count, guideID))
  195. // {
  196. // isSkipGuide = true;
  197. // }
  198. // }
  199. }
  200. /// <summary>
  201. /// 更新循环
  202. /// </summary>
  203. public virtual void LogicUpdate()
  204. {
  205. }
  206. /// <summary>
  207. /// 结束
  208. /// </summary>
  209. public virtual void End()
  210. {
  211. }
  212. /// <summary>
  213. /// 释放逻辑,关闭
  214. /// </summary>
  215. public virtual void LogicRelase()
  216. {
  217. PlayerGuideManager.Instance.guideLogic = null;
  218. }
  219. public virtual void SkipGuide()
  220. {
  221. PlayerGuideManager.Instance.CloseForceGuide();
  222. }
  223. }
  224. }