using UnityEngine; using System.Collections; using UnityEditor; using UnityEngine.SceneManagement; public class RemoveMissingScripts : Editor { [MenuItem("程序/移除丢失的脚本")] public static void RemoveMissingScript() { var gos = GameObject.FindObjectsOfType(); foreach (var item in gos) { SerializedObject so = new SerializedObject(item); var soProperties = so.FindProperty("m_Component"); var components = item.GetComponents(); int propertyIndex = 0; foreach (var c in components) { if (c == null) { soProperties.DeleteArrayElementAtIndex(propertyIndex); } ++propertyIndex; } so.ApplyModifiedProperties(); } AssetDatabase.Refresh(); Debug.Log("清理完成!"); } }