GuideController.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using FairyGUI;
  2. using UI.DressUp;
  3. using UI.Main;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UI.ClothingSynthetic;
  7. using ET;
  8. namespace GFGGame
  9. {
  10. public class GuideController
  11. {
  12. public static bool IsGuide()
  13. {
  14. if (!GameGlobal.isEnterGame) return false;//未进入游戏
  15. bool isAllGuideFinish = false;
  16. for (int i = 0; i < GuideCfgArray.Instance.dataArray.Length; i++)
  17. {
  18. if (GuideDataManager.IsGuideFinish(GuideCfgArray.Instance.dataArray[i].key) <= 0)
  19. {
  20. isAllGuideFinish = false;
  21. break;
  22. }
  23. isAllGuideFinish = true;
  24. }
  25. bool isGuide = GameGlobal.skipGuide == false && !isAllGuideFinish;
  26. return isGuide;
  27. }
  28. /// <summary>
  29. /// 检测当前角色等级是否有引导开启,若有则返回引导id
  30. /// </summary>
  31. /// <returns></returns>
  32. public static string CheckHasRoleLvGuideOpen()
  33. {
  34. GuideCfg[] guideCfgs = GuideCfgArray.Instance.dataArray;
  35. for (int i = 0; i < guideCfgs.Length; i++)
  36. {
  37. if (guideCfgs[i].roleLv <= 0) continue;
  38. bool isFinishCurId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + guideCfgs[i].id) > 0;
  39. if (!isFinishCurId)
  40. {
  41. return guideCfgs[i].viewName;
  42. }
  43. }
  44. return "";
  45. }
  46. public static bool TryGuide(GObject target, string guideKey, int index, string guideStr = null, int listIndex = -1, bool checkPriorIndex = true, int yTxt = 0, float devWidth = 0, float devHeight = 0, bool showAni = true, bool checkChapterPass = false, bool isOptionalGuide = false)
  47. {
  48. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  49. bool isStoryLevelGuide = cfg.storyLevelId > 0;
  50. bool isFinishCurId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.id) > 0;//当前引导未完成
  51. bool isFinishPriorId = cfg.priorId <= 0 || StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.priorId) > 0;//前置引导已完成
  52. bool isFinishCurIndex = GuideDataManager.IsGuideIndexFinish(cfg.id, index) == true;//当前index未完成
  53. bool isFinishPriorIndex = !checkPriorIndex || checkPriorIndex && GuideDataManager.IsGuideIndexFinish(cfg.id, index - 1) == true;//前置index已完成
  54. bool isCfgChapterOpen = MainStoryDataManager.CheckLevelUnlock(cfg.storyLevelId);//引导配置关卡已开启
  55. if (checkChapterPass && !isCfgChapterOpen)
  56. {//cfg.storyLevelId为当前关卡,通关时 MainStoryDataManager.currentLevelCfgId为下一章的第一关,但下一章有可能因为角色等级不足未开启,会导致引导无法正常开启,所以添加是否通关检测
  57. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(cfg.storyLevelId);
  58. if (levelCfg.chapterId - 1 > 0)
  59. {
  60. isCfgChapterOpen = MainStoryDataManager.CheckNeedChapterPass(levelCfg.chapterId - 1, out int needChapterId);
  61. }
  62. }
  63. bool isCfgChapter = MainStoryDataManager.currentLevelCfgId == 0 || MainStoryDataManager.currentLevelCfgId == cfg.storyLevelId;//无选择(进入游戏时无选择)或当前所选择为配置关卡
  64. bool isRoleLvGuide = cfg.roleLv > 0;
  65. bool iscurRoleLv = RoleDataManager.lvl >= cfg.roleLv;
  66. if (isStoryLevelGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && isCfgChapterOpen && isCfgChapter || !isStoryLevelGuide && !isRoleLvGuide && !isFinishCurId || isRoleLvGuide && !isFinishCurId && iscurRoleLv)
  67. {
  68. GuideDataManager.currentGuideId = cfg.id;
  69. GuideDataManager.currentGuideIdIndex = index;
  70. GuideDataManager.SetGuideIndex(cfg.id, index);
  71. if (listIndex >= 0)
  72. {
  73. if (target.asList.numItems > 0)
  74. {
  75. GObject item = (target.asList).GetChildAt(listIndex);
  76. if (item != null)
  77. {
  78. target = item;
  79. // target.asList.ScrollToView(listIndex);
  80. }
  81. }
  82. else
  83. {
  84. return false;
  85. }
  86. }
  87. bool _isOptionalGuide = isOptionalGuide ? isOptionalGuide : cfg.optionalGuide == 1;
  88. ShowGuideByIndex(target, guideStr, yTxt, _isOptionalGuide, devWidth, devHeight, GuideDataManager.currentGuideId, GuideDataManager.currentGuideIdIndex, showAni);
  89. if (!checkPriorIndex)
  90. {
  91. for (int i = 1; i < index; i++)
  92. {
  93. GuideDataManager.TryCompleteGuideIndex(cfg.id, i, false);
  94. }
  95. }
  96. return true;
  97. }
  98. return false;
  99. }
  100. private static void ShowGuideByIndex(GObject target, string guideStr = null, int yTxt = 0, bool isOptionalGuide = false, float devWidth = 0, float devHeight = 0, int guideId = 0, int index = 0, bool showAni = true)
  101. {
  102. HideGuide();
  103. if (GameGlobal.skipGuide)
  104. {
  105. return;
  106. }
  107. ViewManager.Show(ViewName.GUIDE_VIEW, new List<object> { target, guideStr, yTxt, isOptionalGuide, devWidth, devHeight, guideId, index, showAni });
  108. }
  109. public static bool TryCompleteGuideIndex(int guideId, int index)
  110. {
  111. HideGuide();
  112. if (GuideDataManager.TryCompleteGuideIndex(guideId, index))
  113. {
  114. return true;
  115. }
  116. return false;
  117. }
  118. public static async void TryCompleteGuide(string guideKey, int count)
  119. {
  120. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  121. bool result = false;
  122. if (!GuideDataManager.CheckAllIndexFinish(cfg.id, count)) return;
  123. result = await GuideDataManager.TryCompleteGuide(cfg.id);
  124. if (result)
  125. {
  126. GuideDataManager.currentGuideId = 0;
  127. HideGuide();
  128. }
  129. }
  130. public static void HideGuide()
  131. {
  132. ViewManager.Hide(ViewName.GUIDE_VIEW);
  133. }
  134. }
  135. }