1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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の和訳になります。

  1. UnityStandaloneFileBrowserをGitHubからcloneする
  2. Plugins -> MacOS -> StandaloneFileBrowserに行く
  3. StandaloneFileBrowser.xcodeprojを右クリックし、「パッケージの内容を表示」を選択します
  4. 中にあるproject.pbxprojファイルをXcodeで開きます
  5. 次の行を
    ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
    から
    ARCHS = "$(ARCHS_STANDARD)";
    へ変更します(二箇所あります)
  6. 以下の行を削除します(二箇所あります)
    VALID_ARCHS = x86_64;
  7. ファイルを保存して、Xcodeを閉じます
  8. 再びPlugin -> MacOS -> StandaloneFileBrowserフォルダーに戻ります
  9. StandaloneFileBrowser.xcodeprojをXcodeで開きます
  10. メニューの「Product」>「Build」を実行してビルドを行います
  11. ビルドが成功すると、StandaloneFileBrowser.bundleファイルが生成されます
    ※このファイルの場所は、Xcodeの「Product」>「Show Build Folder in Finder」で確認できます。
  12. 生成されたStandaloneFileBrowser.bundleファイルを、既存のファイルと置き換えます

まとめ

Apple Silicon Macは大幅なアーキテクチャ変更により、今まで使えていたものが使えなくなるなどがあります。本記事で誰かの助けになれば幸いです。また何か間違いなどありましたら遠慮なくコメントしてください!

参考リンク

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?