//可能是没有数据的空块,请判断chunk.isTerrainDataPrepared public Chunk GetChunk(int x, int y, int z) { WorldPos pos = Terrain.GetChunkPos(x, y, z); Chunk outputChunk = null; Watcher.instance.worldDictTimes += 1; chunks.TryGetValue(pos, out outputChunk); return(outputChunk); }
public void InitPosition(Vector3 position) { _position = position; inChunkPos = Terrain.GetChunkPos(position); NetManager.Instance.server.sceneManager.ChangeChunkNeedSaved(inChunkPos, true); viewPlayers = NetManager.Instance.server.playerManager.GetAroundPlayer(inChunkPos, ClientPlayer.VIEW_WIDTH); for (int i = 0; i < viewPlayers.Count; i++) { ClientPlayer clientPlayer = NetManager.Instance.server.playerManager.GetPlayer(viewPlayers[i]); clientPlayer.AddViewEntity(aoId); } }
public void UpdatePosition(Vector3 position) { _position = position; WorldPos newPos = Terrain.GetChunkPos(position); if (!inChunkPos.EqualOther(newPos)) { WorldPos oldPos = inChunkPos; inChunkPos = newPos; NetManager.Instance.server.sceneManager.ChangeChunkNeedSaved(inChunkPos, true); NetManager.Instance.server.entityManager.UpdateEntityChunkPos(oldPos, inChunkPos, this); UpdateViewPlayer(); } }
public void UpdatePosition(Vector3 position) { _position = position; WorldPos newPos = Terrain.GetChunkPos(position); if (!inChunkPos.EqualOther(newPos)) { WorldPos oldPos = inChunkPos; inChunkPos = newPos; NetManager.Instance.server.playerManager.UpdatePlayerChunkPos(oldPos, inChunkPos, this); //人物移动时更新人物与怪物的视野范围 UpdateViewPlayer(); UpdateViewEntity(); } }
public GameObject InitMonster(MonsterInfo info) { if (info.isNetObj) { WorldPos pos = Terrain.GetChunkPos(info.position); Chunk chunk = World.world.GetChunk(pos.x, pos.y, pos.z); if (chunk == null || !chunk.isGenerated) { if (!_delayRefreshMonster.ContainsKey(pos)) { _delayRefreshMonster.Add(pos, info); } return(null); } } return(InitMonsterSelf(info)); }
public void InitPosition(Vector3 position) { _position = position; inChunkPos = Terrain.GetChunkPos(position); //初始化人物视野 viewPlayers = NetManager.Instance.server.playerManager.GetAroundPlayer(this, viewWidth, false); for (int i = 0; i < viewPlayers.Count; i++) { ClientPlayer clientPlayer = NetManager.Instance.server.playerManager.GetPlayer(viewPlayers[i]); clientPlayer.AddViewPlayer(id); } viewEntities = NetManager.Instance.server.entityManager.GetAroundEntity(inChunkPos, viewWidth); for (int i = 0; i < viewEntities.Count; i++) { ClientEntity clientMonster = NetManager.Instance.server.entityManager.GetEntity(viewEntities[i]); clientMonster.AddViewPlayer(id); } }
public void LoadFirst(Vector3 pos, int size) { EventManager.SendEvent(EventMacro.START_GENERATE_FIRST_WORLD, null); EventManager.RegisterEvent(EventMacro.CHUNK_GENERATE_FINISH, OnFirstWorldChunkGenerate); WorldPos worldPos = Terrain.GetWorldPos(pos); WorldPos curChunkPos = Terrain.GetChunkPos(worldPos.x, 0, worldPos.z); for (int x = -size; x <= size; x++) { for (int z = -size; z <= size; z++) { WorldPos chunkPos = new WorldPos(curChunkPos.x + x * Chunk.chunkWidth, curChunkPos.y, curChunkPos.z + z * Chunk.chunkDepth); if ((x >= -size + 2 && x <= size - 2) && (z >= -size + 2 && z <= size - 2)) { firstChunks.Add(chunkPos); } world.WorldGenerator.GenerateChunk(chunkPos.x, chunkPos.y, chunkPos.z, curChunkPos); } } }
public void Update() { if (player == null) { player = HasActionObjectManager.Instance.playerManager.getMyPlayer(); } else { WorldPos playerPos = Terrain.GetWorldPos(player.transform.position); WorldPos curChunkPos = Terrain.GetChunkPos(playerPos.x, 0, playerPos.z); if (!curChunkPos.EqualOther(_curChunkPos)) { _curChunkPos = curChunkPos; world.WorldGenerator.DataProcessorManager.UpdateChunkPriority(_curChunkPos); ChangeAllEntityVisible(); LoadChunks(); RemoveChunks(); UpdatePersistanceOperate(); } } }
public void UpdateState() { WorldPos pos = Terrain.GetWorldPos(_controller.transform.position); if (!_curPos.EqualOther(pos)) { _curPos = pos; CheckAndResetPos(); WorldPos chunkPos = Terrain.GetChunkPos(_curPos.x, 0, _curPos.z); if (!chunkPos.EqualOther(_attachChunk.worldPos)) { Chunk chunk = World.world.GetChunk(chunkPos.x, chunkPos.y, chunkPos.z); AttachChunk(chunk); } _inBlock = _attachChunk.GetBlock(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true); _standBlock = _attachChunk.GetBlock(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y - 1, _curPos.z - chunkPos.z, true); _blockLightLevel = _attachChunk.GetBlockLight(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true); _sunLightLevel = _attachChunk.GetSunLight(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true); } UpdateRenderLight(_sunLightLevel, _blockLightLevel); }