//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, January 31, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; //灵宠的技能 namespace vnxbqy.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.SetActive(false); } else { lockObj.SetActive(true); if (!isAll) { lockLvText.SetActive(true); lockLvText.text = Language.Get("LoadIconLV", skillUnlock); } else { lockLvText.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 effect = SkillConfig.GetSkillEffectValue(skillConfig); var count = effect.GetHasValueCount(); var values = new float[count]; if (petModel.TryGetPetSkills(effect, out skills)) { foreach (var id in skills) { if (petModel.IsSkillUnlock(id)) { var skillEffectGroup = petModel.GetSkillEffectGroup(id); for (int i = 0; i < count; i++) { values[i] += skillEffectGroup.GetEffectValue(i); } var config = SkillConfig.Get(id); fightPower += config.FightPower; } } } str[0] = SkillConfig.GetSkillDescription(skillConfig.Description, values); str[1] = string.Empty; } SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.PetSkill, fightPower, str); 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 count = effect.GetHasValueCount(); var values = new float[count]; if (mountModel.TryGetHorseSkills(effect, out skills)) { foreach (var id in skills) { if (mountModel.IsSkillUnlock(id)) { var skillEffectGroup = mountModel.GetSkillEffectGroup(id); for (int i = 0; i < count; i++) { values[i] += skillEffectGroup.GetEffectValue(i); } var config = SkillConfig.Get(id); fightPower += config.FightPower; } } } str[0] = SkillConfig.GetSkillDescription(skillConfig.Description, values); str[1] = string.Empty; } } SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.MountSkill, fightPower, str); break; } }); } } public enum SkillType { PetSkill, MountSkill, } }