Example #1
0
        private static void BuildVariant(IProjectSettingsController projectSettingsController, IBuildVariant buildVariant)
        {
            var tempPath = Path.Combine(Path.Combine(PluginFolder, "Temp"), Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempPath);

            Action restoreFiles = () => { };

            restoreFiles = buildVariant.MoveFiles.Where(f => f.PerformOnStage == BuildStage.BeforeBuild).
                           Aggregate(restoreFiles, (current, fileCopyInfo) =>
                                     current + MoveFile(fileCopyInfo.From, fileCopyInfo.To, fileCopyInfo.Revert ? tempPath : null));
            projectSettingsController.BuildAndApplyProjectSettings(buildVariant);
            var buildPlayerOptions = new BuildPlayerOptions {
                scenes           = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
                locationPathName = buildVariant.BuildPath,
                target           = buildVariant.BuildTarget,
                options          = buildVariant.BuildOptions
            };


            typeof(BuildPipeline).GetMethod("BuildPlayer", new [] { typeof(BuildPlayerOptions) }).
            Invoke(null, new object[] { buildPlayerOptions });

            restoreFiles();

            foreach (var fileMoveInfo in buildVariant.MoveFiles.Where(f => f.PerformOnStage == BuildStage.AfterBuild))
            {
                MoveFile(fileMoveInfo.From, fileMoveInfo.To);
            }

            if (buildVariant.MakeZip)
            {
                var folderToCompressPath = Path.HasExtension(buildVariant.BuildPath)
                    ? Path.GetDirectoryName(buildVariant.BuildPath)
                    : buildVariant.BuildPath;
                var folderName = Path.GetFileName(folderToCompressPath);
                if (folderName != null)
                {
                    using (var zip = new ZipFile())
                    {
                        zip.AddDirectory(folderToCompressPath);
                        zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                        zip.Save(Path.Combine(Directory.GetParent(folderToCompressPath).FullName, folderName + ".zip"));
                    }
                }
            }

            Directory.Delete(tempPath);

            foreach (var fileMoveInfo in buildVariant.MoveFiles.Where(f => f.PerformOnStage == BuildStage.AfterAll))
            {
                MoveFile(fileMoveInfo.From, fileMoveInfo.To);
            }
        }
 public void ActivateBuildVariant(IBuildVariant buildVariant)
 {
     _buildInfo.ActiveVariantGuid = buildVariant != null ? buildVariant.Guid : null;
     _buildInfoStorage.SaveBuildInfo(_buildInfo);
     _projectSettingsController.BuildAndApplyProjectSettings(buildVariant);
 }
Example #3
0
 private static void RollBack(IBuildInfoController buildInfoController,
                              IBuildVariantsController buildVariantsController, IProjectSettingsController projectSettingsController)
 {
     projectSettingsController.BuildAndApplyProjectSettings(buildVariantsController.BuildVariants.
                                                            First(v => v.Guid == buildInfoController.BuildInfo.ActiveVariantGuid));
 }
Example #4
0
        private void DrawSettings(IBuildVariant inspectedBuildVariant, SettingsCategory category)
        {
            string categoryName;
            Action revertAction = null;
            Action saveAction   = null;
            IEnumerable <IProjectSettingsFile> settingsFiles;

            EditorGUILayout.BeginHorizontal();
            if (category == SettingsCategory.ActualSettingsDiff || category == SettingsCategory.ActualRevertableSettingsDiff)
            {
                categoryName  = "Actual project settings diff";
                settingsFiles = _projectSettingsController.GetDiffWithActualSettings(inspectedBuildVariant);
                saveAction    = () => {
                    inspectedBuildVariant.Merge(settingsFiles);
                    _projectSettingsController.InvalidateDiffCache();
                };
                if (category == SettingsCategory.ActualRevertableSettingsDiff)
                {
                    revertAction = () => _projectSettingsController.BuildAndApplyProjectSettings(inspectedBuildVariant);
                }
            }
            else if (category == SettingsCategory.VariantDiff)
            {
                categoryName  = "Variant settings";
                settingsFiles = inspectedBuildVariant.SettingsFileDiffs;
                revertAction  = () => {
                    var currentDiff = _projectSettingsController.GetDiffWithActualSettings(inspectedBuildVariant).ToList();
                    inspectedBuildVariant.Revert();
                    _projectSettingsController.BuildAndApplyProjectSettings(inspectedBuildVariant, currentDiff);
                };
            }
            else
            {
                throw new ArgumentOutOfRangeException("category", category, null);
            }

            var expanded             = inspectedBuildVariant.IsFieldExpanded(category.ToString());
            var projectSettingsFiles = settingsFiles as IProjectSettingsFile[] ?? settingsFiles.ToArray();

            expanded = EditorGUILayout.Foldout(expanded, string.Format("{0} ({1})", categoryName, projectSettingsFiles.Length));
            inspectedBuildVariant.SetFieldExpanded(category.ToString(), expanded);

            GUI.enabled = projectSettingsFiles.Length > 0;
            DrawSaveRevert(revertAction, saveAction);
            GUI.enabled = true;

            EditorGUILayout.EndHorizontal();

            if (!expanded)
            {
                return;
            }

            foreach (var settingsFileDiff in projectSettingsFiles)
            {
                var mappingNode = settingsFileDiff.RootNode as YamlMappingNode;
                if (mappingNode != null)
                {
                    foreach (var keyValue in mappingNode.Children)
                    {
                        DrawNode(inspectedBuildVariant, settingsFileDiff, category, keyValue.Value, keyValue.Key);
                    }
                }
                else
                {
                    DrawNode(inspectedBuildVariant, settingsFileDiff, category, settingsFileDiff.RootNode);
                }
            }
        }