| | |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using System; |
| | | |
| | | public class BattleBuffCell : CellView |
| | | public class BattleBuffCell : MonoBehaviour |
| | | { |
| | | public Image imageIcon; |
| | | public Text textLevel; |
| | | |
| | | public void Display(HB428_tagSCBuffRefresh hB428_TagSCBuffRefresh) |
| | | ImageEx m_buffIcon; |
| | | ImageEx buffIcon |
| | | { |
| | | SkillConfig skillConfig = SkillConfig.Get((int)hB428_TagSCBuffRefresh.SkillID); |
| | | get |
| | | { |
| | | if (m_buffIcon == null) |
| | | { |
| | | m_buffIcon = this.transform.GetComponent<ImageEx>("Container_BuffCell/Img_Icon"); |
| | | } |
| | | return m_buffIcon; |
| | | } |
| | | } |
| | | |
| | | imageIcon.sprite = ResManager.Instance.LoadAsset<Sprite>("", skillConfig.IconName); |
| | | textLevel.text = hB428_TagSCBuffRefresh.Layer.ToString(); |
| | | Button m_buffButton; |
| | | Button buffButton |
| | | { |
| | | get |
| | | { |
| | | if (m_buffButton == null) |
| | | { |
| | | m_buffButton = gameObject.GetComponent<Button>(); |
| | | } |
| | | return m_buffButton; |
| | | } |
| | | } |
| | | |
| | | TextEx m_BuffLayer; |
| | | |
| | | TextEx buffLayer |
| | | { |
| | | get |
| | | { |
| | | if (m_BuffLayer == null) |
| | | { |
| | | m_BuffLayer = this.transform.GetComponent<TextEx>("Container_BuffCell/Text_Layer"); |
| | | } |
| | | return m_BuffLayer; |
| | | } |
| | | } |
| | | |
| | | void Awake() |
| | | { |
| | | LoadPrefab(); |
| | | } |
| | | |
| | | GameObject cellContainer; |
| | | |
| | | private void LoadPrefab() |
| | | { |
| | | if (cellContainer != null) |
| | | return; |
| | | |
| | | var tmp = transform.Find("Container_BuffCell"); |
| | | if (tmp != null) |
| | | { |
| | | cellContainer = tmp.gameObject; |
| | | return; |
| | | } |
| | | |
| | | if (cellContainer == null) |
| | | { |
| | | cellContainer = UIUtility.CreateWidget("BattleBuffCell", "Container_BuffCell"); |
| | | 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>(); |
| | | // 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; |
| | | } |
| | | |
| | | public void Init(HB428_tagSCBuffRefresh buffData, Action onclick = null, bool showType = false) |
| | | { |
| | | if (null == buffData || gameObject == null) |
| | | { |
| | | return; |
| | | } |
| | | LoadPrefab(); //存在被卸载的可能,重新加载 |
| | | var config = SkillConfig.Get((int)buffData.SkillID); |
| | | if (config == null) |
| | | { |
| | | Debug.LogErrorFormat("技能未配置 : {0}", buffData.SkillID); |
| | | return; |
| | | } |
| | | buffIcon.SetOrgSprite(config.BuffIconName, "BuffIcon"); |
| | | |
| | | buffButton.AddListener(() => |
| | | { |
| | | onclick?.Invoke(); |
| | | }); |
| | | |
| | | buffLayer.text = buffData.Layer == 0 ? "" : buffData.Layer.ToString(); |
| | | } |
| | | } |
| | | |