// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-01-03 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { /// /// 日常和成就 /// public class MissionWidget : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] TextMeshProUGUI _tmpDescription; [KUIFlag] Slider _slidProgress; [KUIFlag] TextMeshProUGUI _tmpProgress; [KUIFlag] Button _btnReceive; [KUIFlag] TextMeshProUGUI _tmpReceive; [KUIFlag] KUIList __listRewards; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null #endregion #region Method public override void Refresh() { if (this.data is Mission mission) { _tmpDescription.text = mission.description; _slidProgress.value = mission.curValue / Mathf.Max(1f, mission.maxValue); _tmpProgress.text = $"{mission.curValue}/{mission.maxValue}"; __listRewards.Clear(); foreach (var itemInfo in mission.rewards) { __listRewards.GetItem().SetItem(itemInfo); } if (mission.isRewarded) { _tmpReceive.text = "已领取"; _btnReceive.interactable = false; } else if (mission.isCompleted) { _tmpReceive.text = "领取"; _btnReceive.interactable = true; } else { _tmpReceive.text = "领取"; _btnReceive.interactable = false; } } } private void OnReceiveBtnClick() { if (this.data is Mission mission) { MissionProxy.Instance.GainReward(mission.id, (error, message) => { //if (error == 0) // Refresh(); }); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); _btnReceive.onClick.AddListener(this.OnReceiveBtnClick); __listRewards.AddTemplate(true); } #endregion } }