GuideController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. bool isAllGuideFinish = false;
  15. for (int i = 0; i < GuideCfgArray.Instance.dataArray.Length; i++)
  16. {
  17. if (GuideDataManager.IsGuideFinish(GuideCfgArray.Instance.dataArray[i].key) <= 0)
  18. {
  19. isAllGuideFinish = false;
  20. break;
  21. }
  22. isAllGuideFinish = true;
  23. }
  24. bool isGuide = GameGlobal.skipGuide == false && !isAllGuideFinish;
  25. return isGuide;
  26. }
  27. 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)
  28. {
  29. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  30. bool isStoryLevelGuide = cfg.storyLevelId > 0;
  31. bool isFinishCurId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.id) > 0;//当前引导未完成
  32. bool isFinishPriorId = cfg.priorId <= 0 || StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.priorId) > 0;//前置引导已完成
  33. bool isFinishCurIndex = GuideDataManager.IsGuideIndexFinish(cfg.id, index) == true;//当前index未完成
  34. bool isFinishPriorIndex = !checkPriorIndex || checkPriorIndex && GuideDataManager.IsGuideIndexFinish(cfg.id, index - 1) == true;//前置index已完成
  35. bool isCfgChapterOpen = MainStoryDataManager.CheckLevelUnlock(cfg.storyLevelId);//引导配置关卡已开启
  36. bool isCfgChapter = MainStoryDataManager.currentLevelCfgId == 0 || MainStoryDataManager.currentLevelCfgId == cfg.storyLevelId;//无选择(进入游戏时无选择)或当前所选择为配置关卡
  37. if (isStoryLevelGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && isCfgChapterOpen && isCfgChapter || !isStoryLevelGuide && !isFinishCurId)
  38. {
  39. GuideDataManager.currentGuideId = cfg.id;
  40. GuideDataManager.currentGuideIdIndex = index;
  41. GuideDataManager.SetGuideIndex(cfg.id, index);
  42. if (listIndex >= 0)
  43. {
  44. if (target.asList.numItems > 0)
  45. {
  46. GObject item = (target.asList).GetChildAt(listIndex);
  47. if (item != null)
  48. {
  49. target = item;
  50. // target.asList.ScrollToView(listIndex);
  51. }
  52. }
  53. else
  54. {
  55. return false;
  56. }
  57. }
  58. ShowGuideByIndex(target, guideStr, yTxt, cfg.optionalGuide == 1, devWidth, devHeight, GuideDataManager.currentGuideId, GuideDataManager.currentGuideIdIndex);
  59. if (!checkPriorIndex)
  60. {
  61. for (int i = 1; i < index; i++)
  62. {
  63. GuideDataManager.TryCompleteGuideIndex(cfg.id, i, false);
  64. }
  65. }
  66. return true;
  67. }
  68. return false;
  69. }
  70. 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)
  71. {
  72. HideGuide();
  73. if (GameGlobal.skipGuide)
  74. {
  75. return;
  76. }
  77. ViewManager.Show(ViewName.GUIDE_VIEW, new List<object> { target, guideStr, yTxt, isOptionalGuide, devWidth, devHeight, guideId, index });
  78. }
  79. public static bool TryCompleteGuideIndex(int guideId, int index)
  80. {
  81. HideGuide();
  82. if (GuideDataManager.TryCompleteGuideIndex(guideId, index))
  83. {
  84. return true;
  85. }
  86. return false;
  87. }
  88. public static async void TryCompleteGuide(string guideKey, int count)
  89. {
  90. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  91. bool result = false;
  92. if (!GuideDataManager.CheckAllIndexFinish(cfg.id, count)) return;
  93. result = await GuideDataManager.TryCompleteGuide(cfg.id);
  94. if (result)
  95. {
  96. GuideDataManager.currentGuideId = 0;
  97. HideGuide();
  98. }
  99. }
  100. public static void HideGuide()
  101. {
  102. ViewManager.Hide(ViewName.GUIDE_VIEW);
  103. }
  104. }
  105. }