public void LoadChooseConfig()
        {
            if (string.IsNullOrEmpty(ChooseConfigSavePath))
            {
                return;
            }

            if (File.Exists(ChooseConfigSavePath))
            {
                DuplicationCleanerHelper.ReadConfig(ChooseConfigSavePath, ref DuplicationAssetGroupDic);
            }
        }
        public void ReplaceAssets(string relativePath, string extensions)
        {
            string[] assetsPath = DuplicationCleanerHelper.CollectAssets(relativePath, extensions.Split(','));

            if (assetsPath == null)
            {
                return;
            }

            //for (int i = 0; i < assetsPath.Length; i++)
            //{
            //	SingleFileReplace(assetsPath[i]);
            //}

            //if(m_ReplaceAssetsPathList == null)
            //{
            //	m_ReplaceAssetsPathList = new List<string>();
            //}
            //else
            //{
            //	m_ReplaceAssetsPathList.Clear();
            //}

            int currentIndex = 0;

            EditorApplication.update = delegate()
            {
                string assetPath = assetsPath[currentIndex];

                bool isCancel = EditorUtility.DisplayCancelableProgressBar("正在替换中..."
                                                                           , assetPath
                                                                           , (float)currentIndex / (float)assetsPath.Length);

                SingleFileReplace(assetPath);
                currentIndex++;
                if (isCancel || currentIndex >= assetsPath.Length)
                {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
                    currentIndex             = 0;
                }
            };

            //for (int i = 0; i < m_ReplaceAssetsPathList.Count; i++)
            //{
            //	AssetDatabase.ImportAsset(DuplicationCleanerHelper.GetPathByRelative(m_ReplaceAssetsPathList[i]));
            //}
            AssetDatabase.Refresh();
        }
        protected void SingleFileReplace(string fileFullPath)
        {
            foreach (var duplicationAssetGroup in DuplicationAssetGroupDic)
            {
                if (!duplicationAssetGroup.Value.IsChoosed)
                {
                    continue;
                }

                //筛选出最终使用资源和要替换的资源的GUID
                List <string> oldAssetGUIDs       = new List <string>();
                string        newAssetGUIDs       = string.Empty;
                bool          choosedNewAssetGUID = false;
                int           i = 0;
                for (i = 0; i < duplicationAssetGroup.Value.AssetFilesList.Count; i++)
                {
                    string guid = duplicationAssetGroup.Value.AssetFilesList[i].GUID;
                    if (string.IsNullOrEmpty(guid))
                    {
                        continue;
                    }
                    if (duplicationAssetGroup.Value.AssetFilesList[i].IsChoosed && !choosedNewAssetGUID)
                    {
                        newAssetGUIDs       = guid;
                        choosedNewAssetGUID = true;
                        continue;
                    }
                    oldAssetGUIDs.Add(guid);
                }
                if (string.IsNullOrEmpty(newAssetGUIDs) || oldAssetGUIDs.Count <= 0)
                {
                    continue;
                }

                for (i = 0; i < oldAssetGUIDs.Count; i++)
                {
                    DuplicationCleanerHelper.DoReplace(fileFullPath, newAssetGUIDs, oldAssetGUIDs[i], false);
                    //m_ReplaceAssetsPathList.Add(fileFullPath);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
        }
        public void RemoveUnDuplicationKey()
        {
            if (DuplicationAssetGroupDic == null)
            {
                return;
            }

            List <string> unDuplicationList = new List <string>();

            foreach (var duplicaionAsset in DuplicationAssetGroupDic)
            {
                if (duplicaionAsset.Value == null || duplicaionAsset.Value.AssetFilesList.Count <= 1)
                {
                    unDuplicationList.Add(duplicaionAsset.Key);
                }
            }
            for (int i = 0; i < unDuplicationList.Count; i++)
            {
                DuplicationAssetGroupDic.Remove(unDuplicationList[i]);
            }
            DuplicationAssetGroupDic = DuplicationCleanerHelper.GetSortedDictionary(DuplicationAssetGroupDic);
        }
 public void CheckDuplication()
 {
     DuplicationCleanerHelper.CheckDuplication(this);
 }
 public void SaveChooseConfig()
 {
     DuplicationCleanerHelper.SaveConfig(ChooseConfigSavePath, DuplicationAssetGroupDic);
     LoadChooseConfig();
 }