神様は有休消化中です。

Unity関連の技術ネタを書いてます。

【Unity5】Visual Studio Codeを使ってデバッグする

Visuat Studio Codeを使ってデバッグするための情報が公式から出たので、試してみました。
今の所Mac OS X以外は未サポートみたいです。

環境

Mac OS X 10.10.1
・Unity 5.2.1f1
Visual Studio Code 0.8.0

やりたいこと

・UnityのエディタとしてVisual Studio Codeを使う
デバッグもしたい



Monoアップデート

UnityにくっついてくるMonoは古いらしく、そのままではVisual Studio Codeが落ちるためアップデートする。
インストールを実行するとエラーが・・・orz

$ brew install mono
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mono-3.12.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mono-3.12.0.yosemite.bottle.tar.gz
==> Caveats
To use the assemblies from other formulae you need to set:
  export MONO_GAC_PREFIX="/usr/local"
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/al
Target /usr/local/bin/al
already exists. You may want to remove it:
  rm '/usr/local/bin/al'

To force the link and overwrite all conflicting files:
  brew link --overwrite mono

To list all files that would be deleted:
  brew link --overwrite --dry-run mono


表示された手順を踏んでみる。warningが出るけどそこは気にしない。

$ rm '/usr/local/bin/al'
$ brew link --overwrite mono
Warning: Already linked: /usr/local/Cellar/mono/3.12.0
To relink: brew unlink mono && brew link mono
$ brew link --overwrite --dry-run mono
Warning: Already linked: /usr/local/Cellar/mono/3.12.0
To relink: brew unlink mono && brew link mono


もう一回インストールを試すと、もう入ってるよと。
不安なのでアンインストール後にもう一回インストールする。今度は成功。

$ brew install mono
Warning: mono-3.12.0 already installed
$ brew uninstall mono
Uninstalling /usr/local/Cellar/mono/3.12.0...
$ brew install mono
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mono-3.12.0.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/mono-3.12.0.yosemite.bottle.tar.gz
==> Pouring mono-3.12.0.yosemite.bottle.tar.gz
==> Caveats
To use the assemblies from other formulae you need to set:
  export MONO_GAC_PREFIX="/usr/local"
==> Summary
/usr/local/Cellar/mono/3.12.0: 1131 files, 219M

UnityにVisual Studio Codeのプラグインを適用

まずはgitからcloneしてくる。

$ git clone https://github.com/dotBunny/VSCode.git
Cloning into 'VSCode'...
remote: Counting objects: 175, done.
remote: Total 175 (delta 0), reused 0 (delta 0), pack-reused 175
Receiving objects: 100% (175/175), 418.28 KiB | 333.00 KiB/s, done.
Resolving deltas: 100% (57/57), done.
Checking connectivity... done.

こんな感じでフォルダができるので、/Plugins以下をUnityのAssets以下にインポート(UnityエディタのAssets以下にDrag&DropでOK)

$ pwd
/Users/hoge/VSCode
$ ls -l
total 784
-rw-r--r--  1 hoge  staff  389459  9 27 09:48 HOWTO.pdf
-rw-r--r--  1 hoge  staff    1081  9 27 09:48 LICENSE
drwxr-xr-x  4 hoge  staff     136  9 27 09:50 Plugins
-rw-r--r--  1 hoge  staff    2627  9 27 09:48 README.md

Unityエディタの[Unity]-[Preferences]にVSCodeタブが出るので、[Enable Integration]と[Output Messages To Console]にチェックを入れる。
f:id:appleorbit:20150927102125p:plain


[Assets]-[Open C# Project In Code]でVisual Studio Codeが開きます。

デバッガが使えるようにする

Visual Studio Codeの左側メニューの以下のアイコンを押す。デバッグビューが表示されます。
f:id:appleorbit:20150927103854p:plain

下図矢印のアイコンを押すと、デバッグの設定ファイルが開きます。
f:id:appleorbit:20150927104554j:plain

ファイルの中身の"configurations"以下に、以下の内容を設定します。
※ポート番号は端末ごとに異なります、もともと表示されている設定内容の"port"を設定してください。

{
	"name":"Unity",
	"type":"mono",
	"address":"localhost",
	"port":56039
}

そのままだとデバッグ実行時にエラーが出るので、configurations以下の最初のレコード(一番長いやつ)を削除すると、エラーが消えます。
これで、デバッグができるようになりました。

なんか色々設定ファイルが増えたりEditorCode追加したりしないといけなかったり。そのうちスマートな感じになることを期待しつつ。たぶん仕事では使わないかなー。