FunctionOpenDataManager.cs 3.6 KB

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