コード例 #1
0
    public Hex SpawnAHex(MapElement hexInfo)
    {
        Hex hexInstance = HexBank.Instance.GetDisabledHex(
            hexInfo.GetHex().typeOfHex,
            grid.CellToWorld(new Vector2Int(hexInfo.gridPos.x, hexInfo.gridPos.y)).Value, grid.transform).GetComponent <Hex>();


        Vector3 localPos = ((Vector3)grid.CellToWorld(new Vector2Int(hexInfo.gridPos.x, hexInfo.gridPos.y)));

        hexInstance.transform.localPosition = localPos;

        hexInstance.transform.rotation = grid.transform.rotation;
        if (hexInfo.hexAttribute != null)
        {
            hexInfo.hexAttribute.AddAttributeToHex(hexInstance);
        }
        SetGameobjectWidth(hexInstance.gameObject);

        if (mapLayers[MAP_LAYER_0].ContainsKey(hexInfo.gridPos))
        {
            Hex oldHex = mapLayers[MAP_LAYER_0][hexInfo.gridPos];
            oldHex.FinishDestroy();
            mapLayers[MAP_LAYER_0][hexInfo.gridPos] = hexInstance;

            if (GameManager.instance != null)
            {
                GameManager.instance.ReplaceTilePassScores(oldHex.destroyPoints, hexInstance.destroyPoints);
            }
        }
        else
        {
            mapLayers[MAP_LAYER_0].Add(hexInfo.gridPos, hexInstance);

            if (GameManager.instance != null)
            {
                GameManager.instance.ReplaceTilePassScores(0, hexInstance.destroyPoints);
            }
        }


        return(hexInstance);
    }