public NpcDelegate(DungeonPlacement placement, string sceneid) { this.locator = placement.Locator; if (string.IsNullOrEmpty(placement.Pos)) { this.pos = Vector3.zero; } else { this.pos = GM.LitJsonExtension.ImportVector3(placement.Pos.ToString()); } Quaternion rot = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f)); this.quater = rot; this.sceneid = sceneid; this.modelname = placement.Encounter; this.isfighting = placement.IsFighting; this.role = placement.Role; key = null; this.created = false; this.preloaded = false; if (!placement.Attr.Equals(string.Empty)) { attr = int.Parse(placement.Attr); } }
public void Update(Transform player) { if (!GameEngine.Instance.IsTimeToRootScene) { return; } if (player == null) { return; } Vector3 pos = player.position; int x = (int)(pos.x / m_CellSize); int z = (int)(pos.z / m_CellSize); if (m_ShowingCellKey == null)//首次 { m_ShowingCellKey = new GroupCellKey(x, z); for (int i = x - 1; i <= x + 1; i++) { for (int j = z - 1; j <= z + 1; j++) { ShowCell(string.Format("{0},{1}", i, j), true); } } } else { if (m_ShowingCellKey.X != x || m_ShowingCellKey.Z != z)//变化 { int oldx = m_ShowingCellKey.X; int oldz = m_ShowingCellKey.Z; m_ShowingCellKey = new GroupCellKey(x, z); for (int i = x - 1; i <= x + 1; i++) { for (int j = z - 1; j <= z + 1; j++) { ShowCell(string.Format("{0},{1}", i, j), true); } } for (int i = oldx - 1; i <= oldx + 1; i++) { for (int j = oldz - 1; j <= oldz + 1; j++) { if (i > x + 1 || i < x - 1 || j > z + 1 || j < z - 1) { ShowCell(string.Format("{0},{1}", i, j), false); } } } } } }
public NpcDelegate(string locator, Vector3 pos, Quaternion quater, string sceneid, string modelname, string role, bool isfighting, int attr = 0) { this.locator = locator; this.pos = pos; this.quater = quater; this.sceneid = sceneid; this.modelname = modelname; this.role = role; this.isfighting = isfighting; key = null; this.created = false; this.preloaded = false; this.attr = attr; }
public bool IsCellShowing(GroupCellKey key) { if (key == null) { return(false); } if (m_ShowingCellKey == null) { return(false); } else { return(key.IsShowing(m_ShowingCellKey)); } }
public bool IsShowing(GroupCellKey Center) { //return true; if (Center == null) { return(false); } if (m_X <= Center.X + 1 && m_X >= Center.X - 1 && m_Z <= Center.Z + 1 && m_Z >= Center.Z - 1) { return(true); } else { return(false); } }
public GroupCellKey ObjectIn(string id, Vector3 pos) { int x = (int)(pos.x / m_CellSize); int z = (int)(pos.z / m_CellSize); GroupCellKey key = new GroupCellKey(x, z); string tmp = key.FormatCellKey(); if (m_Cells.ContainsKey(tmp)) { m_Cells[tmp].ObjectIn(id); } else { GroupCell cell = new GroupCell(key); m_Cells.Add(tmp, cell); cell.ObjectIn(id); } return(key); }
/// <summary> /// 切换场景时清理 /// </summary> public void Clear() { m_Cells.Clear(); m_ShowingCellKey = null; }
public GroupCellManager() { m_CellSize = 10; m_Cells = new Dictionary <string, GroupCell>(); m_ShowingCellKey = null; }
public GroupCell(GroupCellKey Key) { m_Key = Key; m_Showing = false; m_Objects = new List <string>(); }
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); } }