FunctionOpenDataManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using ET;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class FunctionOpenDataManager : SingletonBase<FunctionOpenDataManager>
  7. {
  8. /// <summary>
  9. /// 根据功能名检测功能是否开启
  10. /// </summary>
  11. /// <param name="functionId"></param>
  12. /// <returns></returns>
  13. public bool CheckIsFunOpenById(string functionId, bool showTips = true)
  14. {
  15. string name = ViewManager.GetName(functionId);
  16. FunctionOpenCfg cfg = FunctionOpenCfgArray.Instance.GetCfg(name);
  17. if (cfg == null)
  18. {
  19. // Debug.LogWarning("g功能.xlsx 功能开启_FunctionOpenCfg 未添加 " + viewName + " 的配置");
  20. return true;//未配置功能开启的暂时默认开启
  21. }
  22. if (cfg.parentId != null && cfg.parentId != "")
  23. {
  24. //先检查父功能是否开启
  25. if (!CheckIsFunOpenById(cfg.parentId, showTips))
  26. {
  27. return false;
  28. }
  29. }
  30. if (!CheckIsChapterFunOpen(cfg, showTips)) return false;
  31. if (!CheckIsLvFunOpen(cfg, showTips)) return false;
  32. return true;
  33. }
  34. /// <summary>
  35. /// 根据章节Id检测是否有新功能开启
  36. /// </summary>
  37. public void CheckHasChapterFunOpen(int storyLevelCfgId)
  38. {
  39. FunctionOpenCfg[] cfgs = FunctionOpenCfgArray.Instance.dataArray;
  40. List<string> listCfg = new List<string>();
  41. for (int i = 0; i < cfgs.Length; i++)
  42. {
  43. if (cfgs[i].show == 0) continue;
  44. if (cfgs[i].storyLevelId != storyLevelCfgId || !CheckIsChapterFunOpen(cfgs[i], false)) continue;
  45. if (!CheckIsLvFunOpen(cfgs[i], false)) continue;
  46. listCfg.Add(cfgs[i].id);
  47. }
  48. if (listCfg.Count > 0)
  49. {
  50. ViewManager.Show<FunctionOpenView>(listCfg);
  51. }
  52. }
  53. /// <summary>
  54. /// 根据角色Lv检测是否有新功能开启
  55. /// </summary>
  56. public void CheckHasLvFunOpen(int lv)
  57. {
  58. FunctionOpenCfg[] cfgs = FunctionOpenCfgArray.Instance.dataArray;
  59. List<string> listCfg = new List<string>();
  60. for (int i = 0; i < cfgs.Length; i++)
  61. {
  62. if (cfgs[i].show == 0) continue;
  63. if (lv != cfgs[i].lv || !CheckIsLvFunOpen(cfgs[i], false)) continue;
  64. if (!CheckIsChapterFunOpen(cfgs[i], false)) continue;
  65. listCfg.Add(cfgs[i].id);
  66. }
  67. if (listCfg.Count > 0)
  68. {
  69. ViewManager.Show<FunctionOpenView>(listCfg);
  70. }
  71. }
  72. //检测配置章节是否开启
  73. private bool CheckIsChapterFunOpen(FunctionOpenCfg cfg, bool showTips = true)
  74. {
  75. if (cfg.storyLevelId <= 0)
  76. {
  77. return true;
  78. }
  79. if (InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId))
  80. {
  81. return true;
  82. }
  83. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(cfg.storyLevelId);
  84. StoryChapterCfg storyChapterCfg = StoryChapterCfgArray.Instance.GetCfg(storyLevelCfg.chapterId);
  85. if (showTips) PromptController.Instance.ShowFloatTextPrompt(string.Format("通关主线{0}-{1}解锁", storyChapterCfg.order, storyLevelCfg.order));
  86. return false;
  87. }
  88. //检测配置角色是否开启
  89. private bool CheckIsLvFunOpen(FunctionOpenCfg cfg, bool showTips = true)
  90. {
  91. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv)
  92. {
  93. return true;
  94. }
  95. if (showTips) PromptController.Instance.ShowFloatTextPrompt(string.Format("角色达到{0}级解锁", cfg.lv));
  96. return false;
  97. }
  98. }
  99. }