Beispiel #1
0
    private void Awake()
    {
        _instance = this;

        LoadPlayerAround();
    }
Beispiel #2
0
    /// <summary>
    /// 控制重建网格后,显示的面
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <returns>是否显示</returns>
    private bool IsRebuildBlockTransparent(int x, int y, int z)
    {
        #region 检查周围是否有图块,没有则显示该面
        Vector3 worldPos = DataUtil.FloorToInt(new Vector3(x, y, z) + transform.position);
        // 右边
        if (x >= length)
        {
            if (_rightChunk == null)
            {
                _rightChunk = ChunkMgr8Stone.GetChunkByChunkPos(chunkX + 1, chunkY, chunkZ);
            }
            if (_rightChunk != null && _rightChunk != this && _rightChunk.ready)
            {
                return(_rightChunk.GetBlock(worldPos) == null);
            }

            return(true);
        }

        // 左边
        if (x < 0)
        {
            if (_leftChunk == null)
            {
                _leftChunk = ChunkMgr8Stone.GetChunkByChunkPos(chunkX - 1, chunkY, chunkZ);
            }
            if (_leftChunk != null && _leftChunk != this && _leftChunk.ready)
            {
                return(_leftChunk.GetBlock(worldPos) == null);
            }

            return(true);
        }

        // 前面
        if (z < 0)
        {
            if (_frontChunk == null)
            {
                _frontChunk = ChunkMgr8Stone.GetChunkByWorldPos(worldPos);
            }
            if (_frontChunk != null && _frontChunk != this && _frontChunk.ready)
            {
                return(_frontChunk.GetBlock(worldPos) == null);
            }

            return(true);
        }

        // 后面
        if (z >= width)
        {
            if (_backChunk == null)
            {
                _backChunk = ChunkMgr8Stone.GetChunkByWorldPos(worldPos);
            }
            if (_backChunk != null && _backChunk != this && _backChunk.ready)
            {
                return(_backChunk.GetBlock(worldPos) == null);
            }

            return(true);
        }

        // 上面
        if (y >= height)
        {
            if (_topChunk == null)
            {
                _topChunk = ChunkMgr8Stone.GetChunkByWorldPos(worldPos);
            }
            if (_topChunk != null && _topChunk != this && _topChunk.ready)
            {
                return(_topChunk.GetBlock(worldPos) == null);
            }

            return(true);
        }

        // 下面
        if (y < 0)
        {
            if (_bottomChunk == null)
            {
                _bottomChunk = ChunkMgr8Stone.GetChunkByWorldPos(worldPos);
            }
            if (_bottomChunk != null && _bottomChunk != this && _bottomChunk.ready)
            {
                return(_bottomChunk.GetBlock(worldPos) == null);
            }

            return(true);
        }
        #endregion

        if (_map[x, y, z] == null)
        {
            return(true);
        }

        return(false);
    }
Beispiel #3
0
    public void SetBlock(Vector3 pos, Block block)
    {
        Vector3 localPos = pos - transform.position;
        int     blockX   = Mathf.CeilToInt(localPos.x);
        int     blockY   = Mathf.CeilToInt(localPos.y);
        int     blockZ   = Mathf.CeilToInt(localPos.z);

        //print("pos: " + pos.x + ", " + pos.y + ", " + pos.z);
        //print("local pos: " + blockX + ", " + blockY + ", " + blockZ);
        _map[blockX, blockY, blockZ] = block;

        StartCoroutine(RebuildMesh());
        if (block != null)
        {
            return;
        }

        #region 重构相邻的图块,补充未显示的面
        // 右边
        if (blockX == length - 1)
        {
            if (_rightChunk == null)
            {
                _rightChunk = ChunkMgr8Stone.GetChunkByChunkPos(blockX + 1, blockY, blockZ);
            }
            StartCoroutine(_rightChunk.RebuildMesh());
            //Debug.Log("rihgt : " + _rightChunk.name);
        }
        // 左边
        if (blockX == 0)
        {
            if (_leftChunk == null)
            {
                _leftChunk = ChunkMgr8Stone.GetChunkByChunkPos(chunkX - 1, chunkY, chunkZ);
            }
            StartCoroutine(_leftChunk.RebuildMesh());
            //Debug.Log("left : " + _leftChunk.name);
        }
        // 前面
        if (blockZ == 0)
        {
            if (_frontChunk == null)
            {
                _frontChunk = ChunkMgr8Stone.GetChunkByChunkPos(blockX, blockY, blockZ - 1);
            }
            StartCoroutine(_frontChunk.RebuildMesh());
            //Debug.Log("front : " + _frontChunk.name);
        }
        // 后面
        if (blockZ == width - 1)
        {
            if (_backChunk == null)
            {
                _backChunk = ChunkMgr8Stone.GetChunkByChunkPos(blockX, blockY, blockZ + 1);
            }
            StartCoroutine(_backChunk.RebuildMesh());
            //Debug.Log("back : " + _backChunk.name);
        }
        // 上面
        if (blockY == height - 1)
        {
            if (_topChunk == null)
            {
                _topChunk = ChunkMgr8Stone.GetChunkByChunkPos(blockX, blockY + 1, blockZ);
            }
            StartCoroutine(_topChunk.RebuildMesh());
            //Debug.Log("top : " + _topChunk.name);
        }
        // 下面
        if (blockY == 0)
        {
            if (_bottomChunk == null)
            {
                _bottomChunk = ChunkMgr8Stone.GetChunkByWorldPos(blockX, blockY - 1, blockZ);
            }
            StartCoroutine(_bottomChunk.RebuildMesh());
            //Debug.Log("bottom : " + _bottomChunk.name);
        }
        #endregion
    }
Beispiel #4
0
    /// <summary>
    /// 加载周围的图块
    /// </summary>
    public void LoadAround()
    {
        // 左边
        if (_leftChunk == null)
        {
            if (!ChunkMgr8Stone.Instance().IsInPreLoadRange(
                    new Vector3((chunkX - 1) * Chunk.length, chunkY * Chunk.height, chunkZ * Chunk.width)))
            {
                return;
            }

            _leftChunk = ChunkMgr8Stone.GetChunkByChunkPos(new Vector3(chunkX - 1, chunkY, chunkZ));
            if (_leftChunk == null)
            {
                ChunkMgr8Stone.Instance().AddChunk(chunkX - 1, chunkY, chunkZ);
            }
        }
        // 右边
        if (_rightChunk == null)
        {
            if (!ChunkMgr8Stone.Instance().IsInPreLoadRange(
                    new Vector3((chunkX + 1) * Chunk.length, chunkY * Chunk.height, chunkZ * Chunk.width)))
            {
                return;
            }

            _rightChunk = ChunkMgr8Stone.GetChunkByChunkPos(new Vector3(chunkX + 1, chunkY, chunkZ));
            if (_rightChunk == null)
            {
                ChunkMgr8Stone.Instance().AddChunk(chunkX + 1, chunkY, chunkZ);
            }
        }
        // 前面
        if (_frontChunk == null)
        {
            if (!ChunkMgr8Stone.Instance().IsInPreLoadRange(
                    new Vector3(chunkX * Chunk.length, chunkY * Chunk.height, (chunkZ - 1) * Chunk.width)))
            {
                return;
            }

            _frontChunk = ChunkMgr8Stone.GetChunkByChunkPos(new Vector3(chunkX, chunkY, chunkZ - 1));
            if (_frontChunk == null)
            {
                ChunkMgr8Stone.Instance().AddChunk(chunkX, chunkY, chunkZ - 1);
            }
        }
        // 后面
        if (_backChunk == null)
        {
            if (!ChunkMgr8Stone.Instance().IsInPreLoadRange(
                    new Vector3(chunkX * Chunk.length, chunkY * Chunk.height, (chunkZ + 1) * Chunk.width)))
            {
                return;
            }

            _backChunk = ChunkMgr8Stone.GetChunkByChunkPos(new Vector3(chunkX, chunkY, chunkZ + 1));
            if (_backChunk == null)
            {
                ChunkMgr8Stone.Instance().AddChunk(chunkX + 1, chunkY, chunkZ + 1);
            }
        }
        // 上面
        if (_topChunk == null)
        {
            if (!ChunkMgr8Stone.Instance().IsInPreLoadRange(
                    new Vector3(chunkX * Chunk.length, (chunkY + 1) * Chunk.height, chunkZ * Chunk.width)))
            {
                return;
            }

            _topChunk = ChunkMgr8Stone.GetChunkByChunkPos(new Vector3(chunkX, chunkY + 1, chunkZ));
            if (_topChunk == null)
            {
                ChunkMgr8Stone.Instance().AddChunk(chunkX, chunkY + 1, chunkZ);
            }
        }
        // 下面
        if (_bottomChunk == null)
        {
            if (!ChunkMgr8Stone.Instance().IsInPreLoadRange(
                    new Vector3(chunkX * Chunk.length, (chunkY - 1) * Chunk.height, chunkZ * Chunk.width)))
            {
                return;
            }

            _bottomChunk = ChunkMgr8Stone.GetChunkByChunkPos(new Vector3(chunkX, chunkY - 1, chunkZ));
            if (_bottomChunk == null)
            {
                ChunkMgr8Stone.Instance().AddChunk(chunkX, chunkY - 1, chunkZ);
            }
        }
    }