Example #1
0
    public MapBlock CreateOrGetBlock(WorldSpaceType type, ShapeIndex block_index)
    {
        MapBlock block       = null;
        var      block_array = GetMapBlocks(type);

        if (block_array != null)
        {
            int array_index = GetBlockArrayIndex(block_index);
            if (block_array.Length <= array_index)
            {
                int        len = (block_index.z + EXPAND_BLOCK_SIZE) * BLOCKMAP_SIZE * BLOCKMAP_SIZE;
                MapBlock[] bs  = new MapBlock[len];
                Array.Copy(block_array, bs, block_array.Length);
                SetMapBlocks(type, bs);
                block_array = bs;
            }

            block = block_array[array_index];
            if (block == null)
            {
                block           = new MapBlock();
                block.SpaceType = type;
                block.Index     = block_index;
                block.Init();
                block_array[array_index] = block;
            }
        }
        return(block);
    }
Example #2
0
    private Block CreateBlock()
    {
        BlockSaveData saveData = ScriptableObject.CreateInstance <BlockSaveData> ();

        saveData.id            = blockID;
        saveData.name          = "Block_" + blockID;
        saveData.tileColor     = currentColor;
        saveData.slotPosition  = Vector3.zero;
        saveData.hintPosition  = mapTiles[0].transform.localPosition;
        saveData.tilePositions = new List <Vector3> ();
        foreach (MapTile mapTile in mapTiles)
        {
            saveData.tilePositions.Add(mapTile.transform.localPosition - saveData.hintPosition);
        }

        MapBlock block = GameObject.Instantiate <MapBlock> (Map.Instance.mapBlockPrefab);

        block.Init(saveData);
        blocks.Add(block.id, block);

        blockID++;
        mapTiles     = new List <MapTile>();
        currentColor = colors[Random.Range(0, colors.Length)];
        return(block);
    }
Example #3
0
    public void Init(MapSaveData info)
    {
        while (0 < tiles.childCount)
        {
            Transform tile = tiles.GetChild(0);
            tile.SetParent(null);
            DestroyImmediate(tile.gameObject);
        }

        while (0 < blocks.childCount)
        {
            Transform block = blocks.GetChild(0);
            block.SetParent(null);
            DestroyImmediate(block.gameObject);
        }

        while (0 < slots.childCount)
        {
            Transform slot = slots.GetChild(0);
            slot.SetParent(null);
            DestroyImmediate(slot.gameObject);
        }

        while (0 < hints.childCount)
        {
            Transform hint = hints.GetChild(0);
            hint.SetParent(null);
            DestroyImmediate(hint.gameObject);
        }

        if (null != _blinkHintBlock)
        {
            StopCoroutine(_blinkHintBlock);
            _blinkHintBlock = null;
        }
        activatedHintBlocks = new List <HintBlock> ();

        stage          = info.stage;
        level          = info.level;
        width          = info.width;
        height         = info.height;
        blockSlotScale = info.blockSlotScale;
        if (0 == width || 0 == height)
        {
            throw new System.Exception("zero size map");
        }

        mapTiles = new MapTile[width * height];
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                MapTile mapTile = GameObject.Instantiate <MapTile> (mapTilePrefab);
                mapTile.name = "MapTile_" + x + "_" + y;
                mapTile.transform.SetParent(tiles, false);
                mapTile.transform.localPosition = new Vector3(x, height - y, 0.0f);
                mapTile.Init(info.tiles [x + y * width]);
                mapTiles [x + y * width] = mapTile;
            }
        }
        {
            Vector3 position = transform.position;
            position.x         = -(float)(width - 1) / 2;
            transform.position = position;
        }

        {
            Transform blockSlots = transform.Find("BlockSlots");
            Vector3   position   = blockSlots.position;
            position.x = 0.0f;
            blockSlots.transform.position = position;
        }

        mapBlocks = new List <MapBlock> ();
        if (null != info.blocks)
        {
            foreach (BlockSaveData blockSaveData in info.blocks)
            {
                MapBlock mapBlock = GameObject.Instantiate <MapBlock> (mapBlockPrefab);
                mapBlock.Init(blockSaveData);
                mapBlocks.Add(mapBlock);
            }
        }
    }