「UnityによるARゲーム開発」という参考書を見ながら進めているのですが,importさせられて使うスクリプトは数年前のもので,まだスクリプトの組み方は書かれていないので自分で修正することが出来ません.どのように変更すればよいでしょうか
GitHub
ここにファイル等が保存されていて,現在使用しているのはresources内のchapter2です.
###望み
このタイル状に記入してある座標の地図を出したい.
Assets\FoodyGo\Scripts\Mapping\GoogleMapTile.cs(84,17): warning CS0219: The variable 'url' is assigned but its value is never used Assets\FoodyGo\Scripts\Mapping\GoogleMapTile.cs(118,26): warning CS0618: 'UnityWebRequest.Send()' is obsolete: 'Use SendWebRequest. It returns a UnityWebRequestAsyncOperation which contains a reference to the WebRequest object.' Assets\FoodyGo\Scripts\Mapping\GoogleMapTile.cs(90,39): warning CS0618: 'WWW' is obsolete: 'Use UnityWebRequest, a fully featured replacement which is more efficient and has additional features' Assets\FoodyGo\Scripts\Mapping\GoogleMapTile.cs(88,40): warning CS0618: 'WWW' is obsolete: 'Use UnityWebRequest, a fully featured replacement which is more efficient and has additional features' There are inconsistent line endings in the 'Assets/FoodyGo/Scripts/Mapping/Geometry.cs' script. Some are Mac OS X (UNIX) and some are Windows. This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.
###追記
上記のエラーコードをひとまず自分でできるところは対処してみました.
errorで推奨されていた方に書き換えただけですが.
C#
1using UnityEngine; 2using UnityEngine.Networking; 3using System.Collections; 4using packt.FoodyGo.Mapping; 5using packt.FoodyGo.Services; 6 7namespace packt.FoodyGO.Mapping 8{ 9 [AddComponentMenu("Mapping/GoogleMapTile")] 10 public class GoogleMapTile : MonoBehaviour 11 { 12 public enum MapType 13 { 14 RoadMap, 15 Satellite, 16 Terrain, 17 Hybrid 18 } 19 20 //Google Maps API Staticmap URL 21 private const string GOOGLE_MAPS_URL = "https://maps.googleapis.com/maps/api/staticmap"; 22 23 [Header("Map Settings")] 24 [Range(1,20)] 25 [Tooltip("Zoom Level, 1=global - 20=house")] 26 public int zoomLevel = 1; 27 [Tooltip("Type of map, Road, Satellite, Terrain or Hybrid")] 28 public MapType mapType = MapType.RoadMap; 29 [Range(64,1024)] 30 [Tooltip("Size in pixels of the map image")] 31 public int size = 640; 32 [Tooltip("Double the pixel resolution of the image returned")] 33 public bool doubleResolution = true; 34 35 public MapLocation worldCenterLocation; 36 37 [Header("Tile Settings")] 38 [Tooltip("Sets the tiles position in tile units")] 39 public Vector2 TileOffset; 40 [Tooltip("Calculated tile center")] 41 public MapLocation tileCenterLocation; 42 [Tooltip("Calculated tile corners")] 43 public Vector2 TopLeftCorner; 44 public Vector2 BottomRightCorner; 45 46 [Header("GPS Settings")] 47 [Tooltip("GPS service used to locate world center")] 48 public GPSLocationService gpsLocationService; 49 private double lastGPSUpdate; 50 51 // Use this for initialization 52 void Start () 53 { 54 RefreshMapTile (); 55 } 56 57 // Update is called once per frame 58 void Update () 59 { 60 // 新しい位置が取得されたかどうかを確認する 61 if (gpsLocationService != null && 62 gpsLocationService.IsServiceStarted && 63 lastGPSUpdate < gpsLocationService.Timestamp) 64 { 65 lastGPSUpdate = gpsLocationService.Timestamp; 66 worldCenterLocation.Latitude = gpsLocationService.Latitude; 67 worldCenterLocation.Longitude = gpsLocationService.Longitude; 68 print("GoogleMapTile refreshing map texture"); 69 RefreshMapTile(); 70 } 71 } 72 73 public void RefreshMapTile() { 74 75 StartCoroutine(_RefreshMapTile()); 76 } 77 78 IEnumerator _RefreshMapTile () 79 { 80 // タイル中心の緯度/経度を取得 81 tileCenterLocation.Latitude = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel); 82 tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel); 83 84 var url = GOOGLE_MAPS_URL; 85 var queryString = ""; 86 87 // 地図タイルをリクエストするクエリ文字列パラメーターを作成する 88 queryString += "center=" + UnityWebRequest.UnEscapeURL (string.Format ("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude)); 89 queryString += "&zoom=" + zoomLevel.ToString (); 90 queryString += "&size=" + UnityWebRequest.UnEscapeURL (string.Format ("{0}x{0}", size)); 91 queryString += "&scale=" + (doubleResolution ? "2" : "1"); 92 queryString += "&maptype=" + mapType.ToString ().ToLower (); 93 queryString += "&format=" + "png"; 94 95 // 地図のスタイルを追加する 96 queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5"; 97 queryString += "&style=element:labels|visibility:off"; 98 99 var usingSensor = false; 100#if MOBILE_INPUT 101 usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running; 102#endif 103 104 queryString += "&sensor=" + (usingSensor ? "true" : "false"); 105 106 //set map bounds rect 107 TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel); 108 TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel); 109 110 BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel); 111 BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel); 112 113 print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString)); 114 115 // 最後に、画像をリクエストする 116 var req = UnityWebRequestTexture.GetTexture(GOOGLE_MAPS_URL + "?" + queryString); 117 // サービスが応答するまで待つ 118 yield return SendWebRequest; 119 // 最初に古いテクスチャーを破棄する 120 Destroy(GetComponent<Renderer>().material.mainTexture); 121 // エラーをチェックする 122 if (req.error != null) { 123 print (string.Format ("Error loading tile {0}x{1}: exception={2}", 124 TileOffset.x, TileOffset.y, req.error)); 125 } else { 126 // レンダリング画像がエラーがなければ戻ってきた画像をタイルテクスチャーとして設定する 127 GetComponent<Renderer> ().material.mainTexture = ((DownloadHandlerTexture)req.downloadHandler).texture; 128 print (string.Format ("Tile {0}x{1} textured", TileOffset.x, TileOffset.y)); 129 } 130 } 131 } 132} 133
###エラーなど
上二つの白枠エクスクラメーションマークのメッセージはよくわかっていません.
二つ目はforbiddenとなっているので,指定しているHTTPが使えなくなっているのでしょうか.
SendWebRequestは使い方が違いているようなのですが,errorで言われていたように置き換えをしただけなのですが,どうして正常に動作しないのでしょうか.
urlの部分は変わらず,どこに使用するのか分からないです.
GoogleMapTile.cs
//message Tile 0x0 requested with center=37.62815,-122.4265&zoom=15&size=640x640&scale=2&maptype=roadmap&format=png&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5&style=element:labels|visibility:off&sensor=false UnityEngine.MonoBehaviour:print(Object) packt.FoodyGO.Mapping.<_RefreshMapTile>d__16:MoveNext() (at Assets/FoodyGo/Scripts/Mapping/GoogleMapTile.cs:113) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) packt.FoodyGO.Mapping.GoogleMapTile:RefreshMapTile() (at Assets/FoodyGo/Scripts/Mapping/GoogleMapTile.cs:75) packt.FoodyGO.Mapping.GoogleMapTile:Start() (at Assets/FoodyGo/Scripts/Mapping/GoogleMapTile.cs:54) Error loading tile 0x0: exception=HTTP/1.1 403 Forbidden UnityEngine.MonoBehaviour:print(Object) packt.FoodyGO.Mapping.<_RefreshMapTile>d__16:MoveNext() (at Assets/FoodyGo/Scripts/Mapping/GoogleMapTile.cs:123) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) //error Assets\FoodyGo\Scripts\Mapping\GoogleMapTile.cs(118,26): error CS0103: The name 'SendWebRequest' does not exist in the current context //warning Assets\FoodyGo\Scripts\Mapping\GoogleMapTile.cs(84,17): warning CS0219: The variable 'url' is assigned but its value is never used