Beispiel #1
0
    private void CreateBlocks(bool FromExisting = false)
    {
        List <MapBlock> newBlocks = new List <MapBlock>();

        for (int x = 0; x < Size.x; ++x)
        {
            for (int y = 0; y < Size.y; ++y)
            {
                GameObject newBlock = new GameObject("Block (" + x + "," + y + ")");
                newBlock.transform.parent = transform;

                MapBlock blockComponent = newBlock.AddComponent <MapBlock>();
                blockComponent.SetCoordinates(new Vector2(x, y));

                if (FromExisting)
                {
                    MapBlock block = GetBlock(new Vector2(x, y));
                    blockComponent.Copy(block);
                    blockComponent.UpdateWalls();
                }
                newBlocks.Add(blockComponent);
            }
        }

        for (int i = Blocks.Count - 1; i >= 0; --i)
        {
            DestroyImmediate(Blocks[i].gameObject);
        }
        Blocks.Clear();
        Blocks.AddRange(newBlocks);

        if (FogFrontRef[0] != null)
        {
            DestroyImmediate(FogFrontRef[0]);
        }

        Vector3 wallOffset = new Vector3(-0.5f, 0.5f, 0.5f);

        FogFrontRef[0] = Instantiate(FogFront);
        FogFrontRef[0].transform.localScale = new Vector3(FogFrontRef[0].transform.localScale.x * Size.x,
                                                          FogFrontRef[0].transform.localScale.y, FogFrontRef[0].transform.localScale.z);

        FogFrontRef[0].transform.position = MapCoordinatesToWorldSpace(new Vector2(Size.x / 2, 0)) + wallOffset;

        if (FogFrontRef[1] != null)
        {
            DestroyImmediate(FogFrontRef[1]);
        }

        FogFrontRef[1] = Instantiate(FogFront);
        FogFrontRef[1].transform.localScale = new Vector3(FogFrontRef[1].transform.localScale.x * Size.x,
                                                          FogFrontRef[1].transform.localScale.y, FogFrontRef[1].transform.localScale.z);

        FogFrontRef[1].transform.position = MapCoordinatesToWorldSpace(new Vector2(Size.x / 2, Size.y)) + wallOffset;

        if (FogSideRef[0] != null)
        {
            DestroyImmediate(FogSideRef[0]);
        }
        FogSideRef[0] = Instantiate(FogSide);
        FogSideRef[0].transform.localScale = new Vector3(FogSideRef[0].transform.localScale.x * Size.y,
                                                         FogSideRef[0].transform.localScale.y, FogSideRef[0].transform.localScale.z);
        FogSideRef[0].transform.position = MapCoordinatesToWorldSpace(new Vector2(0, Size.y / 2)) + wallOffset;

        if (FogSideRef[1] != null)
        {
            DestroyImmediate(FogSideRef[1]);
        }
        FogSideRef[1] = Instantiate(FogSide);
        FogSideRef[1].transform.localScale = new Vector3(FogSideRef[1].transform.localScale.x * Size.y,
                                                         FogSideRef[1].transform.localScale.y, FogSideRef[1].transform.localScale.z);
        FogSideRef[1].transform.position = MapCoordinatesToWorldSpace(new Vector2(Size.x, Size.y / 2)) + wallOffset;
    }