//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, November 07, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class LocalMapTag : MonoBehaviour { [SerializeField] TextEx m_NpcName; [SerializeField] TextEx m_Level; [SerializeField] Button m_Moveto; [SerializeField] Image m_TaskState; TagType m_TagType; public TagType tagType { get { return m_TagType; } set { m_TagType = value; } } LocalMapFindPath localMapFindPath; Vector3 worldPosition = Vector3.zero; int npcId = 0; int index = 0; TaskModel taskmodel { get { return ModelCenter.Instance.GetModel(); } } FairyLeagueModel fairyLeagueModel { get { return ModelCenter.Instance.GetModel(); } } public void Display(int _npcId, TextColType _colorType) { npcId = _npcId; switch (m_TagType) { case TagType.Function: var status = taskmodel.StatusLightQuery(npcId); if (status > 0) { m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status)); } else { m_TaskState.SetSprite("LocalMapTaskState_0"); } m_TaskState.SetNativeSize(); TaskModel.Event_TaskResponse -= OnTaskStateChange; TaskModel.Event_TaskResponse += OnTaskStateChange; break; case TagType.WayPoint: break; case TagType.Boss: break; case TagType.Elite: case TagType.Monster: var config = NPCConfig.Get(npcId); m_NpcName.text = config.charName; m_NpcName.colorType = _colorType; break; case TagType.Crystal: OnCrystalStateChange(npcId); m_Moveto.RemoveAllListeners(); m_Moveto.AddListener(MoveTo); PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent; PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent; fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange; fairyLeagueModel.UpdateWarCrystalEvent += OnCrystalStateChange; break; } } public void Display(int _npcId, TextColType _colorType, Vector3 _position) { worldPosition = _position; npcId = _npcId; switch (m_TagType) { case TagType.Boss: var config = NPCConfig.Get(npcId); m_NpcName.text = config.charName; m_Level.text = Language.Get("HeadUpName_Monster", config.NPCLV); m_NpcName.colorType = _colorType; var dangerous = PlayerDatas.Instance.baseData.LV <= config.NPCLV; m_Level.color = UIHelper.GetUIColor(dangerous ? TextColType.Red : TextColType.Green, false); m_Moveto.RemoveAllListeners(); m_Moveto.AddListener(MoveTo); break; default: break; } } public void Display(int _index) { index = _index; switch (m_TagType) { case TagType.FairyLeagueBuff: m_Moveto.RemoveAllListeners(); m_Moveto.AddListener(MoveTo); break; } } public void Dispose() { TaskModel.Event_TaskResponse -= OnTaskStateChange; fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange; PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent; } private void MoveTo() { switch (m_TagType) { case TagType.FairyLeagueBuff: { var _help = fairyLeagueModel.fairyLeagueHelp; Vector2 _buffPos = fairyLeagueModel.crystalPosList[index]; var _hero = PlayerDatas.Instance.hero; if (_hero != null) { _hero.MoveToPosition(new Vector3(_buffPos.x, _hero.Pos.y, _buffPos.y)); } } break; default: { var model = ModelCenter.Instance.GetModel(); WindowCenter.Instance.Close(); WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); MapTransferUtility.Instance.MoveToNPC(npcId); model.selectedMapEventPoint = -1; } break; } } private void OnTaskStateChange(int _nowNPCid, int _nPCLamp, Dictionary _dic) { if (npcId == _nowNPCid) { var status = taskmodel.StatusLightQuery(npcId); if (status > 0) { m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status)); } else { m_TaskState.SetSprite("LocalMapTaskState_0"); } m_TaskState.SetNativeSize(); } } private void OnCrystalStateChange() { OnCrystalStateChange(npcId); } private void PlayerDataRefreshInfoEvent(PlayerDataType _type) { if (_type == PlayerDataType.Faction) { OnCrystalStateChange(); } } private void OnCrystalStateChange(int _npcId) { if (npcId != _npcId) { return; } var _index = fairyLeagueModel.GetCrystalIndex(_npcId); m_NpcName.text = (_index + 1).ToString(); var _camp = fairyLeagueModel.fairyLeagueHelp.GetCrystalBelongCamp(_npcId); if (_camp == 0) { m_TaskState.SetSprite("GrayCrystal"); m_Moveto.image.SetSprite("GreyBottom"); return; } m_TaskState.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueCrystal" : "RedCrystal"); m_Moveto.image.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueBottom" : "RedBottom"); } public enum TagType { Boss = 1, Elite = 2, Monster = 3, Function = 4, WayPoint = 5, Crystal = 6, FairyLeagueBuff = 7, } } public class LocalMapTagPool { static Dictionary pools = new Dictionary(); public static LocalMapTag Require(LocalMapTag.TagType _pattern) { GameObjectPoolManager.GameObjectPool pool = null; var poolKey = (int)_pattern; if (!pools.ContainsKey(poolKey)) { var prefab = UILoader.LoadPrefab(StringUtility.Contact("LocalMap_", _pattern)); if (prefab != null) { pool = GameObjectPoolManager.Instance.RequestPool(prefab); pools[poolKey] = pool; } } else { pool = pools[poolKey]; } if (pool != null) { var instance = pool.Request(); var npcBehaviour = instance.GetComponent(); npcBehaviour.tagType = _pattern; npcBehaviour.enabled = true; return npcBehaviour; } else { return null; } } public static void Recycle(LocalMapTag _npcBehaviour) { var pattern = _npcBehaviour.tagType; GameObjectPoolManager.GameObjectPool pool; if (pools.TryGetValue((int)pattern, out pool)) { _npcBehaviour.enabled = false; pool.Release(_npcBehaviour.gameObject); } } public static void Clear() { foreach (var key in pools.Keys) { var pool = pools[key]; if (pool != null) { pool.Clear(); } } pools.Clear(); } } }