コード例 #1
0
 /**
  *<summary>
  * Used to change the tile shown by this node to one of the given <see cref="TileRoadType"/>
  *</summary>
  */
 void updateTile(TileRoadType type)
 {
     Destroy(tile);
     tile = Instantiate(roadLookupTable.getTile(type)) as GameObject;
     tile.transform.SetParent(transform);
     tile.transform.localPosition = new Vector3(0, 0.5f, 0);
 }
コード例 #2
0
        /**
         *<summary>
         * Changes the tile Gameobject to the appropriate one and sets the rotation based on its neighbors
         *</summary>
         */
        public void redrawRoads(NodePosition nodePos)
        {
            Debug.Log("Redraw Roads is called for " + nodePos);
            bool nNeighborEnabled = false, sNeighborEnabled = false, eNeighborEnabled = false, wNeighborEnabled = false;
            int  newNeighborWithRoadCount = 0;

            NodeModel temp = NodeManager.getNode(nodePos.xIndex + 1, nodePos.zIndex);

            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    eNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            temp = NodeManager.getNode(nodePos.xIndex - 1, nodePos.zIndex);
            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    wNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            temp = NodeManager.getNode(nodePos.xIndex, nodePos.zIndex + 1);
            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    nNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            temp = NodeManager.getNode(nodePos.xIndex, nodePos.zIndex - 1);
            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    sNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            //Debug.Log(newNeighborWithRoadCount);

            type = assignTileRoadType(newNeighborWithRoadCount, nNeighborEnabled, sNeighborEnabled, eNeighborEnabled, wNeighborEnabled);
            updateTile(type);
            correctRoadRotation(type, nNeighborEnabled, sNeighborEnabled, eNeighborEnabled, wNeighborEnabled);
        }
コード例 #3
0
 /**
  *<summary>
  * Used to rotate a tile of arbitrary configuration to the correct rotation
  *</summary>
  */
 void correctRoadRotation(TileRoadType type, bool nNeighbor, bool sNeighbor, bool eNeighbor, bool wNeighbor)
 {
     if (type == TileRoadType.N_S)
     {
         correctNS_RoadRotation(nNeighbor, sNeighbor, eNeighbor, wNeighbor);
     }
     else if (type == TileRoadType.N_E)
     {
         correctNE_RoadRotation(nNeighbor, sNeighbor, eNeighbor, wNeighbor);
     }
     else if (type == TileRoadType.N_S_W)
     {
         correctNSW_RoadRotation(nNeighbor, sNeighbor, eNeighbor, wNeighbor);
     }
 }
コード例 #4
0
        /**
         *<summary>
         * Sets a TileRoadType enum based on the number of Neighbors
         *</summary>
         */
        TileRoadType assignTileRoadType(int neighborRoadNumbers, bool nNeighbor, bool sNeighbor, bool eNeighbor, bool wNeighbor)
        {
            TileRoadType type;

            if (neighborRoadNumbers == 0)
            {
                type = TileRoadType.NO_NEIGHBOR;
            }
            else if (neighborRoadNumbers == 1)
            {
                type = TileRoadType.N_S;
            }
            else if (neighborRoadNumbers == 2)
            {
                if ((nNeighbor && sNeighbor) || (eNeighbor && wNeighbor))
                {
                    type = TileRoadType.N_S;
                }
                else
                {
                    type = TileRoadType.N_E;
                }
            }
            else if (neighborRoadNumbers == 3)
            {
                type = TileRoadType.N_S_W;
            }
            else
            {
                type = TileRoadType.N_S_E_W;
            }
            if (!model.roadEnabled)
            {
                type = TileRoadType.NO_ROAD;
            }
            return(type);
        }
コード例 #5
0
ファイル: TileRoadLookupTable.cs プロジェクト: Seth-W/EcoTile
 public GameObject getTile(TileRoadType type)
 {
     return(tileRoadLookupTable[(int)type]);
 }