Created
June 22, 2021 02:43
-
-
Save heppoko/839ab0c8a84adf07a32cfa84f9640bb5 to your computer and use it in GitHub Desktop.
全てのスクリプトの中から特定の ScriptExecutionOrder のものを探してログに出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
// 全てのスクリプトの中から特定の ScriptExecutionOrder のものを探してログに出力する | |
public class FindExecutionOrder : EditorWindow | |
{ | |
private string currentInput = ""; | |
private string lastInput = null; | |
[MenuItem("Window/FindExecutionOrder")] | |
public static void ShowWindow() | |
{ | |
GetWindow<FindExecutionOrder>(); | |
} | |
private void OnGUI() | |
{ | |
currentInput = EditorGUILayout.TextField("ScriptExecutionOrder", currentInput); | |
// Return キーが押されたら入力確定させたいので少々面倒なことをしている... | |
if (Event.current.keyCode == KeyCode.Return) | |
{ | |
if (int.TryParse(currentInput, out int order)) | |
{ | |
if (lastInput != currentInput) | |
{ | |
// 数字が入力確定したので検索する | |
FindScript(order); | |
lastInput = currentInput; | |
} | |
} | |
} | |
} | |
private void FindScript(int order) | |
{ | |
// スクリプト全部 | |
string[] allAssetsGUIDs = AssetDatabase.FindAssets("t:script"); | |
foreach (string guid in allAssetsGUIDs) | |
{ | |
// パスを元に MonoScript を得て、そこから ScriptExecutionOrder を得る | |
string path = AssetDatabase.GUIDToAssetPath(guid); | |
MonoScript monoScript = AssetDatabase.LoadAssetAtPath<MonoScript>(path); | |
int scriptOrder = MonoImporter.GetExecutionOrder(monoScript); | |
// 一致したらログに吐く | |
if (scriptOrder == order) | |
{ | |
Debug.LogFormat("Order:{0} Script:{1}", scriptOrder, path); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment