示例#1
0
        /// <summary>
        /// Write metadata files into the build directory
        /// </summary>
        /// <param name="outputPath"></param>
        void WriteMetadataFile(string outputPath, string buildGUID)
        {
            try
            {
                // dependencies.txt: list of "depepedency@version"
                string dependenciesFilePath = $"{outputPath}/dependencies.txt";

                using (StreamWriter streamWriter = new StreamWriter(dependenciesFilePath, false))
                {
                    PackageManagerProxy.GetAllVisiblePackages()
                    .Select(pkg => $"{pkg.name}@{pkg.version}")
                    // We probably don't have the package.json of the used Microgame available,
                    // so add the information manually
                    .Concat(new[] { $"{PackageManagerProxy.GetApplicationIdentifier() ?? Application.productName}@{Application.version}" })
                    .Distinct()
                    .ToList()
                    .ForEach(streamWriter.WriteLine);
                }

                // The Unity version used
                string versionFilePath = $"{outputPath}/ProjectVersion.txt";
                File.Copy("ProjectSettings/ProjectVersion.txt", versionFilePath, true);

                string guidFilePath = $"{outputPath}/GUID.txt";
                File.WriteAllText(guidFilePath, buildGUID);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
        public void OnPostprocessBuild(BuildReport report)
        {
            if (report.summary.platform == BuildTarget.WebGL)
            {
                StoreFactory.get().Dispatch(new BuildFinishAction
                {
                    outputDir = report.summary.outputPath,
                    buildGUID = report.summary.guid.ToString()
                });

                // Write metadate files into the build directory
                try
                {
                    // depdendencies.txt: list of "depepedency@version"
                    var depFile = $"{report.summary.outputPath}/dependencies.txt";
                    using (var sw = new StreamWriter(depFile, false))
                    {
                        PackageManagerProxy.GetAllVisiblePackages()
                        .Select(pkg => $"{pkg.name}@{pkg.version}")
                        // We probably don't have the package.json of the used Microgame available
                        // so add the information manually.
                        .Concat(new [] { $"{PackageManagerProxy.GetApplicationIdentifier()}@{Application.version}" })
                        .Distinct()
                        .ToList()
                        .ForEach(depStr => sw.WriteLine(depStr));
                    }

                    // The used Unity version.
                    var verFile = $"{report.summary.outputPath}/ProjectVersion.txt";
                    File.Copy("ProjectSettings/ProjectVersion.txt", verFile, overwrite: true);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }
        }