LoginSignup
4
4

More than 5 years have passed since last update.

metaio の Tracking Configuration を外部からロードする

Last updated at Posted at 2015-02-04

Unity で Tracking Configuration (マーカー画像とその設定ファイル) を、アプリに内蔵した StreamingAsset とかからじゃなくって Web サーバーから取ってきて使う方法。

Tracking Configuration をつくる

マーカー画像と設定ファイル (XML) をがっちゃんこした ZIP ファイルをつくる。

Metaio Creator をつかって作るばあい

  1. マーカー画像よみこむ。ウィンドウ下側の Trackable を + 。
  2. Tracking Technology えらぶ。ふつうのマーカーつかう AR なら Image Tracking。くわしくはこちら
  3. 必要あればコンテキストメニュー → Properties で設定。
  4. メニューの Export → Export Tracking Configuration File で ZIP ファイルかきだす。

手動でつくるばあい

Creator では細かい設定ができないので、こっちのがおすすめ。

  1. マーカー画像用意する。
  2. このへん参考にがんばって XML 書く。
  3. まとめて ZIP にかためる。

Web サーバーから読み込む

  1. metaio 初期化されるの待つ。
  2. WWW クラスで ZIP ファイルをダウンロード。
  3. てきとうな場所に保存。
  4. 保存した ZIP ファイルのパスを MetaioSDKUnity.setTrackingConfigurationFromAssets にわたして読み込む。
  5. できた!
metaio/Scripts/metaioCallback.cs
virtual protected void onSDKReady()
{
    StartCoroutine(loadExternalConf("http://example.com/TrackingData.zip"));
}

IEnumerator loadExternalConf(string url)
{
    var www = new WWW(url);
    yield return www;
    string path = Application.persistentDataPath + "/marker.zip";
    Debug.Log("Save downloaded marker to: " + path);
    System.IO.File.WriteAllBytes(path, www.bytes);
    MetaioSDKUnity.setTrackingConfigurationFromAssets(path);
}
4
4
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
4
4