読者です 読者をやめる 読者になる 読者になる

Unity スクリプトやプレハブなどのリソースが使用されているかを自動検索するツール

概要

Unityでオブジェクトが利用されているファイルを自動検索する方法を書いた。
yasuaki-ohama.hatenablog.com
しかし、この方法だと「JumpBoard.prefab」がどこで使われているか知りたい時

$ find . -name JumpBoard.prefab.meta
$ cat ./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab.meta
$ git grep -l f1f94e603ef11234d88f2d5bcf4b23d3

と3回もコマンドを打たなければならないため面倒だ。

そこで今回は以下のシェルスクリプトを実行するだけで簡単に検索できるツールを作成した。

使い方1(検索)

findUsedObject.sh · GitHubをダウンロードしてプロジェクト以下に置く
以下のようにコマンドを打ち実行する。

$ ./findUsedObject.sh JumpBoard.prefab
./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab.meta
Assets/Scenes/Stage/0/0_0.unity
Assets/Scenes/Stage/0/1_0.unity
Assets/Scenes/Stage/0/3_0.unity
Assets/Scenes/Stage/0/6_0.unity
Assets/Scenes/Stage/1/1_1.unity
Assets/Scenes/Stage/1/1_5.unity
Assets/Scenes/Stage/1/1_6.unity
Assets/Scenes/Stage/1/1_7.unity
Assets/Scenes/Stage/2/2_5.unity
Assets/Scenes/Stage/3/3_4.unity
Assets/Scenes/Stage/3/3_7.unity
Assets/Scenes/Stage/4/4_4.unity
Assets/Scenes/Stage/5/5_2.unity
Assets/Scenes/Stage/6/6_3.unity
Assets/Scenes/Stage/7/7_1.unity
Assets/Scenes/Stage/7/7_4.unity
Assets/Scenes/Stage/7/7_7.unity
Assets/Scenes/Stage/8/8_5.unity
Assets/Tutorial/Scenes/0_0_Debug_Object.unity

このオブジェクトが利用されているステージがわかる

使い方2(複数検索)

特定の文字列が入っているオブジェクトを利用しているファイルを全て列挙する

$ ./findUsedObject.sh JumpBoard       
./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.cs.meta
Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab
Assets/Object/AddMoveObject/JumpBoard/JumpBoardE.prefab

./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.mat.meta
Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab
Assets/Object/AddMoveObject/JumpBoard/JumpBoardE.prefab
Assets/Scenes/Stage/1/1_6.unity

./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.png.meta
Assets/Object/Goal/Game_Clear.mat

./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab.meta
Assets/Scenes/Stage/0/0_0.unity
Assets/Scenes/Stage/0/1_0.unity
Assets/Scenes/Stage/0/3_0.unity
Assets/Scenes/Stage/0/6_0.unity
Assets/Scenes/Stage/1/1_1.unity
Assets/Scenes/Stage/1/1_5.unity
Assets/Scenes/Stage/1/1_6.unity
Assets/Scenes/Stage/1/1_7.unity
Assets/Scenes/Stage/2/2_5.unity
Assets/Scenes/Stage/3/3_4.unity
Assets/Scenes/Stage/3/3_7.unity
Assets/Scenes/Stage/4/4_4.unity
Assets/Scenes/Stage/5/5_2.unity
Assets/Scenes/Stage/6/6_3.unity
Assets/Scenes/Stage/7/7_1.unity
Assets/Scenes/Stage/7/7_4.unity
Assets/Scenes/Stage/7/7_7.unity
Assets/Scenes/Stage/8/8_5.unity
Assets/Tutorial/Scenes/0_0_Debug_Object.unity

./Assets/Object/AddMoveObject/JumpBoard/JumpBoardAnimation.cs.meta
Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab
Assets/Object/AddMoveObject/JumpBoard/JumpBoardE.prefab

./Assets/Object/AddMoveObject/JumpBoard/JumpBoardE.prefab.meta
Assets/Scenes/Stage/6/6_7.unity
Assets/Scenes/Stage/7/7_5.unity
Assets/Scenes/Stage/7/7_6.unity
Assets/Scenes/Stage/7/7_7.unity
Assets/Scenes/Stage/8/8_7.unity
Assets/Tutorial/Scenes/0_0_Debug_Object.unity

./Assets/Object/AddMoveObject/JumpBoard.meta

使い方3(複数検索 + 特定の拡張子だけ表示)

$ ./findUsedObject.sh JumpBoard unity 
./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.cs.meta

./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.mat.meta
Assets/Scenes/Stage/1/1_6.unity

./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.png.meta

./Assets/Object/AddMoveObject/JumpBoard/JumpBoard.prefab.meta
Assets/Scenes/Stage/0/0_0.unity
Assets/Scenes/Stage/0/1_0.unity
Assets/Scenes/Stage/0/3_0.unity
Assets/Scenes/Stage/0/6_0.unity
Assets/Scenes/Stage/1/1_1.unity
Assets/Scenes/Stage/1/1_5.unity
Assets/Scenes/Stage/1/1_6.unity
Assets/Scenes/Stage/1/1_7.unity
Assets/Scenes/Stage/2/2_5.unity
Assets/Scenes/Stage/3/3_4.unity
Assets/Scenes/Stage/3/3_7.unity
Assets/Scenes/Stage/4/4_4.unity
Assets/Scenes/Stage/5/5_2.unity
Assets/Scenes/Stage/6/6_3.unity
Assets/Scenes/Stage/7/7_1.unity
Assets/Scenes/Stage/7/7_4.unity
Assets/Scenes/Stage/7/7_7.unity
Assets/Scenes/Stage/8/8_5.unity
Assets/Tutorial/Scenes/0_0_Debug_Object.unity

./Assets/Object/AddMoveObject/JumpBoard/JumpBoardAnimation.cs.meta

./Assets/Object/AddMoveObject/JumpBoard/JumpBoardE.prefab.meta
Assets/Scenes/Stage/6/6_7.unity
Assets/Scenes/Stage/7/7_5.unity
Assets/Scenes/Stage/7/7_6.unity
Assets/Scenes/Stage/7/7_7.unity
Assets/Scenes/Stage/8/8_7.unity
Assets/Tutorial/Scenes/0_0_Debug_Object.unity

./Assets/Object/AddMoveObject/JumpBoard.meta