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

【Unity】デバッグに便利なアセットまとめ

Last updated at Posted at 2025-07-16

1. はじめに

Unityのデバッグに便利なアセットやスクリプトをまとめました.

2. 一覧

(1) Hierarchyのオブジェクトを目立たせる

Rainbow Hierarchy 2 (有料)

Hierarhyのオブジェクト名を強調できるアセット.
オブジェクト名の左隣にアイコンを付けたり,背景色を付けたりできます.
強調したいオブジェクト名の上でalt+clickするだけで設定できるので便利.

Colourful Hierarchy Category GameObject (無料)

こちらはオブジェクト名の先頭に@や///など記号を入れることで強調表示できるアセット.
無料で便利ではあるものの,スクリプト内でオブジェクト名を参照している場合に影響を受けるので注意が必要です.

(2) Gameビューの自動アクティベート

シーン開始と同時にGameビューを有効化しておくスクリプト.
キーボード入力が必要なときに毎度Gameビューをクリックする必要がなくなります.
以下のスクリプトをAssets>Editorフォルダに入れておくだけで動作します.

AutoActivateGameView.cs
using UnityEditor;
using UnityEngine;

public class AutoActivateGameWindow : MonoBehaviour
{
    // クラスが初めて使われたときに1回だけ呼ばれる静的コンストラクタ
    // Playモードの状態変化に対してイベントを登録
    static AutoActivateGameWindow()
    {
        // 再生・停止などのPlayモード状態変更を監視し
        // OnPlayModeChangedメソッドを呼び出す
        EditorApplication.playModeStateChanged += OnPlayModeChanged;
    }

    // Playモード状態が変化したときに呼ばれる処理
    static void OnPlayModeChanged(PlayModeStateChange state)
    {
        // 再生ボタンを押した直後に処理を実行
        if (state == PlayModeStateChange.EnteredPlayMode)
        {
            FocusOnGameView(); // Gameビューを前面に表示する
        }
    }

    // Unityエディタのメニューを実行してGameビューをアクティブにする
    static void FocusOnGameView()
    {
        // "Window > General > Game" メニューを選んだのと同じ動作を実行
        EditorApplication.ExecuteMenuItem("Window/General/Game");
    }
}

(3) Hierarchy自動展開

アバタオブジェクトは子要素のネストが深いため,毎度手動で展開するのは手間ですよね.
以下は特定のGameObjectの位置まで展開するスクリプトです.
※展開するタイミングが,Start()が呼び出されるときなので要改良.
 InitializeOnLoadだとEditorが重くなりそうなので...

HierarchyExpander.cs
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

public class HierarchyExpander : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Scene currentScene = SceneManager.GetActiveScene();
        // 展開するオブジェクト名を指定してhierarchyを展開
        // enabled=falseは無視
        // 子要素のオブジェクトを選択すると親オブジェクトもその階層まで展開される
        ExpandSpecificObjects(currentScene, new string[] { "GameObject", "@CC_Base_R_Forearm" }); 
        //SetExpandedAll(currentScene, true);
    }

    private static void ExpandSpecificObjects(Scene scene, string[] targetNames)
    {
        foreach (var window in Resources.FindObjectsOfTypeAll<SearchableEditorWindow>())
        {
            // Editor WindowのHierarchy windowsだけ処理
            if (window.GetType().Name != "SceneHierarchyWindow")
                continue;

            // 非公開メソッドSsetExpandedRecursiveを実行
            // 直接アクセスできないのでReflectionを使用
            var method = window.GetType().GetMethod("SetExpandedRecursive",
                System.Reflection.BindingFlags.Public |
                System.Reflection.BindingFlags.NonPublic |
                System.Reflection.BindingFlags.Instance, null,
                new[] { typeof(int), typeof(bool) }, null);

            // 使用しているバージョンにSetExpandedRecursiveメソッドが存在しなければ終了
            if (method == null)
            {
                Debug.LogError(
                    "Could not find method 'UnityEditor.SceneHierarchyWindow.SetExpandedRecursive(int, bool)'.");
                return;
            }

            // 指定したオブジェクトだけ展開する
            foreach (string name in targetNames)
            {
                GameObject targetObject = GameObject.Find(name);
                if (targetObject == null)
                {
                    Debug.LogWarning($"GameObject '{name}' not found.");
                    continue;
                }

                // Instance IDを取得
                int instanceID = targetObject.GetInstanceID();

                // 展開処理を適用
                method.Invoke(window, new object[] { instanceID, true });
            }
        }
    }
}

(4) PCソースの可視化

Graphy

CPU, GPU使用率や,FPSを時系列データとしてGameビューに描画してくれるアセット.

(5) スケール計測

どこでも3D定規

VRC定規アバター【無料】

(6) Scene再生中の変更を保存

Transformの直下に保存ボタンを設置するEditor拡張.

(7) Consoleをカスタマイズ

コンソールに色を付けたり文字の大きさを変えたりできます.
Editorに負荷をかけるので注意.
※問題があったので一時保留.

(8) 鏡

↓バージョン2023.12.12以上が必要?
2022.3.21f1に導入したらスクリプトでエラーが出て使えなかった.

(9) HMD装着したまま編集

uDesktopDuplication

こちらのアセットでは仮想デスクトップを配置することができます.
https://github.com/hecomi/uDesktopDuplication

3. おわりに

随時更新していく予定です.

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