public static IGameEntity GetGameEntityById(string entityId) { if (playerEntity.GetEntityId() == entityId) { return(playerEntity); } if (gameEntities.ContainsKey(entityId)) { IGameEntity entity = gameEntities[entityId]; if (entity.IsActive()) { return(gameEntities[entityId]); } else { return(null); } } else { if (NpcManager.instance != null) { return(NpcManager.instance.GetEntityById(entityId)); } else { return(null); } } }
private void CreateNpc(NpcGroup group, NpcDef npcDef, Character character, int order) { Vector3 spawnPosition = SpawnPoint.Instance().GetObjectSpawnPoint(gameObject); GameObject prefab = GameEntityFactory.instance.GetGameEntityPrefab(npcDef.prefabName); IGameEntity gameEntity = CreateGameEntity(character.playerId, character, spawnPosition, prefab); Npc npc = gameEntity.GetGameObject().AddComponent <Npc>() as Npc; npc.group = group; npc.gameEntity = gameEntity; if (order == 0) { group.SetLeader(npc); } npc.order = order; npc.SetNpcDef(npcDef); group.AddNpc(npc); gameEntities.Add(gameEntity); characterIdToGameEntity[character.id] = gameEntity; entityIdToGameEntity[gameEntity.GetEntityId()] = gameEntity; }