前回は、Unityでユーザーインターフェースを作ったところまででしたので、今回はその続きの内容からになります。参考サイト(http://tokyo.supersoftware.co.jp/code/4807)様の内容でいうと、Android用プロジェクトとしてエクスポートするというところからになります。
キャプチャーが貼ってあってそのとおりにしたかったんですが、Unity5以降の画面では、微妙に表示内容が違っていたので、以下のキャプチャーの様にして書き出しました。
古い形式のADT(Legacy)で書き出したら、うまく取り込めました。ちなみにGradleで書き出すと、後述する別の参考サイトの取り込み方で指定されているフォルダ構成にならなかったのであきらめました。尚、Gradleについては、この辺の記事を読めばいいのかな(もっとも自分はまだ読んでないですが [参考]http://gihyo.jp/dev/serial/01/android_studio/0006)。
参考サイトでは、この後サラッとエクスポートしたプロジェクトをAndroidのプロジェクトにインポートしますと書かれていますが、やり方がよく分からなかったので、ここは随分試行錯誤することになりました。Androidに「インポート」って項目があるのでやってみたけど、うまくいかなかったり…。
またまた色々調べて、以下のサイトのやり方に従ってやってみたら、取り込むことが出来ました。
(参考サイト) http://meleap124.blogspot.jp/2015/04/android-studiounity.html
こちらのサイトの指示どおりに従って、手作業で移植すれば動きますね。4のマージは、自分の場合は、Unituロゴアイコンのデータをコピーする程度でした。特に上書きは無かったです。5のマージは、ちょっと注意がいるので、最初の参考サイト(http://tokyo.supersoftware.co.jp/code/4807)の下の方に記載されている、AndroidManifest.xmlの内容に沿ったものになっているか確認しながら移植することになると思います。
私の場合は、以下の様にAndroidStudioが自動で作成したマニュフェストに追加記載しました。また、Unityのユーザーインターフェースは、横向きレイアウトで作成したので、landscape指定を追加でしておきました。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.co.hoge.unity.bluetooth.test">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/UnityThemeSelector"
android:isGame="true">
<activity android:name=".BluetoothTestActivity" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="jp.co.hoge.unity.bluetooth.test.UnityPlayerActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--<category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
<!--</intent-filter>-->
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="26" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
つづく。


コメント