Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        objectPos = transform.position;

        if (deleteTimer == WaitBetweenDeletes)
        {
            DeleteChunks();

            deleteTimer = 0;
            return;
        }
        else
        {
            deleteTimer++;
        }

        if (chunksToRender.Count != 0)
        {
            for (int i = 0; i < ChunksToLoadPerFrame; i++)
            {
                if (chunksToRender.Count == 0)
                {
                    break;
                }

                Pos pos   = chunksToRender[0];
                var chunk = chunks.GetChunk(pos);
                if (chunk != null)
                {
                    chunk.Render();
                }
                chunksToRender.RemoveAt(0);
            }

            if (RenderChunksInSeparateFrame)
            {
                return;
            }
        }

        if (chunksToGenerate.Count == 0)
        {
            FindChunksAndLoad();
        }

        for (int i = 0; i < ChunksToLoadPerFrame; i++)
        {
            if (chunksToGenerate.Count == 0)
            {
                break;
            }

            Pos pos = chunksToGenerate[0];
            chunks.CreateChunk(pos);

            chunksToGenerate.RemoveAt(0);
            chunksToRender.Add(pos);
        }
    }
Ejemplo n.º 2
0
    private bool TestDepth(ref Vector2Int[] lookupReference, int currentIndex, int depth)
    {
        int currentX = currentIndex % mChunkSettings.NumberOfColumns;
        int currentY = (currentIndex / mChunkSettings.NumberOfColumns) % mChunkSettings.NumberOfRows;
        int currentZ = (currentIndex / mChunkSettings.NumberOfColumns) / mChunkSettings.NumberOfRows;

        for (int i = 0; i < lookupReference.Length; ++i)
        {
            int nextX = currentX + lookupReference[i].x;
            int nextY = currentY + lookupReference[i].y;
            if (nextX < 0 || nextX >= mChunkSettings.NumberOfColumns)
            {
                continue;
            }

            if (nextY >= 0 && nextY < mChunkSettings.NumberOfRows)
            {
                int nextId = GetTileId(nextX, nextY, currentZ);
                if (!mChunkSettings.TileData[nextId].IsCollision)
                {
                    mTileDepth[currentIndex] = depth;
                    return(true);
                }
            }
            else
            {
                Chunk otherChunk = null;
                if (nextY < 0)
                {
                    otherChunk = mController.GetChunk(mChunkIndex - 1);
                    nextY      = mChunkSettings.NumberOfRows + nextY;
                }
                else
                {
                    otherChunk = mController.GetChunk(mChunkIndex + 1);
                    nextY      = nextY - mChunkSettings.NumberOfRows;
                }
                if (otherChunk != null)
                {
                    int nextId = otherChunk.GetTileId(nextX, nextY, currentZ);
                    if (!mChunkSettings.TileData[nextId].IsCollision)
                    {
                        mTileDepth[currentIndex] = depth;
                        return(true);
                    }
                }
            }
        }

        return(false);
    }