Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FindMissingScriptsRecursively : EditorWindow
- {
- private Object target;
- private bool recursive = true, compact = true;
- // [SerializeField] private TreeViewState treeState;
- // private T3TreeView treeView;
- [MenuItem("T3/missfinder")]
- public static void ShowWindow() { GetWindow(typeof(FindMissingScriptsRecursively)); }
- // private void OnEnable()
- // {
- // if(treeState == null)
- // treeState = new TreeViewState();
- // treeView = new T3TreeView(treeState);
- // }
- Vector2 scroll = new Vector2();
- void OnGUI()
- {
- GUI.skin.label.wordWrap = true;
- titleContent.text = "T3 missfinder";
- EditorGUILayout.BeginVertical(EditorStyles.helpBox);
- target = EditorGUILayout.ObjectField(target, typeof(Object), true, GUILayout.Height(20));
- EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
- recursive = EditorGUILayout.ToggleLeft("recursive", recursive, GUILayout.Height(20));
- compact = EditorGUILayout.ToggleLeft("compact", compact, GUILayout.Height(20));
- EditorGUILayout.EndHorizontal();
- if(GUILayout.Button("analyze object", GUILayout.Height(30)))
- {
- Result = "";
- if(target is GameObject) FindForGameObject(target as GameObject);
- else FindForFolder();
- }
- GUILayout.Label("Missing reference finder by T3s. Choose a prefab/folder and run `analyze` to get missing references");
- EditorGUILayout.EndVertical();
- EditorGUILayout.BeginVertical(EditorStyles.helpBox);
- scroll = EditorGUILayout.BeginScrollView(scroll);
- EditorGUILayout.TextArea(Result);
- EditorGUILayout.EndScrollView();
- // treeView.OnGUI(new Rect(0, 0, position.width, position.height));
- EditorGUILayout.EndVertical();
- }
- private string Result { get; set; }
- private void FindForGameObject(GameObject go, string path = "")
- {
- FindForSingleGameObject(go, path + go.name + "/");
- if(recursive)
- foreach(Transform child in go.transform)
- FindForGameObject(child.gameObject, go.name + "/");
- }
- private void FindForSingleGameObject(GameObject go, string path = "")
- {
- var components = go.GetComponents<Component>();
- foreach(Component c in components)
- {
- SerializedObject so = new SerializedObject(c);
- var sp = so.GetIterator();
- while(sp.NextVisible(true))
- if(sp.propertyType == SerializedPropertyType.ObjectReference
- && sp.objectReferenceValue == null)
- Result += "\n" + path + " ["+ c.GetType() + "]-> " + sp.displayName;
- }
- }
- private void FindForFolder() { Debug.LogError("Analyze for folder not implemented... YET..."); }
- // [Serializable]
- // internal class T3TreeView : TreeView
- // {
- // public T3TreeView(TreeViewState state) : base(state,) { }
- //
- // protected override TreeViewItem BuildRoot() { }
- //
- // protected override IList<TreeViewItem> BuildRows(TreeViewItem root) { return base.BuildRows(root); }
- // }
- //
- // internal class T3TreeNode
- // {
- // public string path;
- // public Component script;
- // public Object missingField;
- //
- // public T3TreeNode(string path, Component script, Object missingField)
- // {
- // this.path = path;
- // this.script = script;
- // this.missingField = missingField;
- // }
- // }
- //
- // internal class T3TreeModel : List<T3TreeNode>
- // {
- // }
- // public static void FindMissingScripts()
- // {
- // StringBuilder resultBuilder = new StringBuilder();
- // string fileName = "missing.txt";
- //
- //// var components = Selection.activeGameObject.GetComponents<Component>();
- //// foreach(var c in components)
- //// {
- //// var sp = new SerializedObject(c).GetIterator();
- //// while(sp.NextVisible(true))
- //// if(sp.propertyType == SerializedPropertyType.ObjectReference && sp.objectReferenceValue == null)
- //// }
- //
- // foreach(GameObject selectedGameObject in Selection.gameObjects)
- // {
- // string assetPath = AssetDatabase.GetAssetPath(selectedGameObject);
- // AssetDatabase
- // .LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(selectedGameObject))
- // .OfType<GameObject>()
- // .ForEach(gameObject => FindMissingScriptsInGameObject(assetPath, gameObject, resultBuilder));
- // }
- //
- // SaveResultToFile(resultBuilder, fileName);
- // Debug.LogError("Done. Results are in file " + fileName);
- // }
- //
- // private static void FindMissingScriptsInGameObject(string assetPath, GameObject gameObject, StringBuilder resultBuilder)
- // {
- // gameObject.GetComponents<Component>().Where(c => c == null)
- // .ForEach(c => LogMissingScript(assetPath, gameObject, resultBuilder));
- // }
- //
- // private static void LogMissingScript(string assetPath, GameObject gameObject, StringBuilder resultBuilder)
- // {
- // resultBuilder.AppendLine(string.Format("{0:50} {1:50}", assetPath, Chui.Util.GetFullPath(gameObject)));
- // }
- //
- // private static void SaveResultToFile(StringBuilder resultBuilder, string fileName)
- // {
- // File.WriteAllText(fileName, resultBuilder.ToString());
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement