首页 > 编程语言 > 详细

Unity用代码实现Remove Missing Script

时间:2017-11-27 19:13:10      阅读:681      评论:0      收藏:0      [点我收藏+]
 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

原文:http://www.cnblogs.com/AaronBlogs/p/7905619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!