public void Update() { // don't load chunks if engine isn't initialized yet if (!Engine.Initialized || !ChunkManager.Initialized) { return; } // don't load chunks if multiplayer is enabled but the connection isn't established yet if (Engine.EnableMultiplayer) { if (!Network.isClient && !Network.isServer) { return; } } // track which chunk we're currently in. If it's different from previous frame, spawn chunks at current position. currentPos = Engine.PositionToChunkIndex(transform.position); if (currentPos.IsEqual(LastPos) == false) { //ChunkManager.SpawnChunks(currentPos.x, currentPos.y, currentPos.z); StartCoroutine(ReplaceChunks(currentPos)); // (Multiplayer) update server position if (Engine.EnableMultiplayer && Engine.MultiplayerTrackPosition && Engine.UniblocksNetwork != null) { UniblocksClient.UpdatePlayerPosition(currentPos); } } LastPos = currentPos; }
public void Update() { Chunk chunk = Engine.PositionToChunk(transform.position); if (chunk == null) { return; } Index voxelIndex = chunk.PositionToVoxelIndex(transform.position); VoxelInfo voxelInfo = new VoxelInfo(voxelIndex, chunk); // create a local copy of the collision voxel so we can call functions on it GameObject voxelObject = Instantiate(Engine.GetVoxelGameObject(voxelInfo.GetVoxel())) as GameObject; VoxelEvents events = voxelObject.GetComponent <VoxelEvents>(); if (events != null) { // OnEnter if (chunk != LastChunk || voxelIndex.IsEqual(LastIndex) == false) { events.OnBlockEnter(gameObject, voxelInfo); } else // OnStay { events.OnBlockStay(gameObject, voxelInfo); } } LastChunk = chunk; LastIndex = voxelIndex; Destroy(voxelObject); }
public void Update() { // don't load chunks if engine isn't initialized yet if (!Engine.Initialized || !ChunkManager.Initialized) { return; } // don't load chunks if multiplayer is enabled but the connection isn't established yet if (Engine.EnableMultiplayer) { if (!Network.isClient && !Network.isServer) { return; } } // track which chunk we're currently in. If it's different from previous frame, spawn chunks at current position. currentPos = Engine.PositionToChunkIndex (transform.position); if (currentPos.IsEqual(LastPos) == false) { ChunkManager.SpawnChunks(currentPos.x, currentPos.y, currentPos.z); // (Multiplayer) update server position if (Engine.EnableMultiplayer && Engine.MultiplayerTrackPosition && Engine.UniblocksNetwork != null) { UniblocksClient.UpdatePlayerPosition (currentPos); } } LastPos = currentPos; }
public void Update() { // track which chunk we're currently in. If it's different from previous frame, spawn chunks at current position. currentPos = Engine.PositionToChunkIndex (transform.position); if (currentPos.IsEqual(LastPos) == false) { ChunkManager.SpawnChunks(currentPos.x, currentPos.y, currentPos.z); // (Multiplayer) update server position if (Engine.EnableMultiplayer && Engine.MultiplayerTrackPosition && Engine.UniblocksNetwork != null) { UniblocksClient.UpdatePlayerPosition (currentPos); } } LastPos = currentPos; }
public void Update() { // check if chunk is not null GameObject chunkObject = Engine.PositionToChunk(transform.position); if (chunkObject == null) { return; } // get the voxelInfo from the transform's position Chunk chunk = chunkObject.GetComponent <Chunk>(); Index voxelIndex = chunk.PositionToVoxelIndex(transform.position); voxelInfo = new VoxelInfo(voxelIndex, chunk); // create a local copy of the collision voxel so we can call functions on it GameObject voxelObject = Instantiate(Engine.GetVoxelGameObject(voxelInfo.GetVoxel())) as GameObject; VoxelEvents events = voxelObject.GetComponent <VoxelEvents>(); if (events != null) { // OnEnter if (chunk != lastChunk || voxelIndex.IsEqual(voxelIndex) == false) { events.OnBlockEnter(gameObject, voxelInfo); } // OnStay else { events.OnBlockStay(gameObject, voxelInfo); } } lastChunk = chunk; Destroy(voxelObject); }