using System; using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class DungeonTargetBehaviour : MonoBehaviour { [SerializeField] Text descText; [SerializeField] List m_TargetDescs; [SerializeField] List m_TargetNums; private int currentDungeonId=0; DungeonModel m_Model; DungeonModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel()); } } public void Init(int mapID) { currentDungeonId = mapID; UpdateMissionEvent(); } private void OnEnable() { model.updateMissionEvent += UpdateMissionEvent; } private void UpdateMissionEvent() { if (currentDungeonId == 0) return; var dateMapId = model.GetDataMapIdByMapId(currentDungeonId); var hintId = model.GetDungeonHintId(dateMapId, 0); var config = Config.Instance.Get(hintId); m_TargetDescs[0].gameObject.SetActive(config.targetNum >= 1); m_TargetDescs[1].gameObject.SetActive(config.targetNum >= 2); m_TargetDescs[2].gameObject.SetActive(config.targetNum >= 3); var step = Mathf.Clamp(model.mission.step, 1, int.MaxValue) - 1; if (config.targetNum >= 1) { var desc = config.targetDescription1[step < config.targetDescription1.Length ? step : 0]; var npcId = config.NPC1ID.Length == 0 ? 0 : config.NPC1ID[step < config.NPC1ID.Length ? step : 0]; var targetValue = config.targetValue1.Length == 0 ? 0 : config.targetValue1[step < config.targetValue1.Length ? step : 0]; GetTargetInfo(0, desc, targetValue, step, config.targetType1, npcId); } if (config.targetNum >= 2) { var desc = config.targetDescription2[step < config.targetDescription2.Length ? step : 0]; var npcId = config.NPC2ID.Length == 0 ? 0 : config.NPC2ID[step < config.NPC2ID.Length ? step : 0]; var targetValue = config.targetValue2.Length == 0 ? 0 : config.targetValue2[step < config.targetValue2.Length ? step : 0]; GetTargetInfo(1, desc, targetValue, step, config.targetType2, npcId); } if (config.targetNum >= 3) { var desc = config.targetDescription3[step < config.targetDescription2.Length ? step : 0]; var npcId = config.NPC3ID.Length == 0 ? 0 : config.NPC3ID[step < config.NPC3ID.Length ? step : 0]; var targetValue = config.targetValue3.Length == 0 ? 0 : config.targetValue3[step < config.targetValue3.Length ? step : 0]; GetTargetInfo(2, desc, targetValue, step, config.targetType3, npcId); } descText.text = config.Info.Length > step ? config.Info[step] : config.Info[0]; } private void GetTargetInfo(int _index,string desc,int _targetValue,int _targetStep,int _targetType,int npcId=0) { m_TargetDescs[_index].text = desc; m_TargetNums[_index].text = string.Empty; switch ((DungeonTargetType)_targetType) { case DungeonTargetType.NPC: int killCnt = 0; if (npcId != 0) { var npcConfig = Config.Instance.Get(npcId); desc = desc.Replace("@NPCName@", npcConfig.charName); if (model.mission.npc != null) { for (int i = 0; i < model.mission.npc.Length; i++) { var npcInfo = model.mission.npc[i]; if (npcInfo.NPCID == npcId) { killCnt = npcInfo.killCnt; break; } } } } if (_targetValue > 0) { m_TargetNums[_index].text= StringUtility.Contact(killCnt, "/", _targetValue); break; } m_TargetNums[_index].text = killCnt.ToString(); break; case DungeonTargetType.Exp: if (_targetValue > 0) { m_TargetNums[_index].text=StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp), "/", UIHelper.ReplaceLargeNum((ulong)_targetValue)); break; } m_TargetNums[_index].text = StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp), model.mission.isFullExp == 1 ? StringUtility.Contact(" ", Language.Get("FullExp")) : string.Empty); break; case DungeonTargetType.Score: if (_targetValue > 0) { m_TargetNums[_index].text= StringUtility.Contact(model.mission.score, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.score.ToString(); break; case DungeonTargetType.Money: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.money, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.money.ToString(); break; case DungeonTargetType.Wave: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.wheel, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.wheel.ToString(); break; case DungeonTargetType.NpcTotal: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.npcTotal, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.npcTotal.ToString(); break; case DungeonTargetType.Stage: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.step, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.step.ToString(); break; } } private void OnDisable() { model.updateMissionEvent -= UpdateMissionEvent; } } }