lcy
5 天以前 485db99b5c51a971c173664cf6e808dc8424b0a0
Main/System/SkillUI/SkillBaseCell.cs
@@ -45,24 +45,57 @@
        }
    }
    Image m_WordBG;
    Image wordBG
    {
        get
        {
            if (m_WordBG == null)
            {
                m_WordBG = this.transform.GetComponent<Image>("Container_SkillCell/Image");
            }
            return m_WordBG;
        }
    }
    void Awake()
    {
        LoadPrefab();
    }
    private void Init(int skillID, UnityAction onclick, bool showType = false)
    public void Init(int skillID, UnityAction onclick = null, bool showType = false)
    {
        LoadPrefab();   //存在被卸载的可能,重新加载
        var config = SkillConfig.Get(skillID);
        skillIcon.SetSprite(config.IconName);
        skillBtn.AddListener(onclick);
        if (config == null)
        {
            Debug.LogErrorFormat("技能未配置 : {0}", skillID);
            return;
        }
        skillIcon.SetOrgSprite(config.IconName, "SkillIcon");
#if UNITY_EDITOR
        if (string.IsNullOrEmpty(config.IconName))
        {
            //内网测试
            skillIcon.SetOrgSprite("skillicondefault", "SkillIcon");
        }
#endif
        skillBtn.AddListener(()=>
        {
            onclick?.Invoke();
        });
        if (showType)
        {
            skillType.text = Language.Get(config.FuncType == 23 ? "HeroSkillType_1" : "HeroSkillType_2");
            skillType.text = Language.Get(config.FuncType == 1 ? "HeroSkillType_1" : "HeroSkillType_2");
            wordBG.SetActive(true);
        }
        else
        {
        {
            skillType.text = string.Empty;
            wordBG.SetActive(false);
        }
    }
@@ -71,7 +104,7 @@
    {
        if (cellContainer != null)
            return;
        var tmp = transform.Find("Container_SkillCell");
        if (tmp != null)
        {
@@ -88,6 +121,24 @@
                cellContainer.transform.SetAsFirstSibling();
            }
        }
        //缩放到和父rect一样大
        var scale = 1f;
        var rect = cellContainer.GetComponent<RectTransform>();
        var parentRect = transform.GetComponent<RectTransform>();
        float width = parentRect.sizeDelta.x;
        if (width <= 0f)
        {
            //外部控制了尺寸获取为0
            GridLayoutGroup grid = GetComponentInParent<GridLayoutGroup>();
            if (grid != null)
            {
                width = grid.cellSize.x;
            }
        }
        scale = width / rect.sizeDelta.x;
        cellContainer.transform.localScale = cellContainer.transform.localScale * scale;
    }
}