Apple SiliconのMacが発表され、その性能の高さと省電力性に驚いています。
しかし今まで使っていたものが使えなくなるなどの不便を感じることもあります。
その1つとしてUnityStandaloneFileBrowserがあります。
UnityStandaloneFileBrowserとは
UnityStandaloneFileBrowserは、Unity上でネイティブのファイル選択ダイアログ(Open File/Save File)を使用可能にする外部ライブラリです。
Windows, macOS, Linux各プラットフォームに対応しており、Unity標準のFilePanelのように見えるUIではなく、OSが提供するシステムダイアログをそのまま使用できるため、ユーザーにとって自然で直感的な操作が可能になります。
特にmacOSではFinderライクなUIが利用できるので非常に重宝します。
しかし、Apple Silicon環境でこのライブラリをそのまま利用しようとすると、いくつかの問題が発生します。
Apple Silicon環境で発生する問題
- Unity Editor上でファイルダイアログが開かない
 - Arm64向けのビルドでファイルダイアログが開かない
 
以下がおそらくの原因です。
Apple Silicon環境では、UnityがARMアーキテクチャ(arm64)でビルドされるようになったため、UnityStandaloneFileBrowserに含まれるネイティブプラグイン(macOS用の.bundle)がIntel(x86_64)向けにビルドされている場合、そのままではロードできず、動作しません。
その結果、ファイルダイアログが開かない、などの不具合が発生します。
問題の再現
- 
m4 pro mac mini
 - 
Unity Editor 2021.3.12f1
 - 
UnityStandaloneFileBrowserのREADME部分の
Download Packageをクリックすると、Windows用の.dllやmacOS用の.bundleなどが入ったStandaloneFileBrowser.unitypackageが手に入ります - 
この記事に従い、空のプロジェクトを作成します
 - 
StandaloneFileBrowser.unitypackageを空のプロジェクトにインポートします - 
エラーが出ますが、この記事に従い解消します
 - 
インポートした
StandaloneFileBrowser -> Plugins -> Sampleの中にCanvasSampleSceneがあります - 
Gameを再生し、
Open File - Textボタンをクリックすると、以下のエラーが出てファイルダイアログが表示されません。これが今回解決するエラーですDllNotFoundException: StandaloneFileBrowser assembly:<unknown assembly> type:<unknown type> member:(null) SFB.StandaloneFileBrowserMac.OpenFilePanel (System.String title, System.String directory, SFB.ExtensionFilter[] extensions, System.Boolean multiselect) (at Assets/StandaloneFileBrowser/StandaloneFileBrowserMac.cs:44) SFB.StandaloneFileBrowser.OpenFilePanel (System.String title, System.String directory, SFB.ExtensionFilter[] extensions, System.Boolean multiselect) (at Assets/StandaloneFileBrowser/StandaloneFileBrowser.cs:51) SFB.StandaloneFileBrowser.OpenFilePanel (System.String title, System.String directory, System.String extension, System.Boolean multiselect) (at Assets/StandaloneFileBrowser/StandaloneFileBrowser.cs:39) CanvasSampleOpenFileText.OnClick () (at Assets/StandaloneFileBrowser/Sample/CanvasSampleOpenFileText.cs:41) UnityEngine.Events.InvokableCall.Invoke () (at /Users/bokken/build/output/unity/unity/Runtime/Export/UnityEvent/UnityEvent.cs:178) UnityEngine.Events.UnityEvent.Invoke () (at /Users/bokken/build/output/unity/unity/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_0.cs:58) UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272) UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501) 
解決策
検証環境
- m4 pro mac mini
 - Unity Editor 2021.3.12f1
 - Xcode 16.4
 
手順
以下の手順で、Apple Silicon向けにUnityStandaloneFileBrowserのネイティブコードをビルドし直すことで、問題を解決できます。ほぼGitHub Issue #109 Commentの和訳になります。
- UnityStandaloneFileBrowserをGitHubからcloneする
 - 
Plugins -> MacOS -> StandaloneFileBrowserに行く - 
StandaloneFileBrowser.xcodeprojを右クリックし、「パッケージの内容を表示」を選択します - 中にある
project.pbxprojファイルをXcodeで開きます - 次の行を
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
から
ARCHS = "$(ARCHS_STANDARD)";
へ変更します(二箇所あります) - 以下の行を削除します(二箇所あります)
VALID_ARCHS = x86_64; - ファイルを保存して、Xcodeを閉じます
 - 再び
Plugin -> MacOS -> StandaloneFileBrowserフォルダーに戻ります - StandaloneFileBrowser.xcodeprojをXcodeで開きます
 - メニューの
「Product」>「Build」を実行してビルドを行います - ビルドが成功すると、
StandaloneFileBrowser.bundleファイルが生成されます
※このファイルの場所は、Xcodeの「Product」>「Show Build Folder in Finder」で確認できます。 - 生成された
StandaloneFileBrowser.bundleファイルを、既存のファイルと置き換えます 
まとめ
Apple Silicon Macは大幅なアーキテクチャ変更により、今まで使えていたものが使えなくなるなどがあります。本記事で誰かの助けになれば幸いです。また何か間違いなどありましたら遠慮なくコメントしてください!