예제 #1
0
    private void DrawHelpTiles(Vector3 perfPos)
    {
        foreach (GameObject inst in instances)
        {
            Destroy(inst);
        }

        instances.Clear();

        //main tile
        Vector3Int mainTilePos = game.landMap.WorldToCell(perfPos);

        if (!game.structureMap.HasTile(mainTilePos) && structureToBuild.CanBuild(game.landMap.GetTile(mainTilePos) as TownGameTile) == true)
        {
            instances.Add(Instantiate(canBuildTile, perfPos, new Quaternion()));
        }
        else
        {
            instances.Add(Instantiate(notBuildTile, perfPos, new Quaternion()));
        }

        if (!(structureToBuild is House))
        {
            if (structureToBuild is Farm)
            {
                Vector3Int[] posTiles = GetNeighboursPosInTileMap(perfPos);

                foreach (Vector3Int pos in posTiles)
                {
                    if (game.landMap.GetTile(pos) == game.grassTile)
                    {
                        if (game.structureMap.HasTile(pos))
                        {
                            GameObject obj = game.structureInfo.GetPositionProperty <UnityEngine.Object>(pos, "tileObj", null) as GameObject;
                            if (obj != null)
                            {
                                WheatField tile = obj.GetComponent <WheatField>();

                                if (tile != null)
                                {
                                    instances.Add(Instantiate(canBuildTile, game.structureMap.CellToWorld(pos), new Quaternion()));
                                }
                            }
                        }
                        else
                        {
                            instances.Add(Instantiate(canBuildTile, game.structureMap.CellToWorld(pos), new Quaternion()));
                        }
                    }
                }
            }
            else
            {
                Vector3Int[] posTiles = GetNeighboursPosInTileMap(perfPos);

                foreach (Vector3Int pos in posTiles)
                {
                    if (game.structureMap.HasTile(pos))
                    {
                        GameObject obj = game.structureInfo.GetPositionProperty <UnityEngine.Object>(pos, "tileObj", null) as GameObject;
                        if (obj != null)
                        {
                            ResourceObject tile = obj.GetComponent <ResourceObject>();

                            if (tile != null && tile.HasResource(structureToBuild.resourse))
                            {
                                instances.Add(Instantiate(canBuildTile, game.structureMap.CellToWorld(pos), new Quaternion()));
                            }
                        }
                    }
                }
            }
        }
    }