しっぽを追いかけて

ぐるぐるしながら考えています

Unity と猫の話題が中心   掲載内容は個人の私見であり、所属組織の見解ではありません

Unity 5.3.2f1 の UWP で Windows Phone の戻るボタンが効かない?

いつからこうだったのかわかりませんが、Unity で UWP アプリを作ると Windows Phone の戻るボタンがフックされて効かなくなるようです

f:id:matatabi_ux:20160322155256g:plain

これは審査で不合格になるかもしれないので、Unity の公式ページで報告しておきました

とりあえず一時的な対応としては戻るボタンの動作を上書きすることくらいかもしれません

Unity で出力した UWP プロジェクトの中の App.xaml.cs の OnLaunched を書き換えて、1つイベントハンドラを追加します

/// <summary>
/// Invoked when the application is launched normally by the end user.  Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    splashScreen = args.SplashScreen;

    // 追加する
    SystemNavigationManager.GetForCurrentView().BackRequested += this.OnBackRequested;

    InitializeUnity(args.Arguments);
}

/// <summary>
/// 戻るボタン押下イベントハンドラ
/// </summary>
/// <param name="sender">イベント発行者</param>
/// <param name="e">イベント引数</param>
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
    Application.Current.Exit();
}

こんな感じに戻るボタンが押されたらアプリ終了・・・厳密にはこれだと元通りではないので、Unity 側のフックをやめないといけないですがとりあえずならこれでリリースはできるかも?

f:id:matatabi_ux:20160322160206g:plain

対応後はこんな感じ