//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, December 12, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { [XLua.Hotfix] public class GatherSoulTotalPropertyWin : Window { [SerializeField] RectTransform m_Content; [SerializeField] PropertyBehaviour[] m_Propertys; List m_ClonePropertys = new List(); GatheringSoulModel model { get { return ModelCenter.Instance.GetModel(); } } Dictionary displayPropertyDict = new Dictionary(); List propertySorts = new List(); #region Built-in protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { model.gatherSoulHolesRefresh += GatherSoulHoleRefresh; DisplayProperty(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { model.gatherSoulHolesRefresh -= GatherSoulHoleRefresh; } protected override void OnAfterClose() { } #endregion void DisplayProperty() { var count = model.holeCount; propertySorts.Clear(); displayPropertyDict.Clear(); for (int i = 0; i < count; i++) { GatherSoulItem item; if (model.TryGetItem(i, out item)) { var list = model.gatherSoulPropertys[item.id]; for (int k = 0; k < list.Count; k++) { displayPropertyDict.Add(list[k], model.GetPropertyValue(item.id, list[k], item.level)); propertySorts.Add(list[k]); } } } propertySorts.Sort(Compare); CheckPropertyBehaviour(); var index = 0; for (int i = 0; i < propertySorts.Count; i++) { if (index < m_Propertys.Length) { m_Propertys[index].gameObject.SetActive(true); m_Propertys[index].DisplayUpper(propertySorts[i], displayPropertyDict[propertySorts[i]]); } else if (index - m_Propertys.Length < m_ClonePropertys.Count) { m_ClonePropertys[index - m_Propertys.Length].gameObject.SetActive(true); m_ClonePropertys[index - m_Propertys.Length].DisplayUpper(propertySorts[i], displayPropertyDict[propertySorts[i]]); } index++; } for (int i = index; i < m_Propertys.Length; i++) { m_Propertys[i].gameObject.SetActive(false); } index = Mathf.Max(0, index - m_Propertys.Length); for (int i = index; i < m_ClonePropertys.Count; i++) { m_ClonePropertys[i].gameObject.SetActive(false); } } void CheckPropertyBehaviour() { if (m_Propertys.Length + m_ClonePropertys.Count >= propertySorts.Count) { return; } else { var count = propertySorts.Count - m_Propertys.Length - m_ClonePropertys.Count; for (int i = 0; i < count; i++) { var behaviour = GameObject.Instantiate(m_Propertys[0]); if (behaviour != null) { behaviour.transform.SetParent(m_Content); behaviour.transform.localPosition = Vector3.zero; behaviour.transform.localEulerAngles = Vector3.zero; behaviour.transform.localScale = Vector3.one; m_ClonePropertys.Add(behaviour); } } } } int Compare(int lhs, int rhs) { var dict = model.propertySorts; if (dict.ContainsKey(lhs) && dict.ContainsKey(rhs)) { return dict[lhs].CompareTo(dict[rhs]); } return 0; } private void GatherSoulHoleRefresh() { DisplayProperty(); } } }