public void NpcCommIn(NpcDelegate npc) { if (!m_ManagedNpcs.ContainsKey(npc.locator)) { m_ManagedNpcs.Add(npc.locator, npc); m_NpcQueue.Enqueue(npc); } }
public void RegisterNpc(string id, NpcDelegate npc) { if (m_ManagedNpcs.ContainsKey(id)) { EB.Debug.LogError("Npc already have " + id); return; } else { npc.preloaded = true; npc.created = true; m_ManagedNpcs.Add(id, npc); } }
/// <summary> /// is slow function use less /// </summary> public void ClearNotCurrentSceneNpc() { List <string> npc_to_remove = new List <string>(); foreach (KeyValuePair <string, NpcDelegate> entry in m_ManagedNpcs) { NpcDelegate npc = entry.Value; if (!npc.sceneid.Equals(m_CurrentSceneID)) { npc_to_remove.Add(npc.locator); } } for (int i = 0; i < npc_to_remove.Count; i++) { if (m_ManagedNpcs.ContainsKey(npc_to_remove[i])) { m_ManagedNpcs.Remove(npc_to_remove[i]); } } m_GroupCellManager.Clear(); }
/// <summary> /// 清理queue 以免占用太多内存 在战斗回多人场景时 /// </summary> void FreshQueue() { if (m_NpcQueue.Count <= 100) { return; } List <NpcDelegate> list = new List <NpcDelegate>(64); while (m_NpcQueue.Count > 0) { NpcDelegate npcdata = m_NpcQueue.Dequeue(); if (m_ManagedNpcs.ContainsKey(npcdata.locator)) { list.Add(npcdata); } } for (int i = 0; i < list.Count; i++) { m_NpcQueue.Enqueue(list[i]); } }
void NpcCommIn(string locator, IDictionary data, string scenename, string scenetype) { Vector3 v3 = Vector3.zero; if (data["pos"] != null) { v3 = GM.LitJsonExtension.ImportVector3(data["pos"].ToString()); } Quaternion rot = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f)); long sceneid = EB.Dot.Long("sid", data, 0); string role = EB.Dot.String("role", data, ""); string curLayout = EB.Dot.String("bossLayoutId", data, string.Empty); if (string.IsNullOrEmpty(curLayout)) { if (!DataLookupsCache.Instance.SearchDataByID("mainlands.lastWeekBossLayoutId", out curLayout)) { curLayout = "Layout50103"; } } string modelname = Hotfix_LT.Data.SceneTemplateManager.GetNPCModel(scenename, role, locator, curLayout); bool fighting = EB.Dot.Bool("busy", data, false); string strAttr = EB.Dot.String("tag_attribute", data, string.Empty); int attr = 0; if (!strAttr.Equals(string.Empty)) { attr = int.Parse(strAttr); } NpcDelegate npc = new NpcDelegate(locator, v3, rot, scenetype + sceneid, modelname, role, fighting, attr); if (role != "func") { NpcCommIn(npc); } }
public void ProcessNpcUpdateSync(object incomingData) { string scenetype = EB.Dot.String("scenetype", incomingData, ""); IDictionary npcs = EB.Dot.Object(scenetype + ".npc_list", incomingData, null); if (npcs == null) { return; } SceneLogic scenelogic = MainLandLogic.GetInstance(); if (scenelogic == null) { return; } foreach (DictionaryEntry entry in npcs) { bool fighting = EB.Dot.Bool("busy", entry.Value, false); EnemyController ec = scenelogic.GetEnemyController(entry.Key.ToString()); if (ec != null) { //if(!( ec is BoxController)) //{ // ec.SetBarHudState(eHeadBarHud.FightStateHud, null, fighting); //} } else { NpcDelegate npc = null; m_ManagedNpcs.TryGetValue(entry.Key.ToString(), out npc); if (npc != null) { npc.isfighting = fighting; } } } }
void Update() { FreshQueue(); if (!m_IsCanShow) { return; } if (!GM.AssetManager.IsIdle) { return; } if (m_NpcQueue != null && m_NpcQueue.Count > 0) { NpcDelegate npcdata = m_NpcQueue.Dequeue(); if (npcdata != null) { if (npcdata.sceneid.Equals(m_CurrentSceneID) && m_ManagedNpcs != null && m_ManagedNpcs.ContainsKey(npcdata.locator)) { Vector3 v3; Quaternion rot; switch (npcdata.role) { case NPC_ROLE.GHOST: v3 = npcdata.pos; rot = npcdata.quater; break; default: GameObject locator_obj = LocatorManager.Instance.GetLocator(npcdata.locator); if (locator_obj == null) { EB.Debug.LogWarning(string.Format("No available locator data for npc at locator [{0}]", npcdata.locator)); return; } v3 = locator_obj.transform.position; rot = locator_obj.transform.rotation; break; } if (npcdata.key != null) { //夺宝奇兵等级未开放或该区服未开放判断 if (npcdata.role == NPC_ROLE.GHOST && ( !Hotfix_LT.Data.FuncTemplateManager.Instance.GetFunc(10073).IsConditionOK() || !Hotfix_LT.Data.EventTemplateManager.Instance.GetRealmIsOpen("main_land_ghost_start"))) { EB.Debug.LogWarning("NPC_ROLE.GHOST Return! (10073).IsConditionOK()——{0}", Hotfix_LT.Data.FuncTemplateManager.Instance.GetFunc(10073).IsConditionOK() + ";GetRealmIsOpen——" + Hotfix_LT.Data.EventTemplateManager.Instance.GetRealmIsOpen("main_land_ghost_start")); return; } else if (m_GroupCellManager != null && m_GroupCellManager.IsCellShowing(npcdata.key)) { if (!npcdata.preloaded) { if (m_CurrentSceneLogic != null) { m_CurrentSceneLogic.PreloadAsync(npcdata.modelname, (success) => { npcdata.preloaded = success; m_NpcQueue.Enqueue(npcdata); }); } else { EB.Debug.LogError("CurrentSceneLogic is Null"); } } else if (m_ManagedNpcs != null && !m_ManagedNpcs[npcdata.locator].created) { m_ManagedNpcs[npcdata.locator].created = true; if (m_CurrentSceneLogic != null) { #region 异步加载一个NPC m_CurrentSceneLogic.SpawnNpcAsync(npcdata.locator, npcdata.modelname, npcdata.role, v3, rot, ec => { if (ec != null) { Player.EnemyHotfixController ehc = ec.transform.GetMonoILRComponent <Player.EnemyHotfixController>(); ehc.SetBarHudState(eHeadBarHud.FightStateHud, null, m_ManagedNpcs[npcdata.locator].isfighting); ehc.Role = npcdata.role; ehc.Attr = npcdata.attr; ehc.SetNpcName(m_CurrentSceneLogic.CurrentSceneName); } }); #endregion } else { EB.Debug.LogError("CurrentSceneLogic is Null"); } } } } else if (m_GroupCellManager != null) { GroupCellKey key = m_GroupCellManager.ObjectIn(npcdata.locator, v3); npcdata.key = key; if (m_GroupCellManager.IsCellShowing(npcdata.key)) { m_NpcQueue.Enqueue(npcdata); } } } else { } } } if (m_GroupCellManager != null) { var go = PlayerManager.LocalPlayerGameObject(); m_GroupCellManager.Update(go != null ? go.transform : null); } }