using FL.Battle.Buffs; using System.Collections.Generic; using UnityEngine; using XGame.Framework.Map; namespace FL.Map.UI { /// /// TODO 临时代码 /// public class BattleInfoBuffList : MonoBehaviour { [SerializeField] private BattleInfoBuffListItem _template; [SerializeField] private int _itemLimit = 4; private BattleInfoBuffListItem[] _items; private void Awake() { _items = new BattleInfoBuffListItem[_itemLimit]; } private void OnDisable() { foreach (var item in _items) { if (item == null) break; item.gameObject.SetActive(false); } } public void Refresh(List buffs, MapContext context) { // item 显示顺序为: 4 2 0 1 3 5 if (buffs.Count > 1) { buffs.Sort((a, b) => { return b.Layers - a.Layers; }); } var showCount = Mathf.Clamp(buffs.Count, 0, _itemLimit); for (var i = 0; i < _itemLimit; i++) { var item = _items[i]; if (i < showCount) { // 需要显示 var buff = buffs[i]; if (item == null) { item = GameObject.Instantiate(_template, _template.transform.parent); _items[i] = item; var size = (item.transform as RectTransform).sizeDelta; var sign = i % 2 == 0 ? -1 : 1; // 偶数在左边 var localPosition = item.transform.localPosition; localPosition.x = size.x * (0.5f + i / 2) * sign; } var loadAsync = context.Asset.LoadAsync(buff.IconName); loadAsync.On(_ => { item.buffIcon.sprite = loadAsync.Result; }); var layers = buff.Layers; item.buffNumTxt.text = layers > 1 ? layers.ToString() : string.Empty; item.vfxLayer5.SetActive(layers == buff.LayerLimit); item.vfxLayer3.SetActive(layers == 3); item.gameObject.SetActive(true); } else { // 隐藏 if (item == null) { break; } item.gameObject.SetActive(false); } } } } }