| using System;  | 
| using System.Collections;  | 
| using System.Collections.Generic;  | 
|   | 
| using UnityEngine;  | 
| using UnityEngine.UI;  | 
|   | 
| namespace vnxbqy.UI  | 
| {  | 
|     public class TalentSkillBehaviour : MonoBehaviour  | 
|     {  | 
|         [SerializeField] Image m_Icon;  | 
|         [SerializeField] Text m_Level;  | 
|         [SerializeField] Button m_Button;  | 
|         [SerializeField] RectTransform m_ContainerSelect;  | 
|   | 
|         int skillId = 0;  | 
|   | 
|         TalentModel model { get { return ModelCenter.Instance.GetModel<TalentModel>(); } }  | 
|   | 
|         private void Awake()  | 
|         {  | 
|             m_Button.onClick.AddListener(SelectSkill);  | 
|         }  | 
|   | 
|         public void Display(int _skillId)  | 
|         {  | 
|             skillId = _skillId;  | 
|             model.talentSkillUpdate -= TalentSkillUpdate;  | 
|             model.talentSkillUpdate += TalentSkillUpdate;  | 
|             model.selectSkillEvent -= OnSelectSkillEvent;  | 
|             model.selectSkillEvent += OnSelectSkillEvent;  | 
|             model.talentPointUpdate -= TalentPointUpdate;  | 
|             model.talentPointUpdate += TalentPointUpdate;  | 
|             model.talentSkillLevelUp -= TalentSkillLevelUp;  | 
|             model.talentSkillLevelUp += TalentSkillLevelUp;  | 
|             Display();  | 
|         }  | 
|   | 
|         private void Display()  | 
|         {  | 
|             TalentSkill talent;  | 
|             if (model.TryGetTalent(skillId, out talent))  | 
|             {  | 
|                 var config = SkillConfig.Get(talent.skillId);  | 
|                 if (config != null)  | 
|                 {  | 
|                     m_Icon.SetSprite(config.IconName);  | 
|                 }  | 
|                 m_Level.text = StringUtility.Contact(talent.level, "/", talent.maxLevel);  | 
|                 DisplayState();  | 
|                 m_ContainerSelect.SetActive(skillId == model.selectSkill);  | 
|             }  | 
|         }  | 
|   | 
|         private void DisplayState()  | 
|         {  | 
|             TalentSkill talent;  | 
|             if (model.TryGetTalent(skillId, out talent))  | 
|             {  | 
|                 var error = 0;  | 
|                 m_Icon.material = talent.level > 0 || model.SatisfyLevelUp(talent.skillId, out error) ?  | 
|                     MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();  | 
|             }  | 
|         }  | 
|   | 
|         private void TalentSkillUpdate(int _skillid)  | 
|         {  | 
|             if (skillId == _skillid)  | 
|             {  | 
|                 Display();  | 
|             }  | 
|             else if (skillId != 0)  | 
|             {  | 
|                 DisplayState();  | 
|             }  | 
|         }  | 
|   | 
|         private void OnSelectSkillEvent()  | 
|         {  | 
|             m_ContainerSelect.SetActive(skillId == model.selectSkill);  | 
|         }  | 
|   | 
|         public void Dispose()  | 
|         {  | 
|             model.talentSkillUpdate -= TalentSkillUpdate;  | 
|             model.selectSkillEvent -= OnSelectSkillEvent;  | 
|             model.talentPointUpdate -= TalentPointUpdate;  | 
|             model.talentSkillLevelUp -= TalentSkillLevelUp;  | 
|         }  | 
|   | 
|         private void TalentSkillLevelUp(int _skillId)  | 
|         {  | 
|             if (skillId != 0 && skillId == _skillId)  | 
|             {  | 
|                 EffectMgr.Instance.PlayUIEffect(3069, 2500, transform, false);  | 
|             }  | 
|         }  | 
|   | 
|         private void TalentPointUpdate()  | 
|         {  | 
|             if (skillId != 0)  | 
|             {  | 
|                 DisplayState();  | 
|             }  | 
|         }  | 
|   | 
|         private void SelectSkill()  | 
|         {  | 
|             if (skillId != 0)  | 
|             {  | 
|                 model.selectSkill = skillId;  | 
|             }  | 
|         }  | 
|     }  | 
| }  | 
|   |