[MenuItem("Edit/Cleanup Missing Scripts")]
static void CleanupMissingScripts ()
{
for(int i = ; i < Selection.gameObjects.Length; i++)
{
var gameObject = Selection.gameObjects[i]; // We must use the GetComponents array to actually detect missing components
var components = gameObject.GetComponents<Component>(); // Create a serialized object so that we can edit the component list
var serializedObject = new SerializedObject(gameObject);
// Find the component list property
var prop = serializedObject.FindProperty("m_Component"); // Track how many components we've removed
int r = ; // Iterate over all components
for(int j = ; j < components.Length; j++)
{
// Check if the ref is null
if(components[j] == null)
{
// If so, remove from the serialized component array
prop.DeleteArrayElementAtIndex(j-r);
// Increment removed count
r++;
}
} // Apply our changes to the game object
serializedObject.ApplyModifiedProperties();
}
}

原文链接:http://blog.csdn.net/zzmkljd/article/details/52840724

参考链接:

http://www.tallior.com/find-missing-references-unity/

https://github.com/liortal53/MissingReferencesUnity

05-11 10:48
查看更多