码迷,mamicode.com
首页 > 编程语言 > 详细

Unity用代码实现Remove Missing Script

时间:2017-11-27 20:04:18      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:.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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!