0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[MR Dev Tips #9] Visual Studio Tools for Unity を使って Unity C# スクリプトに ブレークポイント を設定する方法

Last updated at Posted at 2023-08-09

はじめに

HoloLens 2 Dev Tips シリーズを始めて、9回目の記事は「Visual Studio Tools for Unity」を使用して、Unity スクリプトにブレークポイントを設定する方法をご紹介したいと思います。先週、Visual Studio Code 向けの Unity 拡張 (プレビュー) がリリースされ、Unity 2021 以降から使用できるようです。興味がある方は 「Visual Studio Code」にも「Unity」拡張機能、Microsoftがプレビューリリース の記事も参考になるかと思います。

前提条件

  • Visual Studio 2022 インストール済みであること

検証環境

  • Visual Studio 2022 (17.1.3)
  • Unity 2020.3.48f1

手順

まず Visual Studio 2022 に 「Unityによるゲーム開発」のワークロードがインストールされているか確認してください。まだ、インストールされていない場合は、インストールする必要があります。

image.png

Unity の Preferences (環境設定) を開いて、Visual Studio を既定のスクリプトエディターに設定します。Edit > Preferences を開きます。External Tools タブを開き、External Script Editor を Visual Studio Community 2022 に設定します。

image.png

Unity の パッケージマネージャーを使って「Visual Studio Editor」の拡張パッケージをインストールします。新しいバージョンが使用可能な場合は、更新をかけておきます。

image.png

Assets > Open C# Project を選択して、Visual Studio 2022 を起動します。

image.png

image.png

表示 > Unity プロジェクトエクスプローラー を選択します。

image.png

Unity プロジェクトエクスプローラーが開くと、Assets フォルダ配下を確認することができます。

image.png

Assets フォルダ内の適当なスクリプトを開いて、ブレークポイントを設定します。設定方法は、ソースコードの行番号の左端の部分をクリックするだけです。ブレークポイントの設定が終わったら 「Unity にアタッチ」 ボタンをクリックします。

image.png

Unity Editor 画面で Play Mode に入ります。今回は、MRTK の Pressable Button を押すと、RecorderSample クラスの recording() が実行されるように設定されており、メソッドの1行目をブレークポイントとして設定しています。

image.png

再び、Visual Studio に戻ってくると、設定したブレークポイントで処理が停止していることが分かります。

image.png

処理を続行する場合は、Visual Studio の [続行] ボタンをクリックすることで、後続の処理が走ります。Visual Studio では、メンバ変数に格納されているデータの中身も見ることができます。ということで、Visual Studio を使って Unity C# スクリプトにブレークポイントを設定する方法でしたー!

Refs

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?