检测丢失文件

  1. 之前升级unity 弄丢了一部分文件 当时也没注意 就是一直报错 

    UnityEngine.UI.Graphic.OnRebuildRequested errors

  2. 我这个强迫症患者受不了了 找打了这个脚本 很好用 分享出来
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.Collections.Generic;
  6. // from: http://wiki.unity3d.com/index.php?title=FindMissingScripts
  7. public class FindMissingScriptsRecursively : EditorWindow
  8. {
  9. static int go_count = 0, components_count = 0, missing_count = 0;
  10. [MenuItem("Window/Find Missing Scripts (All)")]
  11. static void FindInAll()
  12. {
  13. go_count = 0;
  14. components_count = 0;
  15. missing_count = 0;
  16. foreach (var root in SceneRoots())
  17. {
  18. //Debug.Log(root);
  19. FindInGO(root);
  20. }
  21. Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
  22. }
  23. static void FindInGO(GameObject g)
  24. {
  25. go_count++;
  26. Component[] components = g.GetComponents<Component>();
  27. for (int i = 0; i < components.Length; i++)
  28. {
  29. components_count++;
  30. if (components[i] == null)
  31. {
  32. missing_count++;
  33. string s = g.name;
  34. Transform t = g.transform;
  35. while (t.parent != null)
  36. {
  37. s = t.parent.name +"/"+s;
  38. t = t.parent;
  39. }
  40. Debug.Log (s + " has an empty script attached in position: " + i, g);
  41. }
  42. }
  43. // Now recurse through each child GO (if there are any):
  44. foreach (Transform childT in g.transform)
  45. {
  46. //Debug.Log("Searching " + childT.name + " " );
  47. FindInGO(childT.gameObject);
  48. }
  49. }
  50. static IEnumerable<GameObject> SceneRoots()
  51. {
  52. var prop = new HierarchyProperty(HierarchyType.GameObjects);
  53. var expanded = new int[0];
  54. while (prop.Next(expanded)) {
  55. yield return prop.pptrValue as GameObject;
  56. }
  57. }
  58. }
posted @ 2016-07-17 13:28  rexzhao  阅读(312)  评论(0编辑  收藏  举报