using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
///
/// 掉落管理者
///
public class NpcManager : MonoBehaviour
{
///
/// 单键
///
private static NpcManager m_Instance;
private int _mapId;
private float _refreshItemTime = 1.0f;
private float _nowRefreshTime = 0.0f;
///
/// NPC列表
///
private Dictionary npcItems = new Dictionary();
public int MapId
{
get
{
return this._mapId;
}
set
{
this._mapId = value;
}
}
///
/// 单键
///
public static NpcManager Instance
{
get
{
if (m_Instance == null)
{
GameObject obj = new GameObject("NpcManager");
DontDestroyOnLoad(obj);
if (obj)
{
m_Instance = obj.AddComponent();
m_Instance.Init();
}
else
{
Debug.LogError("NpcManager 初始化失败!!!");
}
}
return m_Instance;
}
}
public void Update()
{
if (_nowRefreshTime < _refreshItemTime)
{
_nowRefreshTime += Time.deltaTime;
if (_nowRefreshTime >= _refreshItemTime)
{
}
}
}
public void RefreshTaskCardVo(TaskCardVo vo)
{
vo.curSteps.ForEach(stp =>
{
Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
if (stp.mo().cmd != (int)Enum_TaskCmdType.PlotOver)
{
return;
}
string[] paramList = stp.mo().paras.Split(',');
int stepNpcID = int.Parse(paramList[0]);
int stepStageID = int.Parse(paramList[1]);
RefreshItem(stepNpcID);
});
}
public void RefreshItem(int id)
{
_nowRefreshTime = 0;
if (npcItems.ContainsKey(id))
{
npcItems[id].RefreshTaskSign();
}
else
{
LogHelper.LogError("查找NPC失败!" + id);
}
}
///
/// 初始化
///
public void Init()
{
npcItems.Clear();
}
public void AddNpcItem(SceneEventNpcLogic npc)
{
if (npcItems.ContainsKey(npc.info.npcId) == false)
{
npcItems.Add(npc.info.npcId, npc);
}
// 网格优化分配
MyGridMap gridMap = GameObject.Find("GridMap").GetComponent();
gridMap.AddOneObjToGrid(npc.gameObject);
}
///
/// 删除npc
///
///
public void RemoveNpcItem(SceneEventNpcLogic npc)
{
Destroy(npc.gameObject);
npcItems.Remove(npc.info.npcId);
}
public void RemoveNpcItem(int id)
{
Destroy(npcItems[id].gameObject);
npcItems.Remove(id);
}
public Dictionary GetAllNpc()
{
return npcItems;
}
}