Example #1
0
    static void CopyBetweenProjectAndAB(string versionName, ExcelDirType dirType, bool isABToProject)
    {
        string excelTopDir = ExcelConfig.GetTopDir(dirType);

        string abDir = GetCurrentVersionPath(versionName);

        if (!Directory.Exists(abDir))
        {
            Debug.LogError("Error: directory doesn't exist:" + abDir);
            return;
        }

        List <FileInfo> abInfos = BuildAssetBundleHelper.GetUsefulFileInfosFromDir(abDir);

        string          projectPath = Application.dataPath;
        List <FileInfo> allInfos    = BuildAssetBundleHelper.GetUsefulFileInfosFromDir(projectPath);

        foreach (FileInfo abInfo in abInfos)
        {
            bool isExcel = abInfo.Name.EndsWith(".xls");

            FileInfo projectInfo = ListUtility.FindFirstOrDefault(allInfos, (FileInfo i) => {
                //Debug.Log("name:" + i.Name);
                bool result = abInfo.Name == i.Name;
                if (result && isExcel)
                {
                    result = IsContainDirectory(i.FullName, excelTopDir);
                }
                return(result);
            });

            if (projectInfo == null)
            {
                string errStr = "Can't find corresponding project file:" + abInfo.Name;
                Debug.LogError(errStr);
            }
            else
            {
                if (isABToProject)
                {
                    Debug.Log("copy from " + abInfo.FullName);
                    Debug.Log("copy to " + projectInfo.FullName);

                    File.Copy(abInfo.FullName, projectInfo.FullName, true);

                    string relativePath = BuildAssetBundleHelper.TrimToRelativePath(projectInfo.FullName);
                    AssetDatabase.ImportAsset(relativePath);
                }
                else
                {
                    File.Copy(projectInfo.FullName, abInfo.FullName, true);
                }
            }
        }
    }