Unity用代码实现Remove Missing Script
Posted AaronBlog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity用代码实现Remove Missing Script相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Unity5 项目设置 .gitignore 解决 Missing Prefab 问题