//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, January 31, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; //灵宠的技能 namespace Snxxz.UI { public class SkillButtonPet : CellView { [SerializeField] Button skillBtn; [SerializeField] Image skillIcon; [SerializeField] GameObject lockObj; [SerializeField] Text lockLvText; PetModel petModel { get { return ModelCenter.Instance.GetModel(); } } MountModel mountModel { get { return ModelCenter.Instance.GetModel(); } } public void SetModel(int skillId, int skillUnlock, bool isUnlock, int petId, SkillType skillType, bool isAll = false) { SkillConfig skillConfig = SkillConfig.Get(skillId); if (skillConfig == null) return; skillIcon.SetSprite(skillConfig.IconName); if (isUnlock) { lockObj.SetActive(false); lockLvText.gameObject.SetActive(false); } else { lockObj.SetActive(true); if (!isAll) { lockLvText.gameObject.SetActive(true); lockLvText.text = skillUnlock +Language.Get("Z1041"); } else { lockLvText.gameObject.SetActive(false); } } skillBtn.RemoveAllListeners(); skillBtn.AddListener(() => { string[] str = new string[2]; int fightPower = 0; switch (skillType) { case SkillType.PetSkill: if (petModel.TryGetPetId(skillId, out petId)) { PetInfoConfig petInfo = PetInfoConfig.Get(petId); str[0] = skillConfig.Description; str[1] = Language.Get("pet_SkillTipLv", petInfo.Name, petModel.GetSkillUnlockLevel(skillId)); fightPower = skillConfig.FightPower; } else { List skills; var value = 0; var effect = SkillConfig.GetSkillEffectValue(skillConfig); if (petModel.TryGetPetSkills(effect, out skills)) { foreach (var id in skills) { if (petModel.IsSkillUnlock(id)) { var config = SkillConfig.Get(id); value += config.EffectValue11; fightPower += config.FightPower; } } } str[0] = string.Format(skillConfig.Description, value); str[1] = string.Empty; } break; case SkillType.MountSkill: { if (mountModel.GetMountSkillAndItem.ContainsKey(skillId)) { var horseId = mountModel.GetMountSkillAndItem[skillId].HorseID; var horseConfig = HorseConfig.Get(horseId); if (horseConfig != null) { str[0] = skillConfig.Description; str[1] = Language.Get("pet_SkillTipLv", horseConfig.Name, mountModel.GetSkillUnlockLevel(skillId)); } fightPower = skillConfig.FightPower; } else { var effect = SkillConfig.GetSkillEffectValue(skillConfig); List skills; var value = 0; if (mountModel.TryGetHorseSkills(effect, out skills)) { foreach (var id in skills) { if (mountModel.IsSkillUnlock(id)) { var config = SkillConfig.Get(id); value += config.EffectValue11; fightPower += config.FightPower; } } } str[0] = string.Format(skillConfig.Description, value); str[1] = string.Empty; } } break; } SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.PetSkill, fightPower, str); }); } } public enum SkillType { PetSkill, MountSkill, } }