删除所有Prefab 上Miss的脚本

2019-1-15 雨辰 遇到的一些问题

/************************************************************
  Description:删除所有Miss的脚本
************************************************************/

using UnityEngine;
using UnityEditor;

public class DeleteMissingScripts : MonoBehaviour
{

    [MenuItem("Tools/Delete Missing Scripts")]
    static void CleanupMissingScript()
    {
        GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));

        int r;
        int j;
        for (int i = 0; i < pAllObjects.Length; i++)
        {
            //if (pAllObjects[i].hideFlags == HideFlags.None)//HideFlags.None 获取Hierarchy面板所有Object
            //{
                var components = pAllObjects[i].GetComponents<Component>();
                var serializedObject = new SerializedObject(pAllObjects[i]);
                var prop = serializedObject.FindProperty("m_Component");
                r = 0;

                for (j = 0; j < components.Length; j++)
                {
                    if (components[j] == null)
                    {
                        prop.DeleteArrayElementAtIndex(j - r);
                        r++;
                    }
                }
                serializedObject.ApplyModifiedProperties();
            //}
        }
    }
}

标签: Unity3D-Editer

发表评论:

雨辰 joyimp|@2011-2018 京ICP备16030765号