LoginSignup
8

More than 5 years have passed since last update.

[Unity][NCMB]横画面固定なのに縦画面でアプリが起動されてしまうときの対処法

Last updated at Posted at 2016-12-08

横画面固定の設定(PlayerSettingsでAutoRotation, Landscape Right, Landscape Left)であるのに、端末を縦にしてアプリを起動すると、縦画面になってしまうというバグが発生した。

症状

・上記の通り、端末を縦にしてアプリを起動すると、縦画面になってしまう
・縦画面のままゲームを進めるとレイアウトが崩れる
・起動後、すぐに端末を横向きにすれば画面も横になる
・横向きのまま起動すれば縦にはならない

環境

・mac OS Sierra 10.12.1
・Unity 5.4.3f1
・デバッグ端末:DP-X1、Xperia Tablet Z4

原因の特定経緯・対処法

・iOS版では問題ないことから、Android固有の問題である
NCMBを入れるまでは問題なかった

ということから、NCMBプラグインによって入れられたAndroidManifest.xmlがおかしいのではないかと考えた。

同様の症状を調べると、以下のものが該当した。
[Unity][Unity3d] Android で実行した時に設定している以外の向きに回転してしまう問題の解決方法
App starts and then runs in landscape mode (Unity 4.2 - Android)
[Android] Broken device orientation

これらのサイトを参考にした結果、AndroidManifest.xmlで画面の向きを設定すれば良いことが分かった。

よって、NCMBによって入れられたAndroidManifest.xmlの一部を次のように改変した。

AndroidManifest.xml
        <!-- <meta-data android:name="smallIcon" android:resource="@drawable/comment_icon"/> -->
        <!-- UNITY PLAYER ACTIVITIES ( [WARNING] if use Prime31, edit 'com.nifty.cloud.mb.ncmbgcmplugin' to 'com.prime31' at android:name of 3 these activities) -->
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:screenOrientation="sensorLandscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

まず、元のNCMBによるAndroidManifest.xmlにあった

<activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerProxyActivity"

<activity android:name="com.unity3d.player.UnityPlayerActivity"

と改変した。

また、<activity〜内に

android:screenOrientation="sensorLandscape"

を追記した。

以上の方法で対処することができた。

2016.12.13 追記
もしかしたら、Unity5.5で改善されてるかもしれない

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
8