UnityEditorInternal.InternalEditorUtility
InternalEditorUtilityではリファレンスに載っていない。以下の二箇所にクラスが書かれている。しかし内部の実装までは見れない部分もある。
- UnityCsReference/InternalEditorUtility.cs at master · Unity-Technologies/UnityCsReference · GitHub
- UnityCsReference/InternalEditorUtility.bindings.cs at 73c12b5a403abad9a300f01a81e7aaf30a0d30b5 · Unity-Technologies/UnityCsReference · GitHub
ログファイルを開く
// コード
InternalEditorUtility.OpenEditorConsole();
Editor.logファイルを開きます。MacOS環境下では、~/Library/Logs/Unity/Editor.log
が開かれました。Debug.Logなどの出力が記載されています。エラーが出たけど消してしまった時に見返すことができそうです。
エディタでファイルを開く
// コード InternalEditorUtility.OpenFileAtLineExternal( filePath, line ); // 使用例 : Assets/Scripts/Hoge.csの29行目を開く string path = Application.dataPath + "/Scripts/Hoge.cs"; InternalEditorUtility.OpenFileAtLineExternal( path , 29 );
Consoleで表示されているパスをクリックするとエディタを開くのはこれが利用されていると思います。
パスを取得する
さまざまなパスを取得することができます。実際に利用することは少ないと思います。
InternalEditorUtility.GetAssetsFolder(); /* 出力 Assets */ InternalEditorUtility.GetEditorFolder(); /* 出力 Editor */ InternalEditorUtility.GetEngineAssemblyPath(); /* 出力 /Applications/Unity/Hub/Editor/2021.3.6f1/Unity.app/Contents/Managed/ UnityEngine/UnityEngine.dll */ InternalEditorUtility.GetEngineCoreModuleAssemblyPath(); /* 出力 /Applications/Unity/Hub/Editor/2021.3.6f1/Unity.app/Contents/Managed/UnityEngine/UnityEngine.CoreModule.dll */ InternalEditorUtility.GetFullUnityVersion(); /* 出力 2021.3.6f1 (7da38d85baf6) */ // 他のPath Application.dataPath /* 出力 /Users/ **hogehoge** / ~プロジェクトの位置までのパス~ / Assets Assetsまでの絶対パスを取得できる。 Applecation.dataPath + "/" + "Scripts/hoge/hoge.cs"; のように使用する。 */