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