20210514のUnityに関する記事は8件です。

ボタンを長押しでプレイヤーを右に移動

using System.Collections; using System.Collections.Generic; using UnityEngine; public class RightButton : MonoBehaviour { public float speed = 3; bool push = false; public void Update(){ if(push){ Move(); } } public void PushDown(){ push = true; } public void PushUp(){ push = false; } public void Move(){ Vector2 direction = new Vector2 (1.0f, 0).normalized; GetComponent<Rigidbody2D>().velocity = direction * speed; } } ゲームオブジェクトにアタッチ後、ボタンに設置
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Unity IAPとGooglePlayBillingのclassが競合してAndroidがビルドできない問題の対策

こんにちは。もぐめっとです。 実はタキシードを着たことがあります。 だから何?という感じですね。すみません。調子乗りました。 今回は久々にUnityビルドの沼にハマったので解決策を掲示しておきます。 答えを知りたい場合は対策まで飛んじゃってください。 エラー内容 アプリ内課金(In App Purchase)を導入したく、下記のドキュメントを見て導入をすすめてました。 しかし、Unity IAPとplay-unity-pluginsを導入した状態でAndroid用にビルドすると、ひたすらにduplicateなエラーが出力されます。 Execution failed for task ':launcher:checkReleaseDuplicateClasses'. > 1 exception was raised by workers: java.lang.RuntimeException: Duplicate class com.android.billingclient.BuildConfig found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.AccountIdentifiers found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.AcknowledgePurchaseParams found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.AcknowledgePurchaseParams$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.AcknowledgePurchaseResponseListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClient found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClient$BillingResponseCode found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClient$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClient$FeatureType found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClient$SkuType found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClientImpl found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingClientStateListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingFlowParams found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingFlowParams$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingFlowParams$ProrationMode found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingResult found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.BillingResult$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.ConsumeParams found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.ConsumeParams$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.ConsumeResponseListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.PriceChangeConfirmationListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.PriceChangeFlowParams found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.PriceChangeFlowParams$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.ProxyBillingActivity found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.Purchase found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.Purchase$PurchaseState found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.Purchase$PurchasesResult found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.PurchaseHistoryRecord found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.PurchaseHistoryResponseListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.PurchasesUpdatedListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.SkuDetails found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.SkuDetailsParams found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.SkuDetailsParams$Builder found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.SkuDetailsResponseListener found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zza found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzaa found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzab found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzac found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzad found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzae found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzaf found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzag found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzah found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzai found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzaj found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzak found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzal found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzam found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzan found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzao found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzap found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzaq found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzar found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzas found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzat found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzb found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzc found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzd found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zze found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzf found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzg found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzh found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzi found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzj found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzk found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzl found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzm found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzn found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzo found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzp found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzq found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzr found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzs found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzt found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzu found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzv found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzw found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzx found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzy found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.android.billingclient.api.zzz found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zza found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zzb found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zzc found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zzd found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zze found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zzf found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) Duplicate class com.google.android.gms.internal.play_billing.zzg found in modules jetified-GooglePlayBilling-runtime.jar (:GooglePlayBilling:) and jetified-billing-3.0.3-runtime.jar (:billing-3.0.3:) こいつのおかげでandroidがビルドできません。 原因 googleのドキュメントはUnity IAPを手動でいれた前提で進めているのですが、最近はUnityPackageManagerを導入していれる手順になっております。 UnityPackageManagerでいれると ./Library/PackageCacheのファイルを参照してビルドするのですが、この中にあるbilling-3.0.3.aarを抹消してもビルド時にしつこく復活してしまい、結果競合が起こってました。 ビルド後のファイルの様子 $ find . | grep billing-3 ./Temp/StagingArea/aar/billing-3.0.3.aar ./Temp/gradleOut/unityLibrary/libs/billing-3.0.3.aar ./Library/PackageCache/com.unity.purchasing@3.1.0/Plugins/UnityPurchasing/Android/billing-3.0.3.aar.meta ./Library/PackageCache/com.unity.purchasing@3.1.0/Plugins/UnityPurchasing/Android/billing-3.0.3.aar 対策 ちなみにissueにも上がっておりますが、Googleの言うことはきくな!GooglePlayBillingは消せ!と言ってる人がいました。 しかし見ず知らずの意見を聞くのも微妙なので、頑張りました。 結果、Library/PackageCacheの中身をPackagesにコピーしてくることで解決しました! 手順は下記を実施するだけです! $ cp -r ./Library/PackageCache/com.unity.purchasing@* ./Packages $ rm com.unity.purchasing@3.1.0/Plugins/UnityPurchasing/Android/billing-* この状態でビルドすると、PackageManagerがレポジトリからではなくローカルの方を参照するようになります。 Packages/packages-lock.json ... "com.unity.purchasing": { - "version": "3.1.0", + "version": "file:com.unity.purchasing@3.1.0", "depth": 0, - "source": "registry", + "source": "embedded", "dependencies": { "com.unity.ugui": "1.0.0", "com.unity.modules.unityanalytics": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", "com.unity.modules.androidjni": "1.0.0" + } - }, - "url": "https://packages.unity.com" ... これでduplicateな悩みからはさよならバイバイ! ※ただし、更新とかは手動でやらないといけなくなるので要注意です。 まとめ Library/PackageCache/com.unity.purchasing@*を./Packagesにコピってくれば解決! UnityIAP側がGooglePlayBillingをフォローしてくれれば一番いいんですけどね。。悔やまれます。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Unity】画面回転を禁止して方向を固定する方法

Edit → Project Serrings Player → iOSタブ(Androidタブでも可) → Resolution and Presentation → Default Orientation ※Default Orientationについての解説 Default Orientationは起動時の画面回転方向を決める項目です。iOSまたはAndroidのどちらかにある項目で設定を行えば、もう一つの設定も同一のものが適応されます。 それぞれのパラメーター設定は以下のような意味があります。 Portrait:縦向き PortraitUpsideDown:縦向きの逆方向 LandscapeLeft:左へ傾けた向き 縦向きから反時計回り LandscapeRight:右へ傾けた向き 縦向きから時計回り AutoRotation:使用可能な向きの中で、必要に応じて自動で向きを変更 単純に一方向で固定したい場合は「Portrait」や横方向の「LandscapeLeft(LandscapeRight)」を使って固定すれば目的は達成できると思います。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

モデル内の複数のマテリアルのレンダリング順序

今回の主な話題:モデル内の複数のマテリアルのレンダリング順序、SpriteRenderer画面充填の実現、iOSでLogをエクスポートする方法、Shaderの読み込みエラー、Unity 2018.3.7の開発中、一部のデバイスでモデルは表示できません。 モデル Q1: 1つのモデルに、2つのデフォルトのマテリアルがあります。このとき、コードを使用してマテリアルを強制的に追加すると、Unityは元のマテリアルにある前のマテリアルのMeshをコピーして新しいマテリアルのMeshにします。 ですから2つ問題があります。 1)ShaderにMeshを指定する可能性ありますか? 2)元マテリアルの位置を変更しても効果が正しく表示する方法ありませんか? つまり、下図にある2つのShaderの位置をお互いに変更させ、そして効果を正しく表示します。 一つ目のマテリアルはカラーテクスチャマテリアルで、二つ目のマテリアルは特殊効果ウェーブマテリアルです。 MeshにSubmeshがない場合、複数のShaderが複数回レンダリングされ、使用されるオブジェクトは現在のMeshです。Submeshがある場合、エディターモードではデフォルトでShaderの数を増やすことはできません。コードの使用を介して行けるかどうかがわかりませんが、コードで追加できながらにMeshを識別できないことは、少し不思議と感じます。 順序について、RenderQueueが同じ場合、不透明と透明の順序が異なります。マテリアルの多いMeshのマテリアルレンダリング順序も異なるようです。(RenderQueueは半透明キューに設定されていますが、ZTestとZWriteは依然としてオンになっていることに注意してください。) ですから、2つのShaderのレンダリング順序を制御したい場合、ShaderのRenderQueueを調整すれば良いです。大きい方を後に置きます。 最後に、UnityからのWarningに注意してください。 複数のPassで最適化できます。または、1つのPassの中にマクロスイッチで制御することもできます。(もちろん、マクロスイッチが多すぎるために発生する変体数の問題に注意してください。) レンダリング Q2: 3DシーンにあるSpriteRendererは全画面で表示できますか?直交カメラを使ってこの背景画像を撮ります。この背景画像はシーンに配置されていますが、アダプティブに全画面を充填する方法はありませんか? アダプティブには2種類があります。1つは引き伸ばされる(画像が変形する)、もう1つは引き伸ばされない(画像がトリミングされる)です。 コンパイル Q3: iOSでLogをエクスポートする方法は?私たちのLogはApplication.persistentDataPathの下に書いてありますが、iPhoneでこのファイルを見つけるにはどうすればよいですか? この記事を参照することをお勧めします: 「Unity3D研究室ーーAndroid adbと同じくらい便利さ!WindowsでiOSのLogを確認する」(中国語注意) このツールを使用しています。WindowsでiOS Logをチェックすることが非常に便利です。 Shader Q4: LowPolyWaterv2プラグインを使用しましたが、その中のShaderの1つがシーンで水面効果を作成し、次の問題が発生しました。 1)このShaderが独立のAssetBundleにパッケージ化されていない場合、シーンをロードする後に水面が正常に表示されます。 2)このShaderが独立のAssetBundleにパッケージ化されている場合、シーンをロードする後に水面が異常に表示され、そしてShaderの失いではありません。 Shaderが独立のAssetBundleにパッケージするかどうかがロジックに影響ありますか? 主な違いは、Shader変体に対するコレクションにあります。独立にShaderをパッケージすると、手動で変体を選択する必要があり、Unity自動収集を使用すれば損失が発生します。 モデル Q5: プロジェクトに1つのモデルを使用しました、バージョンはUnity 2018.3.7であります。リリース後にHUAWEIのP30、mate10などの設備で正常に表示できません。その後のテストでモデル法線を変更することや再バインドすることを試しても解決できませんでした。これまで多くの方案をやってみたことの上、以下のルールが見つかりました。 使用されたマテリアルはStandard(Specular setup)であります。 1)モデルはバインドされている状況で独立にインポートすると、正常に表示できます。 2)モデルがバインドされた後、正常に表示できなくなります。 3)バインディングモデルがUnityにインポートされた後、InspectorインターフェイスのModelページにあるNormalsをNoneに選択すると、モデル全体の輪郭が表示できます。 4)バインディングモデルがUnityにインポートされた後、InspectorインターフェイスのModelページにあるNormalsをImportまたはCalculateに選択すると、正常に表示できません。 5)Unityのエクスポート設定を次のように設定します。 Player Settings → Resolution and PresentationにあるUse 32-bit Display buffer* と Disble Depth and Stencil*を全部チェックしますともチェックしませんとも、正常に表示できません。 6)マテリアルを変更しても正常に表示できません。 7)以前のバージョンにします。Unity 5.2.3で試してみましたが、表示されたモデルはすべて黒で、テクスチャ効果はなく、マテリアル自体によって与えられた色は表示されません。(これは一番良い状況ですが、表示はまだ異常です。) 一時的にこの問題を解決しましたが、具体的な原因はまだ明確ではありません。 モデルについて、 1)問題のあるモデルに対して、スキニング前にモデルの回転に1つのキーフレームを設置します。 2)問題のあるモデルに対して、スキニング前のモデルの回転にゼロ以外のデータがあります。 設置について、 Unity2018.3.7f1、デフォルトでパッケージするときにGPU Skinningをチェックしました。 一時的な解決策: UnityでGPU Skinningのチェックを外します。 現在の推測: Huaweiが使用するMali-G7XのGPUがこのようなモデルを計算する時に、最初に初期bound poseを計算する時にエラーが発生しました、モデルスキニングの回転情報が計算されていなかったようです。 残った疑問: 3Dソフトウェアでモデルのスキニングを解除し、モデルのすべての情報をクリアしてから、アニメーションのバインディングを実行し、問題がまだあります。この問題はどちらにあるのが一時的にわかりません。後で見つけたら再び更新しましょう。 UWA Technologyは、モバイル/VRなど様々なゲーム開発者向け、パフォーマンス分析と最適化ソリューション及びコンサルティングサービスを提供している会社でございます。 UWA公式サイト:https://jp.uwa4d.com UWA公式ブログ:https://blog.jp.uwa4d.com
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Unity PDF Rendererのサンプルをしてみた

環境構築 PDF RendererのUnityPackage Unity 5.3.8 以上(この記事で2019バージョン使います) メイン特徴 PDF RendererをUnityプロジェクトに入れたら「PDFViewer」Prefabオブジェクトを開く。「PDFViewer」オブジェクトを検索したら、「Load Settings」の下に「File Source」選択ぼたんがあります。その選択でPDFファイルを取るため、複数な方法があります。まずは各方法をまとめています。 各方法を例のフォルダーで試します。 Web URL方法 まずはWeb URLの方法です。例のフォルダー、「Examples」を開いて、PDFViewer_Webの例を開く。「File Source」の下に、URLを入力します。この記事で400以上ページの本を表示試します。 そのPDFのリンクはこちらへ Model-driven Software Development ページを沢山があればローディングパネルを表示されます。ローディングが終わったら、PDFファイルを普通に表示されます。 Streaming Assets方法 次の方法はStreaming AssetsでPDFファイルを取ります。「Examples」でPDFViewer_StreamingAssetsの例wp開く。そのまえに「Assets」フォルダで新しいフォルダー、「StreamingAssets」を作成してください。作成したら、自分のPDFファイルを「StreamingAssets」フォルダーに入れます。そのしたら、「Load Settings」のしたに、PDFファイル名を「File Name」入力に入れてください。忘れずに、ファイルのエクステンション、「*.pdf」をつけてください。もし、PDFファイルは「StreamingAssets」のサブフォルダーでいるなら、「Load Settings」の「Folder」に入れてください。 Resources方法 Streaming Assets方法のように、Resourcesフォルダーからファイルを開く。違いが、ファイルのエクステンションに「*.pdf」の後「.bytes」をつけてください。「Load Settings」のしたに「File Name」に入れます。 File Path方法 File Path方法で、ファイルの位置をいれば完成です。「Browse」ボタンでも、ファイルの検索ができます。 Persistent Data方法 Persistent Dataの方法はStreaming Assetsの方法とResources方法のように、ファイルを「Persistent Data」フォルダーに入れてください。Unityの「Persistent Data」フォルダーの位置はこの方法で確認できます。 Debug.log(Application.persistentDataPath); 普段はこの場所である Windows → C:/Users/<ユーザー名>/AppData/LocalLow/<会社名>/<アプリ名> Android → /storage/emulated/0/Android/data/<アプリ名>/files iOS → /var/mobile/Containers/Data/Application//Documents 参考 https://docs.unity3d.com/ja/current/ScriptReference/Application-dataPath.html https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html Assets方法 Assets方法を使うため、PDFファイルにAssetファイルに変換が必要です。変換方法は、Unityで選択したファイルに右クリックして、「PDF Renderer → Convert to .assets」をします。そのあと、変換されたファイルをPDF Assetに入れます。 Bytes方法 最後はPDFViewer_Bytesの例を開きます。PDFViewerのオブジェクト検査したら、「PDFBytesSupplierExample.cs」でPDFファイルを取る。このPDFBytesSupplierExampleはbyte arrayとして、PDF内容を保存しています。Supplier Function入力にPDFBytesSupplierExample.csからのリターンされたbyte arrayを入れます。入れたbyte arrayをPDFに変換して、表示します。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Rigidbodyに関する問題の備忘録

環境 Unity 2020.3.2f1 問題の件 RigidbodyにFreeze Positionを設定したGameObjectに別のGameObjectをぶつけると、その方向に反発しない? 参考画像 下のCubeのFreeze Positionをy=0にしている するとCubeの反発もy軸方向が消えている 対策 どちらかにRigidbodyを設定しない、反発してほしい方向にFreeze Positionを設定しないなどが考えられる。 終わりに 誰か解決方法を知っている方はコメントお願いします
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Unity・C#】軽量なObjectPoolを作りたい

やりたいこと ObjectPoolingは大量のオブジェクトを扱う際、メモリ割り当てをしないように一度生成したオブジェクトを常に使い回すための仕組みです。 しかしObjectPoolは結構再開発されまくってて、目的・用途が様々になってきています。 なので、ここで一旦要件をまとめておきたいと思います。 ・プールされるオブジェクトはGameObjectのComponentである。 ・GameObjectには必ず同じComponentがアタッチされている。 ・プールされるオブジェクトは個体識別しない。 ・プールされるオブジェクトに生成時、破棄時のコールバックが欲しい ・プールはシングルトン ・例外なくちゃんとエラーを吐いてくれる コードはGithubにあげています。 実装 オブジェクトプール プールするための配列はQueue<T>を使用しました。 CreatePool(int)で許容量を設定しつつプールを生成します。 ここで許容量を設定するのは、許容量を超えた際にメモリの再割り当てが発生するのを防ぐためです。 また、普通のQueueとは少し違いプールの許容量を超えたら、再割り当てするかしないかをisFixedで設定することができます。(普通は自動で再割り当てされてしまう) public void CreatePool(int capacity, bool isFixed) { if (m_isActive) { Debug.LogWarning("Poolは既に生成されています!"); return; } if (prefab == null) { Debug.LogError("Prefabがセットされていません!"); return; } m_capacity = capacity; Pool = new Queue<IPoolable<T2>>(capacity); for (int i = 0; i < capacity; i++) { T2 obj = Instantiate(prefab, transform).GetComponent<T2>(); obj.gameObject.SetActive(false); Pool.Enqueue(obj); } m_isActive = true; m_isFixed = isFixed; } Release()でプールからオブジェクトを取り出すことができます。 基本的に余計なことはしないスタンスなので、コールバックを呼び出しオブジェクトを取り出すだけの実装になっています。 ここで例外をキャッチしているのは、Pool.Dequeue()でプールが空の状態の時に例外を発生させるからです。ドキュメントによると、TryDequeue(out T)が使えるらしいのですが、恐らくバージョン的に存在しなかったため例外処理をしています。 public T2 Release() { if (!PoolIsAvailable()) return null; try { IPoolable<T2> obj = Pool.Dequeue(); T2 entity = obj.Entity; entity.gameObject.SetActive(true); obj.OnReleased(); return entity; } catch { Debug.LogError("Release可能なPoolEntityが存在しません!"); return null; } } Catch(T)でコールバックを呼び出し、プールにオブジェクトを返却します。 IsFixedを指定した場合、CanDequeue()で弾かれて追加されるのを防ぎます。 public void Catch(IPoolable<T2> obj) { if (!PoolIsAvailable()) return; if (!CanDequeue()) return; obj.OnCatched(); obj.Entity.gameObject.SetActive(false); Pool.Enqueue(obj); } プールされるオブジェクト プールされるComponentにはIPoolable<T>の実装を強制します。 IPoolable<T>の実装はこのようになっています。 public interface IPoolable<T> where T : MonoBehaviour { T Entity { get; } void OnReleased(); //生成時(取得) void OnCatched(); //破棄時(返却) } EntityはIPoolableを実装するクラスのインスタンスを返させます。 OnReleased(), OnCatched()はそれぞれ生成時、破棄時に呼び出されます。 (キャッチアンドリリースってわかりやすい) 使い方 ObjectPool<継承するクラス, プールするクラス>を継承して、利用することができます。 CreatePool(capacity, isFixed)でプールを作成し、DestroyPool()でプールを丸ごと破棄できます。 public class HogePool : ObjectPool<HogePool, Hoge> { private void Start() { CreatePool(100, true); } } 取得と返却は先ほど言った通り、Release(), Catch(T)でできます。 HogePool.Instance.Release(); HogePool.Instance.Catch(this); //返却するクラスのインタンスを渡す サンプルもリポジトリ内にあるので、活用してみてください。 まとめ ・そんなに多機能でもなく、Queue<T>を使ってるのでパフォーマンス的には問題ないはず、、? ・返却はCatch(IPoolable<T>)でinterfaceを渡している。暗黙的なキャストが発生しているので、ここがネック。 ・Queue<T>を自作クラスでもっと軽量にすれば軽くできるかなと思った。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

UnityからXcodeにしてビルドする関連(2021年5月)

やったこと ・Unityで2Dゲームを制作 ・Admobで広告を表示(iOS) Unityでアプリを作るまでは良かったが、その後が大変だった。 自分の環境 ・MacOS catalina ・Xcode 12.4 ・Unity 2019.2.12f1 Personal ・Google Mobile Ads Unity Plugin v5.4.0 ・CocoaPods 1.10.1 Admob広告を表示させる GoogleMobileAds-v5.4.0.unitypackageをダブルクリックしてすべてチェックが入っていることを確認してimport その他メディエーションしている場合は各種Adaptorをimportした後、iOSリゾルバを設定する。 Unity > Assets > External Dependency Manager > iOS resolver > settings にて、CocoaPodsIntegration のプルダウンから Xcode Project Add CocoaPods to the Xcode Project を選ぶ。 アプリを実装する Unityで作る。Admobのテスト広告が表示されることを確認。 証明書を作る 端末で確認&ストアで公開するために必要 ・AppleDeveloperProgramを購入する。 ・Macのキーチェーンアクセス > 証明書アシスタント > 認証局に証明書を要求 CertificateSigningRequest.certSigningRequestを作る ・Apple Developer > Certificates, Identifiers & Profiles > Certificates からCertificateSigningRequest.certSigningRequestのアップロードし、DeveloperとDistributionの証明書を作る(ios_develop.cer, ios_distribution.cer) ・AppIDを作成する ・provisioning profilesを作成する このとき開発用(developer)と公開用(distribution)を作成する。 開発用provisioning fileは開発用のAppIdとBundleIdを割当て、公開用には公開用のAppIdとBundleIdを割り当てておく。また開発用では実行したい端末を登録する。 Unityから「開発用」にビルド UnityでビルドするとXcodeのプロジェクトが作られ、Xcodeからビルドして端末で実行&公開用のipaファイルを作るという流れ。 なおXcodeのシミュレーターでの実行はしない(というよりUnity自体がシミュレーターである...というよりXcodeシミュレータでの確認はできなかったので諦めた)。 まずは端末でアプリを確認するためにUnityからビルドする。 ・Unity > Fils > BuidSettings にてPlatformをiOSを選択してswitch platformする。 ・GraphicAPIsが足りない状況だとBuildボタンがグレーアウトするので PlayerSettings > Other Settings > GraphicAPI にて OpenGLES2, 3を追加する ・Unity > Preferences > PlayerSettings > iOS > Other Settings にて以下の設定をする  ・iOS provisioning profilesの開発用を設定する  ・profile typeをDevelopmentにする  ・Bundle Identiferを開発用にする  ・TargetSDKをDeviceSDKにする ・Buildボタンを押すと開発用のXcodeのプロジェクトファイルができる Xcodeからビルドして端末で確認 ・Xcodeのプロジェクトファイル(Unity-iPhone.xcodeproj)ができているので、ターミナルで同階層のディレクトリに行ってCocoaPodsを実行する pod install --repo-update ここでエラーになる場合はCocoaPodsを再インストールする(別記事を参考にすべし) ・Xcodeをxcworkspace(Unity-iPhone.xcworkspace)で起動する ・build settingsにて以下の設定をする  ・provisioningfile 開発用のprovisioning fileを選択  ・Deployment teamで開発用を選択 ・端末をつないで実行する 公開用のipaファイルを作成する 開発用と公開用とではprojectファイルから異なってくるのでUnityからビルドをしてXcodeプロジェクト自体を作り直すことになる。 2つディレクトリを作っておき、そこに開発用と公開用で別途Xcodeのprojectを作成するのがスマートかと思う。 先程の開発用として設定した部分をすべて公開用のものを使って Unity〜Xcode〜CocoaPods〜BuildSettingsの設定作業を経て XCode > Product > Archive する。 起こりうるエラーと解決方法 証明書関連のエラー ・Signing for "Unity-iPhone" requires a development team. Select a development team in the Signing & Capabilities editor.(「Unity-iPhone」にサインするには開発チームが必要です。 Signing&Capabilitiesエディターで開発チームを選択します) ・Unity-iPhone has conflicting provisioning settings.(Unity-iPhoneのプロビジョニング設定が競合しています) ・A valid provisioning profile for this executable was not found.(この実行可能ファイルの有効なプロビジョニングプロファイルが見つかりませんでした) 証明書には開発用と公開用があり、UnityからXcodeを生成した場合、Xcode上のbuildsettingで開発用と公開用を切り替える必要はない(というよりできないと思う)。 従って開発用と公開用で別々にXcodeのprojectを吐き出させることになる。 Xcode上で設定するのは BuildSettings > Provisioning File と DeveloperTeamの2点のみ。 開発用と公開用でそれぞれ適したProvisioningFileとDeveloperTeamを設定する。 Admob関連のエラー ・GoogleMobileAds/GoogleMobileAds.h' file not found ・No visible @interface for 'GADRewardedAd' declares the selector 'initWithAdUnitID:' ・No visible @interface for 'GADRewardedAd' declares the selector 'loadRequest:completionHandler:' ・No visible @interface for 'GADRewardedAd' declares the selector 'isReady' 各種frameworkは手動ではなくcocoapodsで入れる。またiOSリゾルバ設定を行って解決する。 ・<Google> Cannot find an ad network adapter with the name(s) メディエーションすると起こりうるエラー。 cocoapodsでのimportとiOSリゾルバを設定して解決する。 余談 今回は以下のことも行っているのでこれらも記事にしたい。 ・CocoaPodsのインストール ・スクロールテキスト ・WebView導入 ・iOS14対応(AppTrackingTransparency導入+SKAdNetwork記述) ・サーバとの通信 ・メディエーション
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む