using GCGame.Table; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class FashionAttrBase : MonoBehaviour { private struct AttrItemStruct { public int _PropId; public int _PropVal; public AttrItemStruct(int propId, int val) { _PropId = propId; _PropVal = val; } } public static FashionAttrBase Instance; private void Awake() { Instance = this; } private void OnDestroy() { Instance = null; } public GameObject _AttrItemPrefab; public Transform _AttrItemParent; private List _AttrItemList = new List(); private Tab_ChildrenFashion _ChildFashionTab = null; public Text _CombatVal; public Transform _Parent; public void InitAttrPanel(int fashionId) { _ChildFashionTab = TableManager.GetChildrenFashionByID(fashionId, 0); if (_ChildFashionTab == null) { Debug.LogError("childrenFashionTab is null : " + fashionId); return; } //战力 _CombatVal.text = _ChildFashionTab.CombatVal + ""; //属性词条 if (gameObject.activeInHierarchy) StartCoroutine(CreateAndInitAttrItem()); } Dictionary _PropValDic; IEnumerator CreateAndInitAttrItem() { yield return null; _PropValDic = new Dictionary(); for(int index = 0; index < _ChildFashionTab.getPropIdCount(); index++) { if(_ChildFashionTab.GetPropIdbyIndex(index) != -1) _PropValDic.Add(_ChildFashionTab.GetPropIdbyIndex(index), _ChildFashionTab.GetPropValbyIndex(index)); } var lessCount = 0; if (_AttrItemList == null) lessCount = _PropValDic.Count; else lessCount = _PropValDic.Count - _AttrItemList.Count; for (int index = 0; index < lessCount; index++) { var attrItem = GameObject.Instantiate(_AttrItemPrefab); attrItem.transform.SetParent(_Parent); attrItem.transform.localPosition = Vector3.zero; attrItem.transform.localScale = Vector3.one; attrItem.transform.localRotation = Quaternion.Euler(Vector3.zero); var attrComponent = attrItem.GetComponent(); _AttrItemList.Add(attrComponent); attrItem.gameObject.SetActive(false); } var itemIndex = 0; foreach (var item in _PropValDic) { _AttrItemList[itemIndex++].InitAttrItem(item.Key, item.Value); } for(int index = _PropValDic.Count; index < _AttrItemList.Count; index++) { _AttrItemList[index].gameObject.SetActive(false); } yield break; } }