Beispiel #1
0
    public GameObject edge5; // right edge,        adjacent neighbor (x  , y+1)

    void Start()
    {
        int len = gameObject.transform.childCount;

        edge0 = gameObject.transform.GetChild(len - 6).gameObject;
        edge1 = gameObject.transform.GetChild(len - 5).gameObject;
        edge2 = gameObject.transform.GetChild(len - 4).gameObject;
        edge3 = gameObject.transform.GetChild(len - 3).gameObject;
        edge4 = gameObject.transform.GetChild(len - 2).gameObject;
        edge5 = gameObject.transform.GetChild(len - 1).gameObject;

        // TODO Check from neighboring tiles if they have the same type.
        Debug.Log("This Tile position width: " + _coordinateWidth + " height: " + _coordinateHeight);

        for (int i = 0; i < _neighborTiles.Count; i++)
        {
            // Debug.Log("------> Neighbor:  " + _neighborTiles[i]._type + ", position: " + _neighborTiles[i]._coordinateWidth + "." + _neighborTiles[i]._coordinateHeight);
        }


        foreach (var neighborTile in _neighborTiles)
        {
            if (_type.Equals(neighborTile._type))
            {
                int x = neighborTile._coordinateWidth;
                int y = neighborTile._coordinateHeight;
                if (IsEven(_coordinateWidth))
                {
                    if (x + 1 == _coordinateWidth && y + 1 == _coordinateHeight) // edge0 and edge3 are adjacent
                    {
                        //neighborTile.edge0.SetActive(false);
                        edge3.SetActive(false);
                    }
                    if (x + 1 == _coordinateWidth && y == _coordinateHeight) // edge1 and edge4 are adjacent
                    {
                        //neighborTile.edge1.SetActive(false);
                        edge4.SetActive(false);
                    }
                    if (x + 1 == _coordinateWidth && y - 1 == _coordinateHeight)
                    {
                        //neighborTile.edge1.SetActive(false);
                        edge4.SetActive(false);
                    }


                    if (x == _coordinateWidth && y + 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge5.SetActive(false);
                        edge2.SetActive(false);
                    }
                    if (x == _coordinateWidth && y - 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge5.SetActive(false);
                    }


                    if (x - 1 == _coordinateWidth && y + 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge1.SetActive(false);
                    }
                    if (x - 1 == _coordinateWidth && y == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge0.SetActive(false);
                    }
                    if (x - 1 == _coordinateWidth && y - 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge0.SetActive(false);
                    }
                }
                else
                {
                    if (x + 1 == _coordinateWidth && y + 1 == _coordinateHeight) // edge0 and edge3 are adjacent
                    {
                        //neighborTile.edge0.SetActive(false);
                        edge3.SetActive(false);
                    }
                    if (x + 1 == _coordinateWidth && y == _coordinateHeight) // edge1 and edge4 are adjacent
                    {
                        //neighborTile.edge1.SetActive(false);
                        edge3.SetActive(false);
                    }
                    if (x + 1 == _coordinateWidth && y - 1 == _coordinateHeight)
                    {
                        //neighborTile.edge1.SetActive(false);
                        edge4.SetActive(false);
                    }


                    if (x == _coordinateWidth && y + 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge5.SetActive(false);
                        edge2.SetActive(false);
                    }
                    if (x == _coordinateWidth && y - 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge5.SetActive(false);
                    }


                    if (x - 1 == _coordinateWidth && y + 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge1.SetActive(false);
                    }
                    if (x - 1 == _coordinateWidth && y == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge1.SetActive(false);
                    }
                    if (x - 1 == _coordinateWidth && y - 1 == _coordinateHeight) //
                    {
                        //neighborTile.edge2.SetActive(false);
                        edge0.SetActive(false);
                    }
                }
            }
        }
    }