/// <summary>
    /// 更新runtime的资源
    /// </summary>
    /// <param name="ResModifList">资源列表</param>
    /// <param name="ResDeleteList">其他列表</param>
    /// <param name="needToExportFile">是否需要导出文件,如果为true的话,会调用ExportPackageListToRunTime</param>
    /// <returns>更新后的资源列表</returns>
    private static Dictionary <string, AssetBundleManager.PackageNode> UpdateRunTime_Res(List <string> ResModifList, List <string> ResDeleteList, bool needToExportFile = false)
    {
        string runTimeAssetPcakagePath = GetRunTimeAssetPackagePatchRoot();
        Dictionary <string, AssetBundleManager.PackageNode> runTimeResFileList    = new Dictionary <string, AssetBundleManager.PackageNode>();
        Dictionary <string, AssetBundleManager.PackageNode> runTimeOhterFilerList = new Dictionary <string, AssetBundleManager.PackageNode>();;

        EditorLog.LogInfo("正在进行资源文件加密....", true);
        //加载runtime的进来
        AssetBundleManager.ForceOpenDeCode = true;
        AssetBundleManager.LoadPackageList(GetRunTimeAssetPackagePatchRoot() + AssetBundleManager.AssetPackageListPatch, runTimeResFileList, runTimeOhterFilerList);
        AssetBundleManager.ForceOpenDeCode = false;

        if (null == ResModifList)
        {
            return(runTimeResFileList);
        }
        if (ResModifList.Count <= 0)
        {
            return(runTimeResFileList);
        }

        if (!IsEnableMultThread())
        {
            ProcessEncodeFileNode(PackageNodeType.AssetsBundleFile, ResModifList, ref runTimeResFileList);
        }
        else
        {
            List <EncodeFileNode> AsyncList = DispatchEncodeFileNode(PackageNodeType.AssetsBundleFile, ResModifList, runTimeResFileList, AssetBundleManager.MaxActiveThread);

            while (!IsEncodeFileFinish(AsyncList))
            {
                ;
            }

            CombineEncodeFileTable(ref runTimeResFileList, AsyncList);
        }

        if (null != ResDeleteList)
        {
            foreach (string str in ResDeleteList)
            {
                if (runTimeResFileList.ContainsKey(str))
                {
                    runTimeResFileList.Remove(str);
                }
            }
        }


        if (needToExportFile)
        {
            ExportPackageListToRunTime(runTimeResFileList, runTimeOhterFilerList);
        }

        runTimeOhterFilerList.Clear();
        return(runTimeResFileList);
    }
    /// <summary>
    /// 全部加密一遍
    /// </summary>
    private static void EncodeFile_All(Dictionary <string, AssetBundleManager.PackageNode> ResFileList, Dictionary <string, AssetBundleManager.PackageNode> OtherFileList, bool debugvision)
    {
        List <string> tempList = new List <string>();

        #region Res
        EditorLog.LogInfo("正在进行资源文件加密....", true);
        tempList.AddRange(ResFileList.Keys);
        if (!IsEnableMultThread())
        {
            ProcessEncodeFileNode(PackageNodeType.AssetsBundleFile, tempList, ref ResFileList);
        }
        else
        {
            List <EncodeFileNode> AsyncList = DispatchEncodeFileNode(PackageNodeType.AssetsBundleFile, tempList, ResFileList, AssetBundleManager.MaxActiveThread);

            while (!IsEncodeFileFinish(AsyncList))
            {
                ;
            }

            CombineEncodeFileTable(ref ResFileList, AsyncList);
        }
        #endregion

        #region other
        EditorLog.LogInfo("正在进行代码、配置文件加密....", true);
        tempList.Clear();
        tempList.AddRange(OtherFileList.Keys);

        if (!IsEnableMultThread())
        {
            ProcessEncodeFileNode(PackageNodeType.OtherFile, tempList, ref OtherFileList);
        }
        else
        {
            List <EncodeFileNode> AsyncList = DispatchEncodeFileNode(PackageNodeType.OtherFile, tempList, OtherFileList, AssetBundleManager.MaxActiveThread);

            while (!IsEncodeFileFinish(AsyncList))
            {
                ;
            }

            CombineEncodeFileTable(ref OtherFileList, AsyncList);
        }
        #endregion
        ExportPackageListToRunTime(ResFileList, OtherFileList);
    }
    private static void GenerateErrorFile(string overrideCopyEditorLogPath)
    {
        string LogPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Unity\\Editor\\Editor.log";

        if (EditorRunTypeWindow.IsRunFromCommandLine)
        {
            string[] allCommandLine = Environment.GetCommandLineArgs();
            for (int i = 0; i < allCommandLine.Length; i++)
            {
                if (allCommandLine[i].Contains("-logFile"))
                {
                    LogPath = allCommandLine[i + 1];
                    EditorLog.LogInfo("findCommandLineLogPath:" + LogPath, true);
                    break;
                }
            }
        }
        string reladyCopyPath = CopyLogPath;

        if (!string.IsNullOrEmpty(overrideCopyEditorLogPath))
        {
            reladyCopyPath = overrideCopyEditorLogPath;
        }
        File.Copy(LogPath, reladyCopyPath, true);

        string reader = File.ReadAllText(reladyCopyPath);

        reader = reader.Replace("\r", string.Empty);
        string[] lines = reader.Split('\n');
        foreach (string line in lines)
        {
            FixedPathNode reslut = GetNeedToFixedPath(line);
            if (null != reslut)
            {
                if (reslut.FixedPath.Contains(".dll"))
                {
                    needtoFixDll = true;
                }
                else
                {
                    needToFixedFilePath.Add(reslut);
                }
            }
        }
    }
    /// <summary>
    /// 项目发布完成后
    /// </summary>
    /// <returns></returns>
    private static void OnPostBuildProject(bool debugVersion, bool forceEncodeFile, bool Is64bit)
    {
        EditorLog.LogInfo("正在计算发布后的文件差异....", true);
        GenerateOtherInfo(debugVersion, Is64bit);

        List <string> OtherModifList  = null;
        List <string> OtherDeleteList = null;

        ReadDetailFile(GetOtherDetailFileNamePath(), ref OtherModifList, ref OtherDeleteList);

        //资源文件需要读进来,因为是发布前生成的
        List <string> ResModifList  = null;
        List <string> ResDeleteList = null;

        ReadDetailFile(GetResDetailFileNamePath(), ref ResModifList, ref ResDeleteList);

        EditorLog.LogInfo("正在备份发布文件....", true);
        string BackUpFileFloder = "PackingFileBackUp/";

        BackUpFileFloder += DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "/";

        BackUpFiles_First(BackUpFileFloder);

        Dictionary <string, AssetBundleManager.PackageNode> NewResFileList   = new Dictionary <string, AssetBundleManager.PackageNode>();
        Dictionary <string, AssetBundleManager.PackageNode> NewOtherFileList = new Dictionary <string, AssetBundleManager.PackageNode>();

        AssetBundleManager.LoadPackageList(GetEditorAssetPackagePatchRoot() + AssetBundleManager.AssetPackageListPatch, NewResFileList, NewOtherFileList);

        CorrectRunTimeAssetFile(NewResFileList);

        EncodeFile(NewResFileList, NewOtherFileList, ResModifList, ResDeleteList, OtherModifList, OtherDeleteList, debugVersion, forceEncodeFile);

        NewResFileList.Clear();
        NewOtherFileList.Clear();

        DeleteFileHelper(GetResDetailFileNamePath());
        DeleteFileHelper(GetOtherDetailFileNamePath());
        BackUpFiles_Second(BackUpFileFloder);
    }
    void OnFlow_OnBuildingEXE(bool isDebug, bool is64bit)
    {
        ReleaseBuildingEXECommand();

        if (isDebug)
        {
            EditorLog.StartLog("BuildProjectLog", EditorLog.LogLevel.ERROR);
            //备份文件
            CopyFileHelper(GetClient_GamePathRoot() + ResDetailFileName, GetBuildFlowFloderPathRoot() + ResDetailFileName);

            //告知流程--告知崩溃,如果没有崩溃,后面会删除
            CreateFileHelper(GetBuildProjectCarshFlagsPath());

            OnBuildProjectStart();

            BuildProject_Impl(isDebug, is64bit);

            if (EditorLog.isHaveFatleErrorLog)
            {
                OnBuildProjectFaild();
                EditorLog.EndLog();
                if (!File.Exists(GetRunFromOutSideProgramPath()))
                {
                    EditorUtility.DisplayDialog("致命错误", "!!!!!!Debug版本有致命错误,不能进行后续操作!!!!!!稍后会打开对应的日志路径,请将:" + EditorLog.LogPath + "发给程序.", "确定");
                    System.Diagnostics.Process.Start(Path.GetDirectoryName(EditorLog.LogPath));
                }
                OnFlow_BuildingExeFailed(isDebug, is64bit);
            }
            else if (EditorLog.isHaveErroLog)
            {
                OnBuildProjectFaild();
                EditorLog.EndLog();
                if (!File.Exists(GetRunFromOutSideProgramPath()))
                {
                    EditorUtility.DisplayDialog("发布错误", "Debug版本发布错误,稍后会打开对应的日志路径,请将:" + EditorLog.LogPath + "发给程序.", "确定");
                    System.Diagnostics.Process.Start(Path.GetDirectoryName(EditorLog.LogPath));
                }
                OnFlow_BuildingExeFailed(isDebug, is64bit);
            }
            else
            {
                OnBuildProjectSuccess();
                OnFlow_BuildingExeSuccess(isDebug, is64bit);
                EditorLog.LogInfo("工程发布成功!!!!!!!!!!!!!!!!", true);
            }
            EditorLog.EndLog();
        }
        else
        {
            EditorLog.StartLog("BuildProjectLog", EditorLog.LogLevel.ERROR);
            OnBuildProjectStart();
            CopyFileHelper(GetClient_GamePathRoot() + ResDetailFileName, GetBuildFlowFloderPathRoot() + ResDetailFileName);

            BuildProject_Impl(isDebug, is64bit);

            if (EditorLog.isHaveFatleErrorLog)
            {
                OnBuildProjectFaild();

                EditorLog.EndLog();
                if (!File.Exists(GetRunFromOutSideProgramPath()))
                {
                    EditorUtility.DisplayDialog("致命错误", "!!!Release版本有致命错误,不能进行后续操作!!!稍后会打开对应的日志路径,请将:" + EditorLog.LogPath + "发给程序.", "确定");
                    System.Diagnostics.Process.Start(Path.GetDirectoryName(EditorLog.LogPath));
                }
                OnFlow_BuildingExeFailed(isDebug, is64bit);
            }
            else if (EditorLog.isHaveErroLog)
            {
                OnBuildProjectFaild();

                EditorLog.EndLog();
                if (!File.Exists(GetRunFromOutSideProgramPath()))
                {
                    EditorUtility.DisplayDialog("发布错误", "Release版本发布错误,稍后会打开对应的日志路径,请将:" + EditorLog.LogPath + "发给程序.", "确定");
                    System.Diagnostics.Process.Start(Path.GetDirectoryName(EditorLog.LogPath));
                }
                OnFlow_BuildingExeFailed(isDebug, is64bit);
            }
            else
            {
                OnBuildProjectSuccess();

                OnFlow_BuildingExeSuccess(isDebug, is64bit);
                EditorLog.LogInfo("工程发布成功!!!!!!!!!!!!!!!!", true);
            }
            EditorLog.EndLog();
        }
    }
    /// <summary>
    /// 打包流程
    /// </summary>
    void OnFlow_PackingAssetPackage(bool is64bit)
    {
        /*
         * 1.开始流程要创建文件,需要备份资源文件列表
         */

        ReleasePackignAssetPackageCommand();

        //备份资源列表文件
        CopyFileHelper(GetEditorAssetPackagePatchRoot() + AssetBundleManager.AssetPackageListPatch, GetBuildFlowPackageListPath());

        //告知流程--告知崩溃,如果没有崩溃,后面会删除
        CreateFileHelper(GetBuildFlowPackingAssetPackageCarshFlagsPath());

        EditorLog.StartLog("BuildPacakgeLog", EditorLog.LogLevel.ERROR);
        OnBuildFullPackageStart();


        BuildFullPackage_Impl(is64bit);

        if (EditorLog.isHaveFatleErrorLog)
        {
            //打包失败
            OnBuildFullPackageFaild();

            //告知流程--资源发布失败
            CreateFileHelper(GetBuildFlowPackingAssetPackageFaildPath());
            //告知流程--资源发布没有崩溃
            DeleteFileHelper(GetBuildFlowPackingAssetPackageCarshFlagsPath());

            EditorLog.EndLog();
            if (!File.Exists(GetRunFromOutSideProgramPath()))
            {
                EditorUtility.DisplayDialog("致命错误", "!!!!资源有致命错误,不可进行后续从左!!!!稍后会打开对应的日志路径,请将:" + EditorLog.LogPath + "发给程序.", "确定");
                System.Diagnostics.Process.Start(Path.GetDirectoryName(EditorLog.LogPath));
            }
        }
        else if (EditorLog.isHaveErroLog)
        {
            //打包失败
            OnBuildFullPackageFaild();

            //告知流程--资源发布失败
            CreateFileHelper(GetBuildFlowPackingAssetPackageFaildPath());
            //告知流程--资源发布没有崩溃
            DeleteFileHelper(GetBuildFlowPackingAssetPackageCarshFlagsPath());

            EditorLog.EndLog();
            if (!File.Exists(GetRunFromOutSideProgramPath()))
            {
                EditorUtility.DisplayDialog("资源错误", "资源打包错误,稍后会打开对应的日志路径,请将:" + EditorLog.LogPath + "发给程序.", "确定");
                System.Diagnostics.Process.Start(Path.GetDirectoryName(EditorLog.LogPath));
            }
        }
        else
        {
            //打包成功
            OnBuildFullPackageSuccess();
            //告知流程--资源发布成功
            CreateFileHelper(GetBuildFlowPackingAssetPackageSuccessdPath());
            //告知流程--资源发布没有崩溃
            DeleteFileHelper(GetBuildFlowPackingAssetPackageCarshFlagsPath());
        }

        if (NeedToExitEditor)
        {
            EditorApplication.Exit(0);
        }
    }
    public static void BuildFullPackage_Impl(bool Version_64Bit)
    {
        if (!Is64bitEditor)
        {
            Debug.LogError("发布只能使用64位编辑器");
            return;
        }
        //if (!Is64BitNativeDll("game.dll") && Version_64Bit)
        //{
        //    Debug.LogError("NativeDLL不是64位版本");
        //    return;
        //}
        //if (Is64BitNativeDll("game.dll") && !Version_64Bit)
        //{
        //    Debug.LogError("NativeDLL不是32位版本");
        //    return;
        //}

        //DestroyAllBuiltInMaterial();
        //DestroyAllBuiltInShader();
        isBuildingPackage = true;
        Console.Clear();

        SaveAndRefershAssets();

        Dictionary <string, AssetBundleManager.PackageNode> OldResFileList   = new Dictionary <string, AssetBundleManager.PackageNode>();
        Dictionary <string, AssetBundleManager.PackageNode> OldOtherFileList = new Dictionary <string, AssetBundleManager.PackageNode>();

        //打包之前,先吧资源列表加载进来,后面用于做更新对比
        AssetBundleManager.LoadPackageList(GetEditorAssetPackagePatchRoot() + AssetBundleManager.AssetPackageListPatch, OldResFileList, OldOtherFileList);

        /*
         * 先生成预制体配置,因为有的资源再导入之前是没有assetbundle的
         */
        EditorLog.LogInfo("正在计算预制体信息....", true);
        if (BuildPrePrefabConfig || BuildAll)
        {
            PreGeneratePrefabConfig();
            SaveAndRefershAssets();
        }

        if (BuildPacakage || BuildAll)
        {
            EditorLog.LogInfo("正在打包资源文件....", true);

            if (!System.IO.Directory.Exists(AssetBundleManager.FullAssetPackagePathRoot) && !File.Exists(AssetBundleManager.FullAssetPackagePathRoot))
            {
                System.IO.Directory.CreateDirectory(AssetBundleManager.FullAssetPackagePathRoot);
            }

            BuildPipeline.BuildAssetBundles(AssetBundleManager.FullAssetPackagePathRoot, BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.DeterministicAssetBundle, Version_64Bit ? BuildTarget.StandaloneWindows64 : BuildTarget.StandaloneWindows);
            SaveAndRefershAssets();
        }



        BuildCurrAssetBundleList();

        if (BuildUIConfig || BuildAll)
        {
            EditorLog.LogInfo("正在计算UI配置....", true);
            GenerateUIConfig();
        }
        if (BuildSceneConfig || BuildAll)
        {
            EditorLog.LogInfo("正在计算场景配置....", true);
            GenerateScenConfig();
        }

        if (BuildScheme || BuildAll)
        {
            EditorLog.LogInfo("正在计算Scheme....", true);
            GenerateScheme();
            ExportLightingEffectConfig();
        }

        if (BuildPostPrefabConfig || BuildAll)
        {
            EditorLog.LogInfo("正在合并资源文件....", true);
            PostGeneratePrefabConfig();
        }

        if (BuildAssetsInfo || BuildAll)
        {
            EditorLog.LogInfo("正在计算资源信息....", true);
            GenerateEditorAssetInfo(OldResFileList, OldOtherFileList);
        }

        SaveAndRefershAssets();
        //DeleteMainfainstFile(GetEditorAssetPackagePatchRoot());
        isBuildingPackage = false;

        EditorLog.LogInfo("正在修复打包错误文件...", true);

        if (AssetBundleImporterFixedEditor.DoImporterFixed("CopyEditorLog_BuildPackage.log", "FixedFillPathInfo_BuildPackage.txt"))
        {
            foreach (AssetBundleImporterFixedEditor.FixedPathNode path in AssetBundleImporterFixedEditor.FixedFilePath)
            {
                EditorLog.LogInfo("修复文件成功:" + path.getDesc() + ",可重新打包或者下次打包...", true);
            }

            CreateFileHelper(GetCommand_NeedToRePackingAssets());
        }
        else
        {
            EditorLog.LogInfo("没有发现需要修复的文件...", true);
        }
    }
示例#8
0
    private static void ProcessEncodeFileNode(PackageNodeType packageType, string ModifPath, ref Dictionary <string, AssetBundleManager.PackageNode> resultTable)
    {
        if (packageType == PackageNodeType.AssetsBundleFile)
        {
            string s           = AssetBundleManager.FullAssetPackagePathRoot + ModifPath;
            string RunTimePath = GetRunTimeAssetPackagePatchRoot() + ModifPath;

            //配置文件直接
            if (IsConfigFile(s))
            {
                EnCodeAssetConfigFileHelper(s, RunTimePath);
            }
            else
            {
                EnCodeAssetFileHelper(s, RunTimePath);
            }
            AssetFileInfo info = GetFileInfo(RunTimePath);
            if (null == info)
            {
                return;
            }

            if (info.fileLengthInBytes <= 0)
            {
                EditorLog.LogFatleError("文件为空:" + RunTimePath);
                return;
            }

            AssetBundleManager.PackageNode nod;
            if (resultTable.TryGetValue(ModifPath, out nod))
            {
                nod.md5                = info.md5;
                nod.fileSize           = info.fileLengthInMB;
                resultTable[ModifPath] = nod;
            }
            else
            {
                nod     = new AssetBundleManager.PackageNode();
                nod.md5 = info.md5;
                nod.assetBundlePatch = ModifPath;
                nod.fileSize         = info.fileLengthInMB;
                resultTable.Add(ModifPath, nod);
            }
        }
        else if (packageType == PackageNodeType.OtherFile)
        {
            string s = GetRunTimeBinPatchRoot() + ModifPath;

            //只对C#的代码进行加密
            if (IsManagedScript(s))
            {
                EnCodeScriptHelper(s, s);
            }


            AssetFileInfo info = GetFileInfo(s);
            if (null == info)
            {
                return;
            }
            if (info.fileLengthInBytes <= 0)
            {
                EditorLog.LogFatleError("文件为空:" + s);
                return;
            }
            AssetBundleManager.PackageNode nod;
            if (resultTable.TryGetValue(ModifPath, out nod))
            {
                nod.md5                = info.md5;
                nod.fileSize           = info.fileLengthInMB;
                resultTable[ModifPath] = nod;
            }
            else
            {
                nod     = new AssetBundleManager.PackageNode();
                nod.md5 = info.md5;
                nod.assetBundlePatch = ModifPath;
                nod.fileSize         = info.fileLengthInMB;
                resultTable.Add(ModifPath, nod);
            }
        }
    }
示例#9
0
    public static void ExportLightEffect(bool autoBulid = true)
    {
        Clear();

        if (string.IsNullOrEmpty(configPath))
        {
            configPath = Application.dataPath + schemePath;
        }

        if (!Directory.Exists(configPath))
        {
            if (autoBulid)
            {
                EditorLog.LogError("光效配置根目录不存在!");
            }
            else
            {
                EditorUtility.DisplayDialog("配置导出", "光效配置根目录不存在,请检查!", "OK");
            }

            return;
        }

        string[] schemeArray = Directory.GetFiles(configPath, "*" + schemeExtension, SearchOption.AllDirectories);
        foreach (string strSchemePath in schemeArray)
        {
            if (string.IsNullOrEmpty(strSchemePath) || !strSchemePath.EndsWith(schemeExtension))
            {
                continue;
            }

            string strTempPath = strSchemePath.Replace(@"\", "/");
            strTempPath = strTempPath.Substring(strTempPath.IndexOf("Assets"));

            UnityEngine.Object schemeObj = AssetDatabase.LoadAssetAtPath(@strTempPath, typeof(UnityEngine.Object));
            if (schemeObj != null)
            {
                LightingEffect scheme = schemeObj as LightingEffect;
                if (scheme != null)
                {
                    LightingEffectConfigType type = scheme.GetEffectType();
                    if (!lightEffectConfigMap.ContainsKey(type))
                    {
                        lightEffectConfigMap.Add(type, new List <LightingEffect>());
                    }

                    lightEffectConfigMap[type].Add(scheme);
                }
            }
        }

        lightEffectConfigMap = lightEffectConfigMap.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);

        InitStreamWriter();

        foreach (KeyValuePair <LightingEffectConfigType, List <LightingEffect> > kvp in lightEffectConfigMap)
        {
            WriteSchemeHead(kvp.Key);

            foreach (LightingEffect item in kvp.Value)
            {
                ExportScheme(kvp.Key, item);
            }

            FlushStreamWriter();
        }

        FreeStreamWriter();
        Clear();

        if (!autoBulid)
        {
            EditorUtility.DisplayDialog("配置导出", "光效配置导出完成!", "OK");
        }
    }