うにてぃブログ

主にUnityとC#に関する記事を書いていきます

【Unity】Reveal In Finder / Show in Explorer をスクリプトから呼び出す

アセットを右クリックした際に Reveal In Finder / Show in Explorer を選べば ファイラーが開きます

f:id:hacchi_man:20200924000130p:plain:w200

これをスクリプトから呼び出したい場合は EditorUtility.RevealInFinder を利用する

ファイルを指定した場合は ファイルを選択した状態でファイラーを開けますが
ディレクトリを指定した場合は親ディレクトリが選択した状態でファイラーが開いてしまいます

// ルートからのパス と Assets からのパス 両方指定できる
EditorUtility.RevealInFinder(Application.temporaryCachePath);
EditorUtility.RevealInFinder("Assets/");
 
// Assets の親ディレクトリを選択した状態で開く
EditorUtility.RevealInFinder("Assets/");
 
// Sample.unity ファイルが選択状態で開く
EditorUtility.RevealInFinder("Assets/Sample.unity");