実現したいこと
最近になってunityでライブ壁紙を作れることを知り、検索をかけてこちらのプロジェクトを見つけたのですが、古いunity(2018.3くらいらしい?)向けに書かれたものらしく、私の環境で動かせなかったので、ベースはこのプロジェクトに調べながら変更を加えていくことで新しいunity動かしたいなあと考えています。
しかし、javaに慣れておらずプログラミングの腕もまだまだで、分からないことだらけで手助けを借りたいと思って質問しました。
発生している問題・分からないこと
resフォルダの問題(ここの対応も必要)やUnityPlayerの仕様変更でインスタンス化できない等の問題は無理やりどうにかビルドできる様になったのですが、unityplayeractivityが起動していない為にunityの画面が表示できません…。
unityplayeractivityは他のスクリプトに置き換えており、AndroidManifestもAppを実行しないようにしてあります(上手く動かせなかったため)。
壁紙アプリとして起動するときも、ホーム画面から起動するときも、UnityPlayerActivityがUnityの画面を表示させてくれればいいのですが…。
UnityPlayerActivityがUnityWallpaperServiceから起動したときに動いてません。
元々どうして起動していたのかも分かってないのですが、現在の環境でどう動かせば良いでしょうか?
UnityPlayerActivityの処理もカスタマイズされていたみたいなので、それも書き加えるべきなのかもしれないですが、どこが変更された点なのか、どう直せば良いのかも分かってません。
該当のソースコード
Plugins/Android/AndroidManifest.xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 package="ulw.ulw.ulw" 5 xmlns:tools="http://schemas.android.com/tools"> 6 <application> 7 8 <activity android:name="ulw.ulw.ulw.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false"> 9 <intent-filter> 10 <action android:name="android.intent.action.MAIN" /> 11 <category android:name="android.intent.category.LAUNCHER" /> 12 <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> 13 </intent-filter> 14 <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> 15 </activity> 16 17 <service android:name="ulw.ulw.ulw.UnityWallpaperService" android:label="Unity Live Wallpaper" android:exported="true" android:permission="android.permission.BIND_WALLPAPER"> 18 <intent-filter> 19 <action android:name="android.service.wallpaper.WallpaperService" /> 20 </intent-filter> 21 <meta-data android:name="android.service.wallpaper" android:resource="@xml/wallpaper" /> 22 </service> 23 </application> 24</manifest>
Plugins/Android/App.java
1//変数用に残してありますが、androidmanifestが書き換えられている為関数は恐らく実行されません 2package ulw.ulw.ulw; 3 4import android.app.Application; 5import android.content.Context; 6import android.content.res.Configuration; 7 8import com.unity3d.player.UnityPlayer; 9import ulw.ulw.ulw.UnityPlayerActivity; 10import com.unity3d.player.UnityPlayerForActivityOrService; 11 12public class App extends Application 13{ 14public static UnityPlayerActivity mUnityPlayer; 15 public static boolean PS; 16 public static boolean ACT = false; 17 18 private static App instance; 19 20 public App() { 21 instance = this; 22 } 23//以下略
Plugins/Android/UnityWallpaperService.java
1package ulw.ulw.ulw; 2import android.app.Activity; 3import android.content.Context; 4import android.content.Intent; 5import android.content.res.Configuration; 6import android.service.wallpaper.WallpaperService; 7import android.view.MotionEvent; 8import android.view.Window; 9import ulw.ulw.ulw.App; 10import ulw.ulw.ulw.UnityPlayerActivity; 11import com.unity3d.player.UnityPlayerForActivityOrService; 12 13import android.app.WallpaperManager; 14import android.content.ComponentName; 15public class UnityWallpaperService extends WallpaperService 16{ 17 public void onCreate() { 18 super.onCreate(); 19 20 if (App.mUnityPlayer == null) 21 { 22 //App.mUnityPlayer = new UnityPlayerActivity(); 23 //App.mUnityPlayer.mUnityPlayer = new UnityPlayerForActivityOrService(App.mUnityPlayer, App.mUnityPlayer); 24 //App.mUnityPlayer.setContentView(App.mUnityPlayer.mUnityPlayer.getFrameLayout()); 25 //App.mUnityPlayer.mUnityPlayer.getFrameLayout().requestFocus(); 26 } 27 28 } 29 30 public void onConfigurationChanged(Configuration configuration) { 31 super.onConfigurationChanged(configuration); 32 App.mUnityPlayer.onConfigurationChanged(configuration); 33 } 34 35 public void onDestroy() { 36 super.onDestroy(); 37 } 38 39 public void onLowMemory() { 40 super.onLowMemory(); 41 App.mUnityPlayer.onLowMemory(); 42 } 43 44 public void onTrimMemory(int i) { 45 super.onTrimMemory(i); 46 if (i == 15) { 47 App.mUnityPlayer.onLowMemory(); 48 } 49 } 50 public Engine onCreateEngine() { 51 return new UnityWallpaperEngine(); 52 } 53 54 private class UnityWallpaperEngine extends Engine 55 { 56 57 public void onTouchEvent(MotionEvent motionEvent) { 58 App.mUnityPlayer.mUnityPlayer.injectEvent(motionEvent); 59 } 60 61 public void onVisibilityChanged(boolean z) { 62 super.onVisibilityChanged(z); 63 64 65 if(isPreview() && WallpaperUtility.isULWActive(getApplicationContext())) App.PS = z; 66 67 if (z) { 68 App.mUnityPlayer.onPause(); 69 App.mUnityPlayer.mUnityPlayer.displayChanged(0, getSurfaceHolder().getSurface()); 70 App.mUnityPlayer.onResume(); 71 } 72 else 73 { 74 if(!App.ACT == true) 75 { 76 if(!App.PS) 77 { 78 App.mUnityPlayer.onPause(); 79 } 80 App.PS = false; 81 } 82 } 83 App.mUnityPlayer.onWindowFocusChanged(z); 84 } 85 } 86}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
- ホーム画面から起動→UnityPlayerActivityを直接呼び出している為動作。
- 壁紙設定画面のプレビュー及び壁紙設定されたホーム→UnityWallpaperServiceが実行されるが、UnityPlayerActivityは実行されていない為にUnityPlayerActivityに関連した処理が走る行でアプリが強制終了される
- ホーム画面から起動したタスクを残したまま、上記の画面でプレビューしたり壁紙を設定してみる→意図した画面が表示される
以上の事が分かったので、UnityWallpaperServiceが動いた時点でUnityPlayerActivityが動いていれば動くのかなあと思っています。
ただ検索をかけても、UnityPlayerを直接インスタンスする頃の古い情報しかヒットせず、しかも難しいのでここからどうすればいいか分からず…
補足
文字数制限の都合でこちらにPluginsフォルダごとアップロードしておきました。
新規プロジェクトAssets直下に置き、プロジェクト設定→公開設定→カスタムメインマニフェストにチェックを入れると環境が再現できるはずです。
- リストバージョン:Unity6(6000.0.26f1)

回答1件
あなたの回答
tips
プレビュー