using System; using System.Collections.Generic; using Core.Utility; using Excel2Json; using Fort23.Core; using Fort23.UTool; using GameLogic.Bag; using GameLogic.Hero; using UnityEngine; using UnityEngine.UI; namespace Fort23.Mono { public static class HeroUITools { public static WidgetHero GetCloseHero(List widgetHeroes, WidgetHero widgetHero, bool isNext) { int idx = widgetHeroes.IndexOf(widgetHero); if (isNext && idx < widgetHeroes.Count - 1) { return widgetHeroes[idx + 1]; } if (!isNext && idx > 0) { return widgetHeroes[idx - 1]; } return null; } /// /// 获取技能参数 /// /// /// public static object[] GetSkillParam(SkillConfig skillConfig) { object[] data = null; if (skillConfig.SkillType == 5) { data = new object[skillConfig.addPropertyValue.Length]; for (int j = 0; j < skillConfig.addPropertyValue.Length; j++) { data[j] = skillConfig.addPropertyValue[j]; } } else { data = new object[skillConfig.effectValue.Length]; for (int j = 0; j < skillConfig.effectValue.Length; j++) { data[j] = skillConfig.effectValue[j]; } } return data; } /// /// 是否显示职业装备的小红点 /// /// /// public static bool IsShowRedPointProEq(int zy) { if (PlayerManager.Instance.eqController.allBestEqDic != null) { if (PlayerManager.Instance.eqController.allBestEqDic.TryGetValue(zy, out var bestEq)) { if (bestEq.Count > 0) { return true; } } } return false; } /// /// 更新对应职业的装备图标 /// 该方法调用后,可以把装备了的职业装备, 显示到指定的UI(eqsUIObj)上 /// /// 职业类型 /// 装备的icon public static async void UpdateZyEqIcon(int zy, List eqsUIObj, string poolName = "eq", float size = 1, Action action = null) { List eqList = PlayerManager.Instance.eqController.equipZyEqDic[zy]; for (int i=0; i < 5; i++) { bool empty = true; ItemInfo eqInfo = null; foreach (ItemInfo itemInfo in eqList) { if (itemInfo.eqInfo.basicEquipConfig.Type == i + 1) { empty = false; eqInfo = itemInfo; break; } } GameObject eqGo = eqsUIObj[0] as GameObject; WidgetItem eqItem = await UIManager.Instance. CreateGComponentForObject(eqGo, null, isInstance:true, poolName:poolName, root:eqGo.transform.parent.GetComponent()); eqItem.transform.localScale = new Vector3(size, size, size); if (empty) { // LogTool.Log(zy + "---" + i + "空"); eqItem.SetEmpty(action); } else { eqItem.InitWidget(eqInfo, action); } eqItem.numObj.SetActive(false); } } public static string GetEquipmentIconName(ItemInfo eqItem) { int q = 1; if (eqItem.eqInfo.quality > 3 && eqItem.eqInfo.quality <= 4) { q = 2; } else if (eqItem.eqInfo.quality > 4) { q = 3; } string eqIcon = "icon_eq_" + eqItem.eqInfo.basicEquipConfig.profession + "_" + eqItem.eqInfo.basicEquipConfig.Type + "_" + q; // switch (eqItem.eqInfo.basicEquipConfig.profession) return eqIcon; } /// /// 根据星级,显示不同的数量的星星和样子 /// /// /// public static void SetStarShow(List stars, int starGrade) { // 最大星级展示个数(6星,只显示一颗星星,换颜色) int maxShowStar = 5; // 计算 当前星级 应该用什么星星的表现 int group = (starGrade - 1) / maxShowStar; int i = 1; int showCount = (starGrade - 1) % maxShowStar + 1; foreach (GameObject star in stars) { SetStarImg(group, star); // 根据星级显示星星 if (showCount >= i) { star.SetActive(true); } else { star.SetActive(false); } i++; } SimpleLayout.Layout(stars, LayoutType.Horizontal); } private static void SetStarImg(int group, GameObject starObj) { MyImage image = starObj.GetComponent(); // 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium switch (group) { case 0: // n = 1~5 image.icon_name = "dec_star"; break; case 1: // n = 6~10 image.icon_name = "dec_star_2"; break; default: // 其他情况 LogTool.Error("超出设计表现"); //image.icon_name = "dec_star"; break; } } /// /// 是否展示"去升级"的引导 /// /// /// public static bool IsLvUpShowGuild(HeroInfo heroInfo) { long totalExp = heroInfo.powerUpConfig.levelUpExp; for (int i = 1; i < 10; i++) { HeroPowerUpConfig powerUpConfig = ConfigComponent.Instance.Get(heroInfo.promoteConfig.ID + i); totalExp += powerUpConfig.levelUpExp; } if (BagController.Instance.IsEnough(GlobalParam.Item_HeroExp_ID, totalExp) && heroInfo.level.Value - PlayerManager.Instance.heroController.mainLevel < 10) { return true; } return false; } /// /// 打开对应职业的装备面板 /// /// 1战士;2法师;3牧师;4游侠 public static async void OpenSpecificProfessionEquipmentPanel(int zy, Action action = null) { SpecificProfessionEquipmentPanel specificProfessionEquipmentPanel = await UIManager.Instance.LoadAndOpenPanel(null); specificProfessionEquipmentPanel.InitPanel(zy, action); } /// /// 修改指定 GameObject 和其所有子对象的 Layer /// /// 目标 GameObject /// 新的 Layer 值 public static void ChangeLayerRecursively(GameObject obj, int newLayer) { if (obj == null || obj.layer == newLayer) return; // 修改当前对象的 Layer obj.layer = newLayer; // 遍历所有子对象,递归修改 foreach (Transform child in obj.transform) { ChangeLayerRecursively(child.gameObject, newLayer); } } public static string GetZyIcon(int zy) { string iconZhiYe = ""; switch (zy) { case 1 : iconZhiYe = "icon_zy_Shield"; break; case 2 : iconZhiYe = "icon_zy_Hat"; break; case 3 : iconZhiYe = "icon_zy_Potion"; break; case 4 : iconZhiYe = "icon_zy_Bow"; break; } return iconZhiYe; } } }