using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
using UnityEngine.Events; 
 | 
  
 | 
public class GiftBaseCell : MonoBehaviour 
 | 
{ 
 | 
  
 | 
    Image m_QualityBG; 
 | 
    Image qualityBG 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            if (m_QualityBG == null) 
 | 
            { 
 | 
                m_QualityBG = this.transform.GetComponent<Image>("Container_GiftCell/qualityIcon"); 
 | 
            } 
 | 
            return m_QualityBG; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    Button m_GiftBtn; 
 | 
    Button giftBtn 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            if (m_GiftBtn == null) 
 | 
            { 
 | 
                m_GiftBtn = this.transform.GetComponent<Button>("Container_GiftCell"); 
 | 
            } 
 | 
            return m_GiftBtn; 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    Text m_GiftName; 
 | 
    Text giftName 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            if (m_GiftName == null) 
 | 
            { 
 | 
                m_GiftName = this.transform.GetComponent<Text>("Container_GiftCell/name"); 
 | 
            } 
 | 
            return m_GiftName; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    Transform m_LvRect; 
 | 
    Transform lvRect 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            if (m_LvRect == null) 
 | 
            { 
 | 
                m_LvRect = this.transform.Find("Container_GiftCell/lvrect"); 
 | 
            } 
 | 
            return m_LvRect; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    Text m_LvText; 
 | 
    Text lvText 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            if (m_LvText == null) 
 | 
            { 
 | 
                m_LvText = this.transform.GetComponent<Text>("Container_GiftCell/lvrect/lv"); 
 | 
            } 
 | 
            return m_LvText; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    Image m_StateImg; 
 | 
    Image stateImg 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            if (m_StateImg == null) 
 | 
            { 
 | 
                m_StateImg = this.transform.GetComponent<Image>("Container_GiftCell/state"); 
 | 
            } 
 | 
            return m_StateImg; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    void Awake() 
 | 
    { 
 | 
        LoadPrefab(); 
 | 
    } 
 | 
  
 | 
    //showState 0:不显示 1:新增 2:提升 
 | 
    //giftID 0 :代表未激活灰色 -1:代表不能激活 棕色,其他根据配表 
 | 
    public void Init(int giftID, int lv, UnityAction onclick = null, int showState = 0) 
 | 
    { 
 | 
        if (HeroTalentConfig.HasKey(giftID)) 
 | 
        { 
 | 
            var config = HeroTalentConfig.Get(giftID); 
 | 
            qualityBG.SetSprite("GiftQualityBG" + config.Quality); 
 | 
            giftBtn.AddListener(onclick); 
 | 
            giftName.text = config.Name; 
 | 
            lvText.text = lv.ToString(); 
 | 
            lvText.color = GetColor(1); 
 | 
            Outline textOutline = lvText.GetComponent<Outline>(); 
 | 
            textOutline.effectColor = GetOutlineColor(config.Quality); 
 | 
            lvRect.SetActive(lv > 0); 
 | 
            stateImg.SetActive(showState > 0); 
 | 
            stateImg.SetSprite("GiftState" + showState); 
 | 
            stateImg.SetNativeSize(); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            qualityBG.SetSprite("GiftQualityBG" + giftID); 
 | 
            giftBtn.RemoveAllListeners(); 
 | 
            giftName.text = string.Empty; 
 | 
            lvRect.SetActive(false); 
 | 
            stateImg.SetActive(false); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    Color32 GetColor(int quality) 
 | 
    { 
 | 
        if (quality == 1) 
 | 
        { 
 | 
            //D196FF 
 | 
            return new Color32(209, 150, 255, 255); 
 | 
        } 
 | 
        else if (quality == 2) 
 | 
        { 
 | 
            //ffda8c 
 | 
            return new Color32(255, 218, 140, 255); 
 | 
        } 
 | 
        else if (quality == 3) 
 | 
        { 
 | 
            //ffbd88 
 | 
            return new Color32(255, 189, 136, 255); 
 | 
        } 
 | 
        else if (quality == 4) 
 | 
        { 
 | 
            //ff8888 
 | 
            return new Color32(255, 136, 136, 255); 
 | 
        } 
 | 
        return new Color32(255, 255, 255, 255); 
 | 
    } 
 | 
  
 | 
    Color32 GetOutlineColor(int quality) 
 | 
    { 
 | 
        if (quality == 1) 
 | 
        { 
 | 
            //692088 
 | 
            return new Color32(105, 32, 136, 128); 
 | 
        } 
 | 
        else if (quality == 2) 
 | 
        { 
 | 
            //886220 
 | 
            return new Color32(136, 98, 32, 128); 
 | 
        } 
 | 
        else if (quality == 3) 
 | 
        { 
 | 
            //884a20 
 | 
            return new Color32(136, 74, 32, 128); 
 | 
        } 
 | 
        else if (quality == 4) 
 | 
        { 
 | 
            //882020 
 | 
            return new Color32(136, 32, 32, 128); 
 | 
        } 
 | 
        return new Color32(0, 0, 0, 128); 
 | 
    } 
 | 
  
 | 
    GameObject cellContainer; 
 | 
    protected void LoadPrefab() 
 | 
    { 
 | 
        if (cellContainer != null) 
 | 
            return; 
 | 
         
 | 
        var tmp = transform.Find("Container_GiftCell"); 
 | 
        if (tmp != null) 
 | 
        { 
 | 
            cellContainer = tmp.gameObject; 
 | 
            return; 
 | 
        } 
 | 
        if (cellContainer == null) 
 | 
        { 
 | 
            cellContainer = UIUtility.CreateWidget("GiftBaseCell", "Container_GiftCell"); 
 | 
  
 | 
            if (cellContainer != null) 
 | 
            { 
 | 
                cellContainer.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); 
 | 
                cellContainer.transform.SetAsFirstSibling(); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        //缩放到和父rect一样大 
 | 
        var scale = 1f; 
 | 
        var rect = cellContainer.GetComponent<RectTransform>(); 
 | 
        var parentRect = transform.GetComponent<RectTransform>(); 
 | 
        scale = parentRect.sizeDelta.x / rect.sizeDelta.x; 
 | 
        cellContainer.transform.localScale = new Vector3(scale, scale, scale); 
 | 
    } 
 | 
} 
 |