public void InitializeChunk(int[,] chunk, int x, int y)
    {
        if (_chunkNames.Contains(("Chunk_" + x.ToString() + "_" + y.ToString())))
        {
            return;
        }
        var parent = new GameObject();

        parent.transform.SetParent(Map.transform);
        parent.transform.position = new Vector2(x * ChunkGen.ChunkWidth, y * ChunkGen.ChunkHeight);
        parent.name = "Chunk_" + x + "_" + y;
        _chunkNames.Add(parent.name);

        for (int i = 0; i < ChunkGen.ChunkWidth; i++)
        {
            for (int j = 0; j < ChunkGen.ChunkHeight; j++)
            {
                var pos  = new Vector2(i, j);
                var tile = (Transform)(Instantiate(TileTemplate, pos, Quaternion.identity));
                tile.SetParent(parent.transform, false);
                tile.name = "Tile_" + i + "_" + j;
                OldTile tileScript = tile.GetComponent <OldTile>();
                tileScript.TileType = chunk[i, j];
            }
        }
    }
コード例 #2
0
    private void CheckBlockedMouseUp(ContactPoint2D contact)
    {
        Vector2 thisPosition  = transform.position;
        Vector2 otherPosition = contact.collider.transform.position;

        bool isWall          = contact.collider.gameObject.layer != TILE;
        bool isMouseDownTile = false;
        bool isHeldUpTile    = false;

        if (!isWall)
        {
            OldTile contactTile = contact.collider.gameObject.GetComponent <OldTile>();
            isMouseDownTile = contactTile.mouseDown;
            isHeldUpTile    = contactTile.heldUp;
        }

        if (contact.normal == Vector2.down && (thisPosition.x == otherPosition.x || isWall || isMouseDownTile))
        {
            blockedTop = true;
        }
        if (contact.normal == Vector2.up && (thisPosition.x == otherPosition.x || isWall || isMouseDownTile))
        {
            blockedBottom = true;
            if (isMouseDownTile || isHeldUpTile)
            {
                heldUp = true;
            }
        }
        if (contact.normal == Vector2.right)
        {
            blockedLeft = true;
        }
        if (contact.normal == Vector2.left)
        {
            blockedRight = true;
        }
    }