// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-06-10 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using static G.PlayerProxy; namespace G.UI { /// /// /// public class EquipmentUpgradeWidget : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] Button _btnUpgrade; [KUIFlag] Button _btnOneKeyUpgrade; [KUIFlag] KUIList __goExtraAttributes; [KUIFlag] GameObject __goUpgradeCost; [KUIFlag] GameObject __goOnekeyUpgradeCost; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null private CostWidget _upgradeCost; private CostWidget _onekeyUpgradeCost; #endregion #region Method public override void Refresh() { if (this.data is EquipmentSlotInfo equipmentSlot) { bool enough = PlayerProxy.Instance.GetUpgradeEquipmentSlotCost(equipmentSlot.id, false, out int costId, out int cost); _upgradeCost.SetPrice(costId, cost, enough); SetExtra(equipmentSlot.equipment.extraAttributes, equipmentSlot.upgradeAttributes); } } private void SetExtra(List attributes, List attributes2) { if (attributes != null && attributes.Count > 0) { __goExtraAttributes.gameObject.SetActive(true); __goExtraAttributes.Clear(); for (int i = 0; i < attributes.Count; i++) { var at = __goExtraAttributes.GetItem(); at.SetData(attributes[i].ToString()); if (i < attributes2.Count) { var at2 = __goExtraAttributes.GetItem(); at2.SetData("强化+" + attributes2[i].value + ""); } } } else { __goExtraAttributes.gameObject.SetActive(false); } } private void OnUpgradeBtnClick() { if (this.data is EquipmentSlotInfo equipmentSlot) { if (PlayerProxy.Instance.UpgradeEquipmentSlot(equipmentSlot.id, false, true)) { Refresh(); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnOneKeyUpgradeBtnClick() { if (this.data is EquipmentSlotInfo equipmentSlot) { if (PlayerProxy.Instance.UpgradeEquipmentSlot(equipmentSlot.id, true, true)) { Refresh(); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); __goExtraAttributes.AddTemplate(true); _upgradeCost = __goUpgradeCost.AddComponent(); _onekeyUpgradeCost = __goOnekeyUpgradeCost.AddComponent(); _btnUpgrade.onClick.AddListener(this.OnUpgradeBtnClick); _btnOneKeyUpgrade.onClick.AddListener(this.OnOneKeyUpgradeBtnClick); } #endregion } }