예제 #1
0
        /// <summary>
        /// 打印没有guid的miss脚本信息
        /// </summary>
        void PrintMissScriptNoGUID()
        {
            string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/prefab" });//获取所有预制体guid
            int      i           = 0;

            foreach (var prefabGUID in prefabGuids)
            {
                EditorUtility.DisplayProgressBar("Processing...", "打印没有guid的miss脚本中....", i++ / (float)prefabGuids.Length);
                var prefabPath      = DeleteMissScriptTool.GetPathByGUID(prefabGUID);//预制体全路径
                var scriptFileIDLst = DeleteMissScriptTool.GetScriptNoGUIDFileIDLst(prefabPath);

                foreach (var fileID in scriptFileIDLst)
                {
                    Debug.LogFormat("prefab:{0},script:{1}", prefabPath, fileID);
                }
            }
            EditorUtility.ClearProgressBar();
        }
예제 #2
0
        /// <summary>
        /// 获取有guid的miss脚本信息
        /// </summary>
        /// <param name="Dictionary<string"></param>
        /// <param name="guid2prefab"></param>
        /// <param name="Dictionary<string"></param>
        /// <param name="prefab2guid2fileID"></param>
        /// <returns></returns>
        HashSet <string> GetMissScriptGUID(out Dictionary <string, HashSet <string> > guid2prefab, out Dictionary <string, Dictionary <string, string> > prefab2guid2fileID)
        {
            string[]         guids      = AssetDatabase.FindAssets("t:Script");//所有脚本guid
            HashSet <string> existGuids = new HashSet <string>(guids);

            HashSet <string> referenceGuids = new HashSet <string>();                                                //所有预制体引用的脚本guid

            prefab2guid2fileID = new Dictionary <string, Dictionary <string, string> >();                            //脚本guid到预制体列表的映射
            guid2prefab        = new Dictionary <string, HashSet <string> >();                                       //脚本guid到预制体列表的映射

            string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/prefab" }); //获取所有预制体guid
            int      i           = 0;

            foreach (var prefabGUID in prefabGuids)
            {
                EditorUtility.DisplayProgressBar("Processing...", "收集miss脚本的guid中....", i++ / (float)prefabGuids.Length);
                var prefabPath = DeleteMissScriptTool.GetPathByGUID(prefabGUID);           //预制体全路径

                var fileID2guid = DeleteMissScriptTool.GetScriptFileIDAndGuid(prefabPath); //脚本guid到fileID的映射

                prefab2guid2fileID[prefabPath] = fileID2guid;                              //预制体上的脚本guid到fileID的映射

                //脚本guid到预制体列表的映射
                foreach (var item in fileID2guid)
                {
                    if (guid2prefab.ContainsKey(item.Value) == false)
                    {
                        guid2prefab[item.Value] = new HashSet <string>();
                    }
                    guid2prefab[item.Value].Add(prefabPath);
                }

                referenceGuids.UnionWith(fileID2guid.Values); //合并预制体引用的脚本guid并去重
            }
            referenceGuids.ExceptWith(guids);                 //提取出不存在的脚本guid
            EditorUtility.ClearProgressBar();
            return(referenceGuids);
        }