2020年11月09日

[Unity] VFX(Visual Effect Graph)を勉強する 〜Unity2020での導入〜

Unityで格好良いエフェクトを作れるというVFX Graph(Visual Effect Graph)を、VFX Graphの知識ゼロの状態から勉強していく過程を残していきます。



既存のパーティクルとの違いは?


エフェクトと言えば既にパーティクルがあるのですが、違いを調べてみると大きな違いはこんな感じ。

・パーティクル = CPUで実現(モバイルでたくさん描けないけど、どの機種でも表現できる)
・VFX Graph = GPUで実現(モバイルでたくさん描けるけど、機種によって対応していない)
※ググれば詳しい情報がヒットします
※スマホアプリで使うことを前提にしています



なぜVFX Graphか?


対応機種が増えてくるだろうし、これから多用されそうな気がするから。



導入してみる


@Unityをインストール
どうせなら現時点で新しいUnityを使おうということで、Unity2020をインストール。
スクショは「2020.1.12f1」ですが、実際に使っているのは「2020.1.9」。

20201108_1.png

Aプロジェクトを新規作成
将来的には、VFXを愚痴フリーで使いたいので、プロジェクトを新規作成するときは「2D」を選択。

20201108_2.png

BVisual Effect Graphをインストール
Window > Package Manager から、Visual Effect Graph を選んでインストール。
画面右に「Samples」とあるけど、VFXのサンプルをインポートすることが出来た(今回は無視)。

20201108_3.png

C早速VFX Graphを作ってみる
Projectウィンドウで右クリック > Create > Visual Effects > Visual Effect Graph を選択。

20201108_4.png

すると、「New VFX」というオブジェクトができます。

20201108_5.png

「New VFX」オブジェクトをHierarchyウィンドウにドラッグ&ドロップします。

20201108_6.png

すると、SceneウィンドウにVFXが表示されました。

20201108_7.png

DVFX Graphを確認する
Hierarchyウィンドウで「New VFX」を選択すると、Inspectorウィンドウに詳しい情報が表示されます。
その中の「Visual Effect > Edit」ボタンを押します。

20201108_8.png

すると、VFX Graphの中身が確認できるウィンドウが出現します。

20201108_9.png

基本的な使い方は、こちらの動画で紹介されています。




基本の4要素


VFX Graphで重要なのは、軸となる4要素です。
スクショでは上から順に

・Spawn = いくつパーティクルを生み出す
・Initialize Particle = どういう風にパーティクルを生み出す
・Update Particle = パーティクルを動かす
・Output Particle XXXX ※XXXX が何種類かある = パーティクルの見た目

となっています。
次回からは、このVFX Graphの使い方についてもう少し掘り下げていってみます。
posted by be-style at 22:09| Comment(0) | Unity

2020年09月20日

[iOS] Xcode12.0で「building for iOS Simulator, but linking in object file ... for architecture arm64」エラーの対処法

Xcode12.0にバージョンアップして作業していたところ、ビルドが実機では通るのにシミュレーターに切り替えたらエラーになる事があったので解決方法をメモ。

FIrebaseのSDKがひっかかった。
--------------------------------------------
ld: in /Users/[ユーザー名]/[プロジェクト名)/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_e321ed8e3db06efc9803f6c008e67a34.o), building for iOS Simulator, but linking in object file (/Users/[ユーザー名]/[プロジェクト名)/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_e321ed8e3db06efc9803f6c008e67a34.o)) built for iOS, file '/Users/[ユーザー名]/[プロジェクト名)/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
--------------------------------------------

TARGET > Build Settings > Excluded Architectures
の Debug と Release のに「Any iOS Simulator SDK > arm64」を追記することで、シミュレーターでもビルドが通った。

スクリーンショット 2020-09-20 12.51.09.png

参考:
https://stackoverflow.com/questions/63607158/xcode-12-building-for-ios-simulator-but-linking-in-object-file-built-for-ios
posted by be-style at 12:59| Comment(0) | iOS

2020年08月14日

[Unity] Unity2019.4のエディタで動くのにAndroidの実機でDynamoDB(AWS Mobile SDK for Unity)が動かないときの対処

Unity2017で作ったアプリをUnity2019で更新した時の話。エディタでは動くのにAndroidの実機でDynamoDBの関数を実行しようとしたら動かないことがあったのでメモ。

OS : macOS Catalina(10.15.4)
使用環境 : Unity2019.4.0f1

事の発端は、DynamoDBの関数を呼ぶところで謎のエラーが出たところから。
------------------------
ArgumentException: Object of type 'System.Object[]' cannot be converted to type 
'UnityEngine.AndroidJavaObject[]'.
at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder,
System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr)
[0x00000] in <00000000000000000000000000000000>:0
at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder,
System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo
culture, System.Reflection.BindingFlags invokeAttr) [0x00000] in
<00000000000000000000000000000000>:0
------------------------

調べてみたら、AWSの公式プラグインではUnity2019には対応していないらしい。
参考: https://qiita.com/kosuke1113/items/904df92d444804d496c3

できるだけ簡単な対処方法を探していたところ、良いページを発見。
https://lhkmarcus.com/2020/04/05/how-to-use-aws-sdk-in-unity-2019/

このページを参考に、自分がやった事は以下の通り。

@link.xmlを確認。(変更なし)
実際に使ったlink.xmlはこの通り。

------------------------
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.Networking.UnityWebRequest" preserve="all" />
<type fullname="UnityEngine.Networking.UploadHandlerRaw" preserve="all" />
<type fullname="UnityEngine.Networking.UploadHandler" preserve="all" />
<type fullname="UnityEngine.Networking.DownloadHandler" preserve="all" />
<type fullname="UnityEngine.Networking.DownloadHandlerBuffer" preserve="all" />
</assembly>
<assembly fullname="mscorlib">
<namespace fullname="System.Security.Cryptography" preserve="all"/>
</assembly>
<assembly fullname="System">
<namespace fullname="System.Security.Cryptography" preserve="all"/>
<namespace fullname="System.ComponentModel" preserve="all" />
</assembly>
<assembly fullname="System.Configuration">
<namespace fullname="System.Configuration" preserve="all" />
</assembly>
<assembly fullname="AWSSDK.Core" preserve="all">
<namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
</assembly>
<assembly fullname="AWSSDK.DynamoDBv2" preserve="all"/>
<assembly fullname="AWSSDK.CognitoIdentity" preserve="all"/>
<assembly fullname="AWSSDK.CognitoIdentityProvider" preserve="all"/>
<assembly fullname="AWSSDK.SecurityToken" preserve="all"/>
</linker>
------------------------

AAWS for Unityのプラグインをダウンロード&インポート。
ダウンロード元: ※2020年8月13日現在 = aws-sdk-unity_3.3.796.0
https://docs.aws.amazon.com/ja_jp/mobile/sdkforunity/developerguide/setup-unity.html

zipファイルを解凍すると、各サービス用のUnityパッケージがあるので、その中の
「AWSSDK.DynamoDBv2.3.3.106.45.unitypackage」
をWクリックして、Unityプロジェクトにインポートする。

BAssets/Plugins/Android/AndroidManifest.xml を修正。
------------------------
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="@string/app_name">
 ↓赤い箇所を削除
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="@string/app_name">
------------------------

CUnity2019用に修正されたSDKをダウンロード&解凍して、既存ライブラリを上書き。
このページにある「3.Download the fixed SDK here」から、Unity2019用に修正されたSDKをダウンロードする。
解凍すると、各サービス用にUnityパッケージがあるので、必要な分を選んで上書きする。
自分の場合は、link.xmlに記載されてあったサービスのを選んだ。

001.png

上書きされるのは、Unityプロジェクト内のAssets/AWSSDK にあるライブラリ。

002.png

これでビルドして実行したら、Androidの実機で無事DynamoDBが動作した!
本当にありがたい。

こうなるとUnity2020は、怖くて使えないなー。
posted by be-style at 00:45| Comment(0) | Unity

2020年08月12日

[Unity] Androidプラグインにおける依存関係の解決と重複クラスの解消方法

------ 後日談 ------
ビルドエラーはなくなったものの、AdMob広告が表示されなかったりGooglePlayServiceが動かなかったり、問題は残っています。
本ページの内容が何かしらのヒントになれば幸いです。
---------------------

UnityのAndroid用ビルドするとき、いつもプラグインにおける依存関係で問題があったりクラス宣言が重複したりとかで困っていたので、対処方法をメモ。


AdMobのプラグイン(2020年8月11日現在 v5.3.0)
https://github.com/googleads/googleads-mobile-unity/releases/tag/v5.3.0

Google Play Serviceのプラグイン(2020年8月11日現在 v0.10.09)
https://github.com/playgameservices/play-games-plugin-for-unity/releases

まずはビルドのエラーメッセージ。

001.png

Google Play Serviceにおけるクラス宣言の重複があるというエラー(たくさん表示される中から一部を抜粋)
---------------------------------------------
Duplicate class com.google.android.gms.common.data.DataBufferObserver found in modules classes.jar (:com.google.android.gms.play-services-base-17.1.0:) and classes.jar (:play-services-base-9.4.0:)
---------------------------------------------

これからUnityの機能を使って依存関係を解決するんだけど、ビルド時に自動でjarファイルを追加されないように設定しておく。

Assets > External Dependency Manager > Android Resolver > Settings

002.png

上から3つ目の「Enable Resolution On Build」のチェックを外す。そうしないと、この後の操作で消したはずのjarファイルがビルド時に復活してビルドエラーになる。

003.png

準備ができたところで、Project内を確認してみると、Assets > Plugins の中にたくさんのjarファイルがあって、この中のいくつかでクラス宣言が重複していたりするらしい。

004.png

なので、依存関係を解決してみる。
Assets > External Dependency Manager > Android Resolver > Resolve

005.png

うまくいくとこんなメッセージが表示される。

006.png

この状態でビルドしてもエラーになる。
なので、依存関係を解決したjarファイル(ライブラリ)を削除する。
Assets > External Dependency Manager > Android Resolver > Delete resolved Libraries

007.png

すると、たくさんあったプロジェクト内のjarファイルのいくつかが削除された。

008.png

これで終わったと思いきや、まだビルドエラーが出る。
今度はAdMobにおけるクラス宣言の重複らしい。

---------------------------------------------
Duplicate class com.google.unity.ads.RewardBasedVideo$2 found in modules classes.jar (:googlemobileads-unity:) and unity-plugin-library.jar (unity-plugin-library.jar)
---------------------------------------------

プロジェクトで、エラーメッセージにあった「googlemobileads-unity」で検索をかけてみると、Inspector画面の「Select platforms for plugin」にてAndroidにチェックが入っていたので、このライブラリではAndroid用に使用しないようにチェックを外し、Applyを押して更新する。

これでビルドが通った。
Unityってこんなに便利になってたんだ、と驚きました。
posted by be-style at 16:09| Comment(0) | Unity

[Unity] AndroidManifest.xml is missing. の対処法

UnityのAndroid用ビルドをしようとして、AdMobのエラーが出たときの対処法をメモで残しておく。

Unity用のAdMobSDKのパッケージ  ※Ver. 5.3.0 = 2020年8月12日現在
https://developers.google.com/admob/unity/start?hl=ja

エラーメッセージ:
-------------------------------------
BuildMethodException: [GoogleMobileAds] AndroidManifest.xml is missing. Try re-importing the plugin.
ManifestProcessor.StopBuildWithMessage (System.String message) (at Assets/GoogleMobileAds/Editor/ManifestProcessor.cs:175)
ManifestProcessor.OnPreprocessBuild (UnityEditor.Build.Reporting.BuildReport report) (at Assets/GoogleMobileAds/Editor/ManifestProcessor.cs:52)
UnityEditor.Build.BuildPipelineInterfaces+<>c__DisplayClass15_0.b__1 (UnityEditor.Build.IPreprocessBuildWithReport bpp) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:411)
UnityEditor.Build.BuildPipelineInterfaces.InvokeCallbackInterfacesPair[T1,T2] (System.Collections.Generic.List`1[T] oneInterfaces, System.Action`1[T] invocationOne, System.Collections.Generic.List`1[T] twoInterfaces, System.Action`1[T] invocationTwo, System.Boolean exitOnFailure) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:391)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)
-------------------------------------

「AndroidManifest.xml 」が見つからないということで、パスが誤っているらしい。

Assets > GoogleMobileAds > ManifestProcessor.cs
を開き、40行目あたりにある赤い部分を削除する。

-------------------------------------
string manifestPath = Path.Combine(Application.dataPath, "Plugins/Android/GoogleMobileAdsPlugin.androidlib/AndroidManifest.xml");

string manifestPath = Path.Combine(Application.dataPath, "Plugins/Android/GoogleMobileAdsPlugin/AndroidManifest.xml");
-------------------------------------

これでビルドが通った。
公式のプラグインに誤りがあるなんて!

参考:
https://stackoverflow.com/questions/57920250/androidmanifest-xml-is-missing-try-reimporting-the-plugin
posted by be-style at 14:57| Comment(0) | Unity