美文网首页
2020-06-29【UnityEditor】2019批量删除丢

2020-06-29【UnityEditor】2019批量删除丢

作者: 持刀的要迟到了 | 来源:发表于2020-06-29 15:34 被阅读0次

关键方法:

GameObjectUtility.RemoveMonoBehavioursWithMissingScript

由于unity版本更新,网上找的代码不能用了。
但是使用这个方法可以。
代码:

using UnityEngine;
using UnityEditor;

public class RemoveMissingScriptsRecursively : EditorWindow
{
    [MenuItem("Tools/RemoveMissingScriptsRecursively")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(RemoveMissingScriptsRecursively));
    }

    public void OnGUI()
    {
        if (GUILayout.Button("Remove Missing Scripts in selected GameObjects"))
        {
            RemoveInSelected();
        }
    }
    private static void RemoveInSelected()
    {
        GameObject[] go = Selection.gameObjects;
        foreach (GameObject g in go)
        {
            RemoveRecursively(g);
        }
    }

    private static void RemoveRecursively(GameObject g)
    {
        GameObjectUtility.RemoveMonoBehavioursWithMissingScript(g);

        foreach (Transform childT in g.transform)
        {
            RemoveRecursively(childT.gameObject);
        }
    }
}

相关文章

网友评论

      本文标题:2020-06-29【UnityEditor】2019批量删除丢

      本文链接:https://www.haomeiwen.com/subject/xpnofktx.html