using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; using System.Text; using Snxxz.UI; using System.Collections; public class RoleEquipStarTips : MonoBehaviour { #region 成员变量 [SerializeField] CanvasGroup tipAlpha; private GameObject _curStars; private Text _curStarsText; private Text _curAttrValueText; private Text _haveStarsText; private GameObject _nextStars; private Text _nextStarsText; private Text _nextAttrValueText; private Text _noOpenText; #endregion private int p_preIndex = -1; private int p_nextIndex = -1; private int _curStarsCount; private int[] attrTypes; private int[] attrValues; private PlayerPropertyConfig _playerProModel; private ItemConfig _tagChinModel; private Dictionary _itemDict; private RoleEquipStarsConfig _tagEquipStarsModel; private List _tagEquipStarsModellist; PackModel _playerPack; PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } private void Awake() { _curStars = transform.Find("CurrentStars").gameObject; _curStarsText = transform.Find("CurrentStars/TargetNowText").GetComponent(); _curAttrValueText = transform.Find("CurrentStars/AttrValueText").GetComponent(); _haveStarsText = transform.Find("CurrentStars/CountNowText").GetComponent(); _nextStars = transform.Find("NextStars").gameObject; _nextStarsText = transform.Find("NextStars/TargetNextText").GetComponent(); _nextAttrValueText = transform.Find("NextStars/AttrValueText").GetComponent(); _noOpenText = transform.Find("CurrentStars/NoOpenText").GetComponent(); } private void OnEnable() { SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip); if (singlePack != null) { _itemDict = singlePack.GetAllItems(); } _tagEquipStarsModellist = RoleEquipStarsConfig.GetEquipStarslist(); tipAlpha.alpha = 0; _nextStars.SetActive(false); _curStars.SetActive(false); RefreshUI(); StartCoroutine(SetScrollSize()); } private void RefreshUI() { _curStarsCount = 0; p_preIndex = -1; p_nextIndex = -1; RectTransform size = _haveStarsText.GetComponent(); if (_itemDict != null) { foreach (var model in _itemDict.Values) { _tagChinModel = ItemConfig.Get((int)model.itemId); if (_tagChinModel == null) return; _curStarsCount += _tagChinModel.StarLevel; } } GetTwoAdjacentNumber(0, _tagEquipStarsModellist.Count - 1, _curStarsCount); StringBuilder attrStr = new StringBuilder(); if (p_preIndex != -1) { _tagEquipStarsModel = _tagEquipStarsModellist[p_preIndex]; _noOpenText.gameObject.SetActive(false); _curStarsText.gameObject.SetActive(true); _curAttrValueText.gameObject.SetActive(true); _curStarsText.text = Language.Get("KnapS123").Replace("{0}", _tagEquipStarsModel.countNeed.ToString()); _haveStarsText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString()); int i = 0; for (i = 0; i < _tagEquipStarsModel.attType.Length; i++) { _playerProModel = PlayerPropertyConfig.Get(_tagEquipStarsModel.attType[i]); if (_playerProModel != null) { attrStr.Append(SetIsPercentShow(_playerProModel, _tagEquipStarsModel.attValue[i]) + "\n"); } } _curAttrValueText.text = attrStr.ToString(); } else { _noOpenText.gameObject.SetActive(true); _curStarsText.gameObject.SetActive(false); _curAttrValueText.gameObject.SetActive(false); _haveStarsText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString()); } if (p_nextIndex != -1) { _nextStars.SetActive(true); attrStr.Length = 0; _tagEquipStarsModel = _tagEquipStarsModellist[p_nextIndex]; _nextStarsText.text = Language.Get("KnapS123").Replace("{0}", _tagEquipStarsModel.countNeed.ToString()); int i = 0; for (i = 0; i < _tagEquipStarsModel.attType.Length; i++) { _playerProModel = PlayerPropertyConfig.Get(_tagEquipStarsModel.attType[i]); if (_playerProModel != null) { attrStr.Append(SetIsPercentShow(_playerProModel, _tagEquipStarsModel.attValue[i]) + "\n"); } } _nextAttrValueText.text = attrStr.ToString(); } else { _nextStars.SetActive(false); } } IEnumerator SetScrollSize() { yield return null; yield return null; _curStars.SetActive(true); StartCoroutine(ShowBottomPart()); } IEnumerator ShowBottomPart() { yield return null; _nextStars.SetActive(true); StartCoroutine(SetPanelScale()); } IEnumerator SetPanelScale() { yield return null; tipAlpha.alpha = 1; } //得到相邻的两个数 private void GetTwoAdjacentNumber(int minIndex, int maxIndex, int currentLevel) { p_preIndex = -1; p_nextIndex = -1; int minCount = _tagEquipStarsModellist[minIndex].countNeed; int maxCount = _tagEquipStarsModellist[maxIndex].countNeed; int sum = minCount + maxCount; int adjacentIndex = 0; if (sum != 0) { adjacentIndex = (int)((float)currentLevel / (minCount + maxCount) * _tagEquipStarsModellist.Count); } if (adjacentIndex < _tagEquipStarsModellist.Count) { for (int i = adjacentIndex; i > -1; i--) { if (_tagEquipStarsModellist[i].countNeed <= currentLevel) { p_preIndex = i; break; } else { p_nextIndex = i; } } if (p_nextIndex == -1) { for (int i = adjacentIndex; i < _tagEquipStarsModellist.Count; i++) { if (_tagEquipStarsModellist[i].countNeed >= currentLevel) { if (adjacentIndex != _tagEquipStarsModellist.Count - 1) { p_nextIndex = i; } break; } else { p_preIndex = i; } } } if (p_preIndex != -1 && p_nextIndex != -1) { if (p_preIndex == p_nextIndex) { p_nextIndex += 1; } } } else { p_preIndex = _tagEquipStarsModellist.Count - 1; p_nextIndex = -1; } } //判断属性是否百分比显示 public string SetIsPercentShow(PlayerPropertyConfig _playerProModel, int proValue) { string strPro = ""; if (!_playerProModel.Name.Contains("%s")) { if (_playerProModel.ISPercentage == 0) { strPro = _playerProModel.Name + "+" + proValue; } else if (_playerProModel.ISPercentage == 1) { strPro = _playerProModel.Name + "+" + (float)Math.Round(proValue / 100f, 1) + "%"; } } else { if (_playerProModel.ISPercentage == 0) { strPro = _playerProModel.Name.Replace("%s", proValue.ToString()); } else if (_playerProModel.ISPercentage == 1) { strPro = _playerProModel.Name.Replace("%s", (float)Math.Round(proValue / 100f, 1) + "%"); } } return strPro; } }