質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
URL

URL(ユニフォームリソースロケータ)とは、インターネット上のリソース(Webページや電子メールの宛先等)を特定するための形式的な記号の並びの事を言う。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

AR(Augmented Reality)

AR(Augmented Reality)とは、拡張現実のことです。人が認識する現実の環境で視覚・聴覚などの知覚が感知する情報をコンピュータで拡張する技術、もしくはその環境そのものを表す言葉です。

Q&A

1回答

1408閲覧

タイル状に地図が表示できない

grape_ll

総合スコア83

URL

URL(ユニフォームリソースロケータ)とは、インターネット上のリソース(Webページや電子メールの宛先等)を特定するための形式的な記号の並びの事を言う。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

AR(Augmented Reality)

AR(Augmented Reality)とは、拡張現実のことです。人が認識する現実の環境で視覚・聴覚などの知覚が感知する情報をコンピュータで拡張する技術、もしくはその環境そのものを表す言葉です。

0グッド

0クリップ

投稿2021/05/24 15:02

編集2021/05/27 13:15

「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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fiveHundred

2021/05/25 02:26 編集

提示のメッセージは上から順に - urlという『変数』は一度も使われていない - UnityWebRequest.Send()は非推奨になったので、代わりにSendWebRequestを使ってくれ - WWWは非推奨になったので、代わりにUnityWebRequestを使ってくれ - 同上 - 改行コードが混在している と、「urlが古い」という結論には到底思えないものですが、なぜそのように判断したのでしょうか?
grape_ll

2021/05/25 04:42

きちんとエラーコードを読まずに,urlと見かけて勝手な想像で質問してしまいました.訂正してきます. ご指摘ありがとうございます.
kaina

2021/05/25 04:50

>きちんとエラーコードを読まずに,urlと見かけて勝手な想像で質問してしまいました. まずきちんとエラーコードを読んで自分で調べて、それでも分からなければ質問するという やり方に変えるという発想はありませんか? あなたが働き始めてプログラムを作成することになり、エラーが出るたびに同じやり方を 繰り返したらどのようになるか想像して下さい。
grape_ll

2021/05/25 05:00

それが一番だというのはもっともです. 以後心がけようと思います.
grape_ll

2021/05/27 13:17

マニュアルに目を通し,メッセージ,警告,エラーの区別は把握いたしました. ありがとうございます. エラーなどを修正するための具体的な案などはございますでしょうか. 宜しくお願いいたします.
guest

回答1

0

結論

結論から言うと、最初のエラーメッセージを見て、'warning'の部分を直そうとしたのが間違いです。
'warning'は無視して、改行コードだけ直すべきでした。
(余裕があれば、ワーニングも直したほうが良いのは当然ですが…)

今すぐ現状のコードを削除して、chapter2のコードを入れ直しましょう。

現状のコードを修正したい場合(オプション)

もしも、現状のコードを直したい場合ですが、その場合、次のような手順で修正すると良いでしょう。

・元のコードで使われているクラスや関数の使い方を調べ、
・置き換える方のクラスや関数の使い方を調べ
・両者の差異を認識し
・単純に置き換えられるかどうか検討する。
(場合によっては、引数が違っていたり、そもそも使い方が根本から変わっていたりするので)
・単純な置き換えで済む場合は置き換える。それが無理な場合は、別の方針を考える。

もちろん、上記の手順は、書いてあるコードをきちんと理解しているのが前提です。
コードを理解できていない場合は理解するところからはじめましょう。

豆知識

Unityのワーニングで'obsolete'と言われた場合、「将来のバージョンのUnityでは使えなくなるよ」という意味なので、最初は気にしなくて良いことが多いです。

投稿2021/06/01 04:29

JunSuzukiJapan

総合スコア310

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

grape_ll

2021/06/01 05:23

確かにエラーの部分から対処すべきでした もう一度最初から考え直してみます.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問