unity删除丢失的脚本

unity 删除丢失的脚本

 public static void DestoryMissScript()
    {
     
        if(Selection.activeGameObject==null)
        {
     
            return;
        }
        var gos = Selection.activeGameObject.GetComponentsInChildren<Transform>(true);
        foreach (var item in gos)
        {
     
            Debug.Log(item.name);
            SerializedObject so = new SerializedObject(item.gameObject);
             var soProperties = so.FindProperty("m_Component");
            var components = item.GetComponents<Component>();
            int propertyIndex = 0;
            foreach (var c in components)
            {
     
                if (c == null)
                {
     
                    soProperties.DeleteArrayElementAtIndex(propertyIndex);
                }
                ++propertyIndex;
            }
            so.ApplyModifiedProperties();
        }
        AssetDatabase.Refresh();
        Debug.Log("清理完成!");
    } 

你可能感兴趣的:(unity,unity)