# M1 mac環境でUnityのエディタにVS codeを使うときのメモ ###### tags: `development` **超大事: monoを入れるときにx86版のbrew を使う** ## 必須 ### VScode extensio - [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) - [Debugger for Unity](https://marketplace.visualstudio.com/items?itemName=Unity.unity-debug) ### .Net - .Net SDK - .NET CLI tools ## brewでアーキテクチャの切り替えをできるようにする - この設定ファイルを適用することで - `switch-arch`でアーキテクチャの切り替えが可能 - `$ brew ` はx86アーキテクチャを使用 - ` $ =brew はarm` アーキテクチャを使用 - ` $ uname -m` アーキテクチャを確認 - `~/.zshrc` に以下を追記する ``` .zshrc typeset -U path PATH path=( /opt/homebrew/bin(N-/) /usr/local/bin(N-/) $path ) if (( $+commands[sw_vers] )) && (( $+commands[arch] )); then [[ -x /usr/local/bin/brew ]] && alias brew="arch -arch x86_64 /usr/local/bin/brew" alias x64='exec arch -x86_64 /bin/zsh' alias a64='exec arch -arm64e /bin/zsh' switch-arch() { if [[ "$(uname -m)" == arm64 ]]; then arch=x86_64 elif [[ "$(uname -m)" == x86_64 ]]; then arch=arm64e fi exec arch -arch $arch /bin/zsh } fi setopt magic_equal_subst ``` ## monoをx86のbrewでインストールする ``` $ brew install mono $ mono -v Mono JIT compiler version 6.12.0.125 (2020-02/8c552e98bd6 Mon Mar 8 13:06:52 EST 2021) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: SIGSEGV: altstack Notification: kqueue Architecture: amd64 Disabled: none Misc: softdebug Interpreter: yes LLVM: yes(610) Suspend: hybrid GC: sgen (concurrent by default) ``` ## Unityでの設定 - 設定よりエディタをVisual Studio Code に変更 - "Generate .csproj file for"のチェックボックスに全てチェックをいれる - "Regenerate project file" を押してcsprojファイルを生成 ## VScode側の設定 Unity側でc#のスクリプトファイルを開く デフォルトだとエラーがでる OUTPUTのC#の部分で ``` [fail]: OmniSharp.MSBuild.ProjectLoader The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks ``` というエラーがでるのでVScodeの設定 `"Manage"->"Settings"-> "Omnisharp: Use Global Mono" ` の項目をalwaysに変更する(デフォルトはauto) # 参考 - https://zenn.dev/nmrtkhs/articles/0b75959281c9a7 - https://zenn.dev/ress/articles/069baf1c305523dfca3d THX: @Inaba