コード例 #1
0
    private static void CompileTest(BuildTarget buildTarget, BuildTargetGroup buildTargetGroup, bool isDevelopmentBuild)
    {
        const string tempBuildPath = "Temp/CompileTest";

        var settings = new ScriptCompilationSettings
        {
            target  = buildTarget,
            group   = buildTargetGroup,
            options = isDevelopmentBuild ? ScriptCompilationOptions.DevelopmentBuild : ScriptCompilationOptions.None
        };

        var result = PlayerBuildInterface.CompilePlayerScripts(settings, tempBuildPath);

        if (result.assemblies == null || !result.assemblies.Any() || result.typeDB == null)
        {
            throw new Exception("compile error");
        }

        Debug.Log($"Compile Test Success! - BuildTarget: {settings.target}");

        // NOTE: tempBuildPathにはコンパイル後のDLLが吐き出されている
        if (Directory.Exists(tempBuildPath))
        {
            Directory.Delete(tempBuildPath, true);
        }
    }
コード例 #2
0
        private List <string> GetPlayerAssemblies()
        {
            List <string> assemblies = new List <string>();

#if UNITY_2018_2_OR_NEWER
            var outputFolder = FileUtil.GetUniqueTempPathInProject();
            if (Directory.Exists(outputFolder))
            {
                Directory.Delete(outputFolder, true);
            }

            ScriptCompilationSettings input = new ScriptCompilationSettings();
            input.target = EditorUserBuildSettings.activeBuildTarget;
            input.@group = EditorUserBuildSettings.selectedBuildTargetGroup;

            var compilationResult = PlayerBuildInterface.CompilePlayerScripts(input, outputFolder);
            foreach (var assembly in compilationResult.assemblies)
            {
                assemblies.Add(Path.Combine(outputFolder, assembly));
            }
#else
            // fallback to CompilationPipeline assemblies
            foreach (var playerAssembly in m_PlayerAssemblies)
            {
                assemblies.Add(playerAssembly.outputPath);
            }
#endif
            return(assemblies);
        }
コード例 #3
0
    static void BuildAllAssetBundles()
    {
        string assetBundleDirectory = "Assets/AssetBundles";

        if (!Directory.Exists(assetBundleDirectory))
        {
            Directory.CreateDirectory(assetBundleDirectory);
        }

        CompilationPipeline.compilationFinished += OnCompilationFinished;

        var input = new ScriptCompilationSettings
        {
            target = BuildTarget.StandaloneWindows,
            group  = BuildTargetGroup.Standalone,
        };

        string dllpath = $"{Application.streamingAssetsPath}/Assemblies";

        if (!Directory.Exists(Application.streamingAssetsPath))
        {
            Directory.CreateDirectory(Application.streamingAssetsPath);
        }

        PlayerBuildInterface.CompilePlayerScripts(input, dllpath);

        BuildPipeline.BuildAssetBundles(assetBundleDirectory,
                                        BuildAssetBundleOptions.None,
                                        BuildTarget.StandaloneWindows);

        string source = $"{assetBundleDirectory}/valheimtwitchgui";
        string target = $"{destDir}\\valheimtwitchgui";

        FileUtil.ReplaceFile(source, target);
    }
コード例 #4
0
    public static void CheckCompilePlayerScripts_Win64()
    {
        ScriptCompilationSettings settings = new ScriptCompilationSettings();

        settings.target  = BuildTarget.StandaloneWindows64;
        settings.group   = BuildTargetGroup.Standalone;
        settings.options = ScriptCompilationOptions.None;
        CheckCompilePlayerScripts(settings);
    }
コード例 #5
0
        public static bool CompilePlayerScripts(BuildTarget buildTarget, ScriptCompilationOptions options, string outputFolder, bool displayUI, out ScriptCompilationResult result)
        {
            ScriptCompilationSettings settings = new ScriptCompilationSettings();

            settings.target  = buildTarget;
            settings.group   = BuildPipeline.GetBuildTargetGroup(buildTarget);
            settings.options = options;
            return(CompilePlayerScripts(settings, outputFolder, displayUI, out result));
        }
コード例 #6
0
    public static ScriptCompilationResult CompileScripts()
    {
        ScriptCompilationSettings input = new ScriptCompilationSettings();

        input.target       = EditorUserBuildSettings.activeBuildTarget;
        input.targetGroup  = EditorUserBuildSettings.selectedBuildTargetGroup;
        input.options      = ScriptCompilationOptions.None;
        input.outputFolder = "Library/ScriptAssemblies";
        return(PlayerBuildInterface.CompilePlayerScripts(input));
    }
コード例 #7
0
ファイル: ILFixEditor.cs プロジェクト: zxsean/InjectFix
        //生成特定平台的patch
        public static void GenPlatformPatch(Platform platform, string patchOutputDir,
                                            string corePath = "./Assets/Plugins/IFix.Core.dll")
        {
            var outputDir = "Temp/ifix";

            Directory.CreateDirectory("Temp");
            Directory.CreateDirectory(outputDir);
#if UNITY_2018_3_OR_NEWER
            ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();
            if (platform == Platform.android)
            {
                scriptCompilationSettings.group  = BuildTargetGroup.Android;
                scriptCompilationSettings.target = BuildTarget.Android;
            }
            else if (platform == Platform.ios)
            {
                scriptCompilationSettings.group  = BuildTargetGroup.iOS;
                scriptCompilationSettings.target = BuildTarget.iOS;
            }
            else
            {
                scriptCompilationSettings.group  = BuildTargetGroup.Standalone;
                scriptCompilationSettings.target = BuildTarget.StandaloneWindows;
            }

            ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, outputDir);

            foreach (var assembly in injectAssemblys)
            {
                if (!Directory.Exists(patchOutputDir))
                {
                    Directory.CreateDirectory(patchOutputDir);
                }

                GenPatch(assembly, string.Format("{0}/{1}.dll", outputDir, assembly),
                         "./Assets/Plugins/IFix.Core.dll", string.Format("{0}{1}.patch.bytes", patchOutputDir, assembly));
            }
#else
            throw new NotImplementedException();
            //var compileArgFile = "Temp/ifix/unity_" + platform + "_compile_argument";
            //var tmpDllPath = "Temp/ifix/Assembly-CSharp.dll";
            //File.WriteAllText(compileArgFile, getCompileArguments(platform, tmpDllPath));
            //先编译dll到Temp目录下
            //Compile(compileArgFile);
            //对编译后的dll生成补丁
            //GenPatch("Assembly-CSharp", tmpDllPath, corePath, patchPath);

            //File.Delete(compileArgFile);
            //File.Delete(tmpDllPath);
            //File.Delete(tmpDllPath + ".mdb");
#endif
        }
コード例 #8
0
        /// <summary>
        /// 检测代码
        /// </summary>
        /// <returns></returns>
        public static bool CheckCode()
        {
            //检查下打包前的代码错
            var setting = new ScriptCompilationSettings();

            setting.options = ScriptCompilationOptions.Assertions;
            setting.target  = BuildTarget.Android;
            var ret = PlayerBuildInterface.CompilePlayerScripts(setting, BApplication.Library + "/BuildTest");

            if (ret.assemblies.Contains("Assembly-CSharp.dll"))
            {
                return(true);
            }
            return(false);
        }
コード例 #9
0
    public static void CompilerCode()
    {
        Debug.Log("<<<compiling code<<<<");
        ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();

        scriptCompilationSettings.target  = BuildTarget.StandaloneWindows64;
        scriptCompilationSettings.group   = BuildTargetGroup.Standalone;
        scriptCompilationSettings.options = ScriptCompilationOptions.DevelopmentBuild;
        string dllpath = Application.streamingAssetsPath + "/my.dll";

        if (!Directory.Exists(Application.streamingAssetsPath))
        {
            Directory.CreateDirectory(Application.streamingAssetsPath);
        }
        PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, dllpath);
        Debug.Log("<<<compiling code<<<<");
    }
コード例 #10
0
        private static void Check(BuildTarget target)
        {
            var group = BuildPipeline.GetBuildTargetGroup(target);

            var input = new ScriptCompilationSettings
            {
                target = target,
                group  = group,
            };

            PlayerBuildInterface.CompilePlayerScripts(input, OUTPUT_FOLDER);

            if (Directory.Exists(OUTPUT_FOLDER))
            {
                Directory.Delete(OUTPUT_FOLDER, true);
            }
        }
コード例 #11
0
    private static void CheckCompilePlayerScripts(ScriptCompilationSettings settings)
    {
        EditorUtility.DisplayProgressBar("Check Compile Player Scripts", "Do not operate the computer", 0);
        ScriptCompilationResult result = PlayerBuildInterface.CompilePlayerScripts(settings, string.Format("{0}/Unity_{1}/", System.IO.Path.GetTempPath(), GUID.Generate()));

        EditorUtility.ClearProgressBar();

        if ((result.assemblies == null ||
             result.assemblies.Count == 0) &&
            result.typeDB == null)
        {
            EditorUtility.DisplayDialog("Check Compile Player Scripts", "Failed\nSee Console Window", "OK");
        }
        else
        {
            EditorUtility.DisplayDialog("Check Compile Player Scripts", "Success", "OK");
        }
    }
コード例 #12
0
        //生成特定平台的patch
        public static void GenPlatformPatch(Platform platform, string patchOutputDir,
                                            string corePath = CoreDllPath)
        {
            var outputDir = "Temp/ifix";

            Directory.CreateDirectory("Temp");
            Directory.CreateDirectory(outputDir);
#if UNITY_2018_3_OR_NEWER
            ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();
            if (platform == Platform.android)
            {
                scriptCompilationSettings.group  = BuildTargetGroup.Android;
                scriptCompilationSettings.target = BuildTarget.Android;
            }
            else if (platform == Platform.ios)
            {
                scriptCompilationSettings.group  = BuildTargetGroup.iOS;
                scriptCompilationSettings.target = BuildTarget.iOS;
            }
            else
            {
                scriptCompilationSettings.group  = BuildTargetGroup.Standalone;
                scriptCompilationSettings.target = BuildTarget.StandaloneWindows;
            }

            ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, outputDir);

            // 走自定义生成补丁函数,统一处理
            CustomizedGenPatch();
#else
            throw new NotImplementedException();
            //var compileArgFile = "Temp/ifix/unity_" + platform + "_compile_argument";
            //var tmpDllPath = "Temp/ifix/Assembly-CSharp.dll";
            //File.WriteAllText(compileArgFile, getCompileArguments(platform, tmpDllPath));
            //先编译dll到Temp目录下
            //Compile(compileArgFile);
            //对编译后的dll生成补丁
            //GenPatch("Assembly-CSharp", tmpDllPath, corePath, patchPath);

            //File.Delete(compileArgFile);
            //File.Delete(tmpDllPath);
            //File.Delete(tmpDllPath + ".mdb");
#endif
        }
コード例 #13
0
        IEnumerable <string> CompilePlayerAssemblies(Assembly[] assemblies, IProgressBar progressBar = null)
        {
            if (progressBar != null)
            {
                var numAssemblies = assemblies.Length;
                progressBar.Initialize("Assembly Compilation", "Compiling project scripts",
                                       numAssemblies);
                m_OnAssemblyCompilationStarted = s =>
                {
                    // The compilation pipeline might compile Editor-specific assemblies
                    // let's advance the progress bar only for Player ones.
                    var assemblyName = Path.GetFileNameWithoutExtension(s);
                    if (assemblies.FirstOrDefault(asm => asm.name.Equals(assemblyName)) != null)
                    {
                        progressBar.AdvanceProgressBar(assemblyName);
                    }
                };
                CompilationPipeline.assemblyCompilationStarted += m_OnAssemblyCompilationStarted;
            }
            CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;

            m_OutputFolder = FileUtil.GetUniqueTempPathInProject();

            var input = new ScriptCompilationSettings
            {
                target = EditorUserBuildSettings.activeBuildTarget,
                group  = EditorUserBuildSettings.selectedBuildTargetGroup
            };

            var compilationResult = PlayerBuildInterface.CompilePlayerScripts(input, m_OutputFolder);

            if (progressBar != null)
            {
                progressBar.ClearProgressBar();
            }

            if (!m_Success)
            {
                Dispose();
                throw new AssemblyCompilationException();
            }

            return(compilationResult.assemblies.Select(assembly => Path.Combine(m_OutputFolder, assembly)));
        }
コード例 #14
0
    public static void BuildDll()
    {
        string outputDir = ".";
        var    target    = EditorUserBuildSettings.activeBuildTarget;
        var    group     = BuildPipeline.GetBuildTargetGroup(target);

        ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();

        scriptCompilationSettings.group  = group;
        scriptCompilationSettings.target = target;
        var buildDir = $"{outputDir}/build";

        if (false == Directory.Exists(buildDir))
        {
            Directory.CreateDirectory(buildDir);
        }
        ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, buildDir);

        //MoveAssemblys(outputDir, buildDir, true);
    }
コード例 #15
0
        public static bool CompileAssemblies()
        {
#if UNITY_2018_2_OR_NEWER
            var path = compiledAssemblyPaths.FirstOrDefault();
            if (!string.IsNullOrEmpty(path))
            {
                Directory.Delete(Path.GetDirectoryName(path), true);
            }
            compiledAssemblyPaths.Clear();
            var outputFolder = FileUtil.GetUniqueTempPathInProject();
            if (Directory.Exists(outputFolder))
            {
                Directory.Delete(outputFolder, true);
            }

            ScriptCompilationSettings input = new ScriptCompilationSettings
            {
                target = EditorUserBuildSettings.activeBuildTarget,
                @group = EditorUserBuildSettings.selectedBuildTargetGroup
            };

            var compilationResult = PlayerBuildInterface.CompilePlayerScripts(input, outputFolder);

            foreach (var assembly in compilationResult.assemblies)
            {
                compiledAssemblyPaths.Add(Path.Combine(outputFolder, assembly));
            }

            return(compilationResult.assemblies.Count > 0);
#else
            compiledAssemblyPaths.Clear();
            // fallback to CompilationPipeline assemblies
            foreach (var playerAssembly in CompilationPipeline.GetAssemblies().Where(a => a.flags != AssemblyFlags.EditorAssembly))
            {
                compiledAssemblyPaths.Add(playerAssembly.outputPath);
            }

            return(true);
#endif
        }
コード例 #16
0
ファイル: ILFixEditor.cs プロジェクト: MF-JIN/test
        //生成特定平台的patch
        public static void GenPlatformPatch(BuildTargetGroup group, BuildTarget buildTarget,
                                            string corePath = IFixCoreDllPath)
        {
#if UNITY_2018_3_OR_NEWER
            RuntimePlatform           rplatform;
            ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings()
            {
                group  = group,
                target = buildTarget,
            };

            var patchOutputDir = $"Assets/AppRes/ifix/{IFixCfg.TargetName(buildTarget)}/";
            Directory.CreateDirectory(patchOutputDir);

            var assemblyOutputDir = $"obj/{IFixCfg.TargetName(buildTarget)}/";
            Directory.CreateDirectory(assemblyOutputDir);
            ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, assemblyOutputDir);

            foreach (var assembly in injectAssemblys)
            {
                GenPatch(assembly, string.Format("{0}/{1}.dll", assemblyOutputDir, assembly),
                         IFixCoreDllPath, string.Format("{0}{1}.patch.ifix", patchOutputDir, assembly));
            }
#else
            throw new NotImplementedException();
            //var compileArgFile = "Temp/ifix/unity_" + platform + "_compile_argument";
            //var tmpDllPath = "Temp/ifix/Assembly-CSharp.dll";
            //File.WriteAllText(compileArgFile, getCompileArguments(platform, tmpDllPath));
            //先编译dll到Temp目录下
            //Compile(compileArgFile);
            //对编译后的dll生成补丁
            //GenPatch("Assembly-CSharp", tmpDllPath, corePath, patchPath);

            //File.Delete(compileArgFile);
            //File.Delete(tmpDllPath);
            //File.Delete(tmpDllPath + ".mdb");
#endif
        }
コード例 #17
0
        /// <returns>是否成功</returns>
        public static bool CompilePlayerScripts(ScriptCompilationSettings settings, string outputFolder, bool displayUI, out ScriptCompilationResult result)
        {
            if (displayUI)
            {
                EditorUtility.DisplayProgressBar($"Compile Player Scripts ({settings.target})", "Do not operate the computer", 0);
            }
            result = PlayerBuildInterface.CompilePlayerScripts(settings, outputFolder);
            EditorUtility.ClearProgressBar();

            if (result.assemblies != null &&
                result.assemblies.Count > 0 &&
                result.typeDB != null)
            {
                if (settings.target == EditorUserBuildSettings.activeBuildTarget)
                {
                    s_CurrentTargetTypeDBCache = result.typeDB;
                }

                if (displayUI)
                {
                    EditorUtility.DisplayDialog("Check Compile Player Scripts"
                                                , $"Success\n{settings.target}: {settings.options}"
                                                , "OK");
                }
                return(true);
            }
            else
            {
                if (displayUI)
                {
                    EditorUtility.DisplayDialog("Check Compile Player Scripts"
                                                , $"Failed\n{settings.target}: {settings.options}\nSee Console Window"
                                                , "OK");
                }
                return(false);
            }
        }
コード例 #18
0
        // 采用新的ScriptableBuildPipeline
        private static void InternalScriptableBuildAndPushDll()
        {
            EditorUtility.DisplayProgressBar("BuildingDll", "Building Dll...", 0);

            string projectPath  = Application.dataPath.Replace("Assets", "");
            string srcDllFolder = $@"{projectPath}AndroidDll/{Application.productName}";
            ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();

            scriptCompilationSettings.group  = BuildTargetGroup.Android;
            scriptCompilationSettings.target = BuildTarget.Android;
            try
            {
                ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, srcDllFolder);
                string srcDllPath = $@"{srcDllFolder}/{DLL_NAME}";
                PushDll(srcDllPath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            EditorUtility.ClearProgressBar();
        }
コード例 #19
0
ファイル: CompileCheck.cs プロジェクト: su10/Unity-AsReadOnly
        private static void Check(BuildTarget target, BuildTargetGroup group)
        {
            var input = new ScriptCompilationSettings
            {
                target = target,
                group  = group,
            };

            var result     = PlayerBuildInterface.CompilePlayerScripts(input, OUTPUT_FOLDER);
            var assemblies = result.assemblies;

            var isSuccess =
                assemblies != null &&
                assemblies.Count != 0 &&
                result.typeDB != null
            ;

            if (Directory.Exists(OUTPUT_FOLDER))
            {
                Directory.Delete(OUTPUT_FOLDER, true);
            }

            Assert.IsTrue(isSuccess);
        }
コード例 #20
0
        public IEnumerable <AssemblyInfo> Compile(IProgressBar progressBar = null)
        {
#if UNITY_2018_1_OR_NEWER
            var assemblies = CompilationPipeline.GetAssemblies(AssembliesType.Player);
#else
            var assemblies = CompilationPipeline.GetAssemblies();
#endif

#if UNITY_2018_2_OR_NEWER
            if (progressBar != null)
            {
                var numAssemblies = assemblies.Length;
                progressBar.Initialize("Assembly Compilation", "Compiling project scripts",
                                       numAssemblies);
                m_OnAssemblyCompilationStarted = (s) =>
                {
                    progressBar.AdvanceProgressBar(Path.GetFileName(s));
                };
                CompilationPipeline.assemblyCompilationStarted += m_OnAssemblyCompilationStarted;
            }
            CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;

            m_OutputFolder = FileUtil.GetUniqueTempPathInProject();

            var input = new ScriptCompilationSettings
            {
                target = EditorUserBuildSettings.activeBuildTarget,
                group  = EditorUserBuildSettings.selectedBuildTargetGroup
            };

            var compilationResult = PlayerBuildInterface.CompilePlayerScripts(input, m_OutputFolder);

            if (progressBar != null)
            {
                progressBar.ClearProgressBar();
            }

            if (!m_Success)
            {
                Dispose();
                throw new AssemblyCompilationException();
            }

            var compiledAssemblyPaths = compilationResult.assemblies.Select(assembly => Path.Combine(m_OutputFolder, assembly));
#else
            // fallback to CompilationPipeline assemblies
            var compiledAssemblyPaths = CompilationPipeline.GetAssemblies()
                                        .Where(a => a.flags != AssemblyFlags.EditorAssembly).Select(assembly => assembly.outputPath);
#endif

            var assemblyInfos = new List <AssemblyInfo>();
            foreach (var compiledAssemblyPath in compiledAssemblyPaths)
            {
                var assemblyInfo = AssemblyHelper.GetAssemblyInfoFromAssemblyPath(compiledAssemblyPath);
                var assembly     = assemblies.First(a => a.name.Equals(assemblyInfo.name));
                var sourcePaths  = assembly.sourceFiles.Select(file => file.Remove(0, assemblyInfo.relativePath.Length + 1));

                assemblyInfo.sourcePaths = sourcePaths.ToArray();
                assemblyInfos.Add(assemblyInfo);
            }

            return(assemblyInfos);
        }