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

            bool shouldPlace = true;

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

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

            if (shouldPlace)
            {
                Debug.Log("Placing a new tile of type " + id + " at " + loc + ".");
                connectedGenericTileMap.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
        public T GetTileObjectAt(TileLoc tileLoc)
        {
            if (tileLoc == null)
            {
                Debug.LogError("Fatal : TileLoc should not be null.");
                return(null);
            }

            return(!Tiles.ContainsKey(tileLoc) ? null : Tiles[tileLoc]);
        }
コード例 #4
0
ファイル: GameMap.cs プロジェクト: AldeRoberge/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);
        }
コード例 #5
0
        public void RemoveTileObjectAt(TileLoc tileLoc)
        {
            if (tileLoc == null)
            {
                Debug.LogError("Fatal : TileLoc should not be null.");
                return;
            }

            if (Tiles.ContainsKey(tileLoc))
            {
                Tiles.Remove(tileLoc);
            }
        }
コード例 #6
0
ファイル: GameMap.cs プロジェクト: AldeRoberge/UnityGameMap
        // Converts a TileLoc to a Vector3
        public Vector3 GetWorldPosFromTileLoc(TileLoc tileLoc)
        {
            TileObject tileAt = tileMap.GetTileObjectAt(tileLoc);

            if (tileAt != null)
            {
                return(new Vector3(tileAt.transform.position.x, 0, tileAt.transform.position.z));
            }

            Debug.Log("tileMapTiles : " + tileMap.Tiles.Count);

            Debug.LogError("Fatal error : Could not find tile at '" + tileLoc + "'.");

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

                if (c != null)
                {
                    Debug.Log("Updating " + tileLoc + "...");
                    c.UpdateConnection();
                }
            }
        }
コード例 #8
0
ファイル: TileMap.cs プロジェクト: AldeRoberge/UnityGameMap
        public TileObject CreateTileObject(TileLoc loc, string type = UITileObjectTypes.DEFAULT)
        {
            if (GetTileObjectAt(loc) != null)
            {
                Debug.Log("Fatal : Tile already at '" + loc + "'.");
                return(null);
            }

            GameObject tile = GameMap.Instance.CreateTileAt(loc, transform);

            TileObject c = tile.AddComponent <TileObject>();

            c.SetObjectType(type);
            c.tileLoc = loc;

            Tiles.Add(loc, c);

            return(c);
        }
コード例 #9
0
 public TileLoc(TileLoc tileLoc)
 {
     x = tileLoc.x;
     y = tileLoc.y;
 }