Advertisement
LittleAngel

FindMissingReferences

Dec 9th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. public class ToolTest : MonoBehaviour {
  6.  
  7. [MenuItem("Tools/Find Missing references in scene")]
  8. public static void FindMissingReferences()
  9. {
  10. var objects = GameObject.FindObjectsOfType();
  11.  
  12. foreach (var go in objects)
  13. {
  14. var components = go.GetComponents();
  15.  
  16. foreach (var c in components)
  17. {
  18. SerializedObject so = new SerializedObject(c);
  19. var sp = so.GetIterator();
  20.  
  21. while (sp.NextVisible(true))
  22. {
  23. if (sp.propertyType == SerializedPropertyType.ObjectReference)
  24. {
  25. if (sp.objectReferenceValue == null && sp.objectReferenceInstanceIDValue != 0)
  26. {
  27. ShowError(FullObjectPath(go), sp.name);
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }
  34.  
  35. private static void ShowError (string objectName, string propertyName)
  36. {
  37. Debug.LogError("Missing reference found in: " + objectName + ", Property : " + propertyName);
  38. }
  39.  
  40. private static string FullObjectPath(GameObject go)
  41. {
  42. return go.transform.parent == null ? go.name : FullObjectPath(go.transform.parent.gameObject) + "/" + go.name;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement