标签:.net actual objects can tail static apply missing array
1 [MenuItem("Edit/Cleanup Missing Scripts")] 2 static void CleanupMissingScripts () 3 { 4 for(int i = 0; i < Selection.gameObjects.Length; i++) 5 { 6 var gameObject = Selection.gameObjects[i]; 7 8 // We must use the GetComponents array to actually detect missing components 9 var components = gameObject.GetComponents<Component>(); 10 11 // Create a serialized object so that we can edit the component list 12 var serializedObject = new SerializedObject(gameObject); 13 // Find the component list property 14 var prop = serializedObject.FindProperty("m_Component"); 15 16 // Track how many components we‘ve removed 17 int r = 0; 18 19 // Iterate over all components 20 for(int j = 0; j < components.Length; j++) 21 { 22 // Check if the ref is null 23 if(components[j] == null) 24 { 25 // If so, remove from the serialized component array 26 prop.DeleteArrayElementAtIndex(j-r); 27 // Increment removed count 28 r++; 29 } 30 } 31 32 // Apply our changes to the game object 33 serializedObject.ApplyModifiedProperties(); 34 } 35 }
原文链接:http://blog.csdn.net/zzmkljd/article/details/52840724
Unity用代码实现Remove Missing Script
标签:.net actual objects can tail static apply missing array
原文地址:http://www.cnblogs.com/AaronBlogs/p/7905619.html