コード例 #1
0
ファイル: GameMap.cs プロジェクト: Sirzerion/UnityGameMap
        private void PlaceObjectOfTypeAt(int objectType, TileLoc loc)
        {
            ConnectedTileObject cto = connectedTileMap.GetConnectedTileAt(loc);

            bool shouldPlace = true;

            if (cto != null)
            {
                Debug.Log("Removing underlying tile of type " + objectType + " at " + loc + ".");
                connectedTileMap.RemoveConnectedTileAt(cto.tileLoc);

                if (cto.objectType == pathObjectTypeToBuild)
                {
                    // Do not place new path.
                    shouldPlace = false;
                }
            }

            if (shouldPlace)
            {
                Debug.Log("Placing a new tile of type " + objectType + " at " + loc + ".");
                connectedTileMap.CreateConnectedTileObject(loc, pathObjectTypeToBuild);
            }

            // Update the surrounding tiles
            UpdateNeigboursOf(loc);
        }
コード例 #2
0
        public TileLoc RelativeTo(TileLoc tileLoc)
        {
            if (tileLoc == null)
            {
                throw new ArgumentNullException();
            }

            return(new TileLoc(tileLoc.x + x, tileLoc.y + y));
        }
コード例 #3
0
ファイル: GameMap.cs プロジェクト: Sirzerion/UnityGameMap
        /**
         * Utility method used by both ConnectedTileObjects (paths) and TileObjects (other) to create a basic tile.
         */
        public GameObject CreateTileAt(TileLoc loc, Transform parent)
        {
            GameObject tile = GameObject.CreatePrimitive(PrimitiveType.Plane);

            tile.name                    = "Ground Tile (" + loc.x + ", " + loc.y + ")";
            tile.transform.parent        = parent;
            tile.transform.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
            tile.transform.localPosition = new Vector3(loc.x, 0, loc.y);

            return(tile);
        }
コード例 #4
0
ファイル: GameMap.cs プロジェクト: Sirzerion/UnityGameMap
        private void UpdateNeigboursOf(TileLoc tileLoc)
        {
            // Update neighbours
            foreach (TileLoc pos in TilesUtils.Cardinal)
            {
                ConnectedTileObject c =
                    GameMap.Instance.connectedTileMap.GetConnectedTileAt(pos.RelativeTo(tileLoc));

                if (c != null)
                {
                    Debug.Log("Updating " + tileLoc + "...");
                    c.UpdateConnection();
                }
            }
        }
コード例 #5
0
 public TileLoc(TileLoc tileLoc)
 {
     this.x = tileLoc.x;
     this.y = tileLoc.y;
 }
コード例 #6
0
ファイル: GameMap.cs プロジェクト: Sirzerion/UnityGameMap
        private void GenerateFakeObjectAtRandomPost()
        {
            TileLoc loc = new TileLoc(Random.Range(0, SquaredMapSize), Random.Range(0, SquaredMapSize));

            //GameObject donut = Resources.I TODO
        }