LoginSignup
2
0

More than 5 years have passed since last update.

UnityでGoogle Maps Viewを利用したときの "Unsupported texture format" の対応方法

Last updated at Posted at 2019-02-19

概要

UnityでGoogle Maps Viewを使ってマーカーを差し替える時にUnsupported texture format - Texture2D::EncodeTo functions do not support compressed texture formats. が出てハマったのでメモとして残しておきます。

結論

リソースをインポートした後に
image.png

設定を以下のように変える。
image.png

詳細

Google Maps Viewは、UnityでAndroid/iOSアプリ作る際にGoogleマップを利用するためのAssetです。
導入自体はドキュメントにまとまっているので割愛します。

Googleマップのマーカーをカスタムする際はDrawing Elements on the Mapにあるように.Icon(ImageDescriptor.FromAsset("ファイル名")で変更できます。

// Exampleより
Marker marker = _map.AddMarker(CreateInitialMarkerOptions());

static MarkerOptions CreateInitialMarkerOptions()
{
    const float LondonLatitude = 51.5285582f;
    const float LondonLongitude = -0.2417005f;

    // Create a amrker in London, Great Britain
    return new MarkerOptions()
        .Position(new LatLng(LondonLatitude, LondonLongitude))
        .Icon(ImageDescriptor.FromAsset("map-marker-icon.png")) // image must be in StreamingAssets folder!
        .Alpha(0.5f) // make semi-transparent image
        .Anchor(0.5f, 1f) // anchor point of the image
        .InfoWindowAnchor(0.5f, 1f)
        .Draggable(true)
        .Flat(false)
        .Rotation(30f) // Rotate marker a bit
        .Snippet("Snippet Text")
        .Title("Title Text")
        .Visible(true)
        .ZIndex(1f);
}

ImageDescriptorFromAsset()の他にFromTexture2D()というメソッドがあり今回はそちらを使いました。

利用したいリソースをインポートした後
image.png

// インポートしたリソースを設定する
public Texture2D icon;

Marker marker = _map.AddMarker(CreateInitialMarkerOptions());

static MarkerOptions CreateInitialMarkerOptions()
{
    const float LondonLatitude = 51.5285582f;
    const float LondonLongitude = -0.2417005f;

    // Create a amrker in London, Great Britain
    return new MarkerOptions()
        .Position(new LatLng(LondonLatitude, LondonLongitude))
        .Icon(ImageDescriptor.FromTexture2D(icon)) // ←ここをFromAsset()からFromTexture2D()に変更
        .Alpha(0.5f) // make semi-transparent image
        .Anchor(0.5f, 1f) // anchor point of the image
        .InfoWindowAnchor(0.5f, 1f)
        .Draggable(true)
        .Flat(false)
        .Rotation(30f) // Rotate marker a bit
        .Snippet("Snippet Text")
        .Title("Title Text")
        .Visible(true)
        .ZIndex(1f);
}

このままAndroidで実行するとマーカーが表示されません。
Logcatを見ると以下のログが出ていました。

2019-02-19 12:39:41.933 17365-17381/com.sample.sampleApp E/Unity: Unsupported texture format - Texture2D::EncodeTo functions do not support compressed texture formats.
    UnityEngine.ImageConversion:EncodeToPNG()

対応していないCompressionの設定だったみたいなので、結論に書いたように変更したところ表示されるようになりました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0