关键句子:
var cs = gameObject.GetComponents<Component>();
foreach (var c in cs)
{
if (c == null) GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
}
}
public class ContextRemoveMissing : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Delete(this.gameObject);
}
[ContextMenu("删除丢失的脚本")]
// Update is called once per frame
void Remove()
{
var gos = FindObjectsOfType<GameObject>();
foreach (var g in gos)
{
Delete(g);
}
}
void Delete(GameObject gameObject)
{
if (gameObject != null)
{
var cs = gameObject.GetComponents<Component>();
foreach (var c in cs)
{
if (c == null) GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
}
}
}
}