public void BuildAndApplyProjectSettings(IBuildVariant buildVariant,
                                          IEnumerable <IProjectSettingsFile> additionalSettings    = null,
                                          IProjectSettingsFile ignoreAdditionalProjectSettingsFile = null,
                                          YamlNode ignoreAdditionalNode = null)
 {
     if (additionalSettings == null)
     {
         additionalSettings = Enumerable.Empty <IProjectSettingsFile>();
     }
     else
     {
         if (ignoreAdditionalProjectSettingsFile != null)
         {
             additionalSettings = additionalSettings.Where(p => p.FileName != ignoreAdditionalProjectSettingsFile.FileName);
             if (ignoreAdditionalNode != null)
             {
                 additionalSettings = additionalSettings.Append(
                     new ProjectSettingsFile {
                     FileName = ignoreAdditionalProjectSettingsFile.FileName,
                     RootNode =
                         ignoreAdditionalProjectSettingsFile.RootNode.
                         Diff(ignoreAdditionalProjectSettingsFile.RootNode.GetChildBranch(ignoreAdditionalNode))
                 });
             }
         }
     }
     _projectSettingsStorage.SaveProjectSettings(
         _baseSettings.Concat(buildVariant.GetFinalProjectSettings()).
         Concat(additionalSettings).Merge().ToList());
     _actualProjectSettings = _projectSettingsStorage.LoadProjectSettings();
     InvalidateDiffCache();
 }
示例#2
0
        private void DrawVariant(IBuildVariant buildVariant, int indentLevel)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(indentLevel * 16.0f + 8.0f);
            var isVariantInActiveCollection = _buildInfoController.IsBuildVariantInActiveCollection(buildVariant);
            var newToggleValue = EditorGUILayout.Toggle("", isVariantInActiveCollection, GUILayout.Width(20));

            if (newToggleValue != isVariantInActiveCollection)
            {
                _buildInfoController.ToggleBuildVariantInActiveCollection(buildVariant, newToggleValue);
            }
            var isVariantActive   = buildVariant.Guid == _buildInfoController.BuildInfo.ActiveVariantGuid;
            var isVariantSelected = buildVariant.Guid == _buildInfoController.BuildInfo.SelectedVariantGuid;

            if (GUILayout.Button(buildVariant.VariantName + (isVariantActive ? " (Active)" : ""),
                                 isVariantSelected ? _selectedConfigurationStyle : _configurationStyle))
            {
                _buildInfoController.SelectBuildVariant(buildVariant);
            }
            GUILayout.FlexibleSpace();
            var icon = _buildTargetIcons.GetIconForBuildTarget(buildVariant.BuildTarget);

            GUILayout.Label(icon != null ? EditorGUIUtility.IconContent(icon) : new GUIContent(""),
                            _platformIconStyle);
            EditorGUILayout.EndHorizontal();

            DrawVariants(buildVariant, indentLevel + 1);
        }
示例#3
0
        public void SaveVariant(IBuildVariant buildVariant)
        {
            var serializer = new SerializerBuilder().WithTagMapping("!BuildVariant", typeof(BuildVariant)).
                             WithTagMapping("!ProjectSettingsFile", typeof(ProjectSettingsFile)).
                             WithTagMapping("!YamlMappingNode", typeof(YamlMappingNode)).
                             WithTagMapping("!YamlScalarNode", typeof(YamlScalarNode)).
                             EnsureRoundtrip().Build();

            File.WriteAllText(Path.Combine(_buildVariantsPath, buildVariant.Guid + VariantFileExtension), serializer.Serialize(buildVariant));
        }
 public IEnumerable <IProjectSettingsFile> GetDiffWithActualSettings(IBuildVariant buildVariant)
 {
     if (_cachedDiff.Key == buildVariant)
     {
         return(_cachedDiff.Value);
     }
     _cachedDiff = new KeyValuePair <IBuildVariant, IEnumerable <IProjectSettingsFile> >(buildVariant,
                                                                                         _baseSettings.Concat(buildVariant.GetFinalProjectSettings()).Diff(_actualProjectSettings));
     return(_cachedDiff.Value);
 }
示例#5
0
 private void DrawVariants(IBuildVariant parent, int indentLevel)
 {
     foreach (var variant in _buildVariantsController.BuildVariants)
     {
         if (variant.Parent != parent)
         {
             continue;
         }
         DrawVariant(variant, indentLevel);
     }
 }
示例#6
0
        private IEnumerable <IBuildVariant> GetBuildVariantsChain()
        {
            var           result             = new List <IBuildVariant>();
            IBuildVariant nextVariantInChain = this;

            while (nextVariantInChain != null)
            {
                result.Insert(0, nextVariantInChain);
                nextVariantInChain = nextVariantInChain.Parent;
            }
            return(result);
        }
        public void CreateVariant(IBuildVariant parentBuildVariant = null)
        {
            var variant = new BuildVariant {
                VariantName = "New variant",
                Guid        = System.Guid.NewGuid().ToString()
            };

            SetVariantParent(variant, parentBuildVariant == null ? "" : parentBuildVariant.Guid);
            _buildInfoController.ActivateBuildVariant(variant);
            _buildInfoController.SelectBuildVariant(variant);
            _buildVariants.Add(variant);

            SaveVariant(variant);
        }
        public void ToggleBuildVariantInActiveCollection(IBuildVariant buildVariant, bool toggleValue)
        {
            if (toggleValue && !IsBuildVariantInActiveCollection(buildVariant))
            {
                _activeCollection.BuildVariantGuids.Add(buildVariant.Guid);
                _buildInfoStorage.SaveBuildInfo(_buildInfo);
            }

            if (!toggleValue && IsBuildVariantInActiveCollection(buildVariant))
            {
                _activeCollection.BuildVariantGuids.Remove(buildVariant.Guid);
                _buildInfoStorage.SaveBuildInfo(_buildInfo);
            }
        }
 public void SetVariantParent(IBuildVariant buildVariant, string parentGuid)
 {
     ((BuildVariant)buildVariant).ParentGuid = parentGuid;
     if (string.IsNullOrEmpty(parentGuid))
     {
         return;
     }
     foreach (var parentVariant in _buildVariants)
     {
         if (parentVariant.Guid != parentGuid)
         {
             continue;
         }
         ((BuildVariant)buildVariant).Parent = parentVariant;
         SaveVariant(buildVariant);
         break;
     }
 }
示例#10
0
 private void DrawFilesList(IBuildVariant buildVariant, ICollection <FileMoveInfo> filesList)
 {
     EditorGUILayout.BeginHorizontal();
     buildVariant.SetFieldExpanded("MoveFiles",
                                   EditorGUILayout.Foldout(buildVariant.IsFieldExpanded("MoveFiles"),
                                                           string.Format("{0} ({1})", "Move files",
                                                                         filesList.Count)));
     if (GUILayout.Button("+", GUILayout.Width(30)))
     {
         filesList.Add(new FileMoveInfo());
     }
     EditorGUILayout.EndHorizontal();
     if (!buildVariant.IsFieldExpanded("MoveFiles"))
     {
         return;
     }
     EditorGUI.indentLevel++;
     foreach (var copyFileInfo in filesList)
     {
         DrawFile(filesList, copyFileInfo);
         EditorGUILayout.Space();
     }
     EditorGUI.indentLevel--;
 }
示例#11
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);
            }
        }
示例#12
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);
                }
            }
        }
 public void ActivateBuildVariant(IBuildVariant buildVariant)
 {
     _buildInfo.ActiveVariantGuid = buildVariant != null ? buildVariant.Guid : null;
     _buildInfoStorage.SaveBuildInfo(_buildInfo);
     _projectSettingsController.BuildAndApplyProjectSettings(buildVariant);
 }
 public bool IsBuildVariantInActiveCollection(IBuildVariant buildVariant)
 {
     return(_activeCollection.BuildVariantGuids.Contains(buildVariant.Guid));
 }
 public void SelectBuildVariant(IBuildVariant buildVariant)
 {
     _buildInfo.SelectedVariantGuid = buildVariant != null ? buildVariant.Guid : null;
     _buildInfoStorage.SaveBuildInfo(_buildInfo);
 }
示例#16
0
        private void DrawNode(IBuildVariant inspectedBuildVariant,
                              IProjectSettingsFile projectSettingsFile, SettingsCategory category, YamlNode node, YamlNode labelNode = null)
        {
            if (node == null)
            {
                return;
            }
            EditorGUI.indentLevel++;

            Action revertAction = null;
            Action saveAction   = null;

            if (category == SettingsCategory.ActualSettingsDiff || category == SettingsCategory.ActualRevertableSettingsDiff)
            {
                saveAction = () => {
                    inspectedBuildVariant.Merge(projectSettingsFile, node);
                    _projectSettingsController.InvalidateDiffCache();
                };
                if (category == SettingsCategory.ActualRevertableSettingsDiff)
                {
                    revertAction = () => {
                        _projectSettingsController.BuildAndApplyProjectSettings(inspectedBuildVariant,
                                                                                _projectSettingsController.GetDiffWithActualSettings(inspectedBuildVariant),
                                                                                projectSettingsFile, node);
                    }
                }
                ;
            }
            else if (category == SettingsCategory.VariantDiff)
            {
                revertAction = () => {
                    var currentDiff = _projectSettingsController.GetDiffWithActualSettings(inspectedBuildVariant).ToList();
                    inspectedBuildVariant.Revert(projectSettingsFile, node);
                    _projectSettingsController.BuildAndApplyProjectSettings(inspectedBuildVariant, currentDiff);
                };
            }

            if (node.NodeType == YamlNodeType.Mapping)
            {
                EditorGUILayout.BeginHorizontal();
                var expanded = inspectedBuildVariant.IsFieldExpanded(string.Format("{0}_{1}_{2}",
                                                                                   category.ToString(), projectSettingsFile.FileName, labelNode));

                expanded = EditorGUILayout.Foldout(expanded, string.Format("{0} ({1})",
                                                                           labelNode, ((YamlMappingNode)node).Children.Count));
                inspectedBuildVariant.SetFieldExpanded(string.Format("{0}_{1}_{2}",
                                                                     category.ToString(), projectSettingsFile.FileName, labelNode), expanded);
                DrawSaveRevert(revertAction, saveAction);
                EditorGUILayout.EndHorizontal();
                if (expanded)
                {
                    foreach (var keyValue in ((YamlMappingNode)node).Children)
                    {
                        DrawNode(inspectedBuildVariant, projectSettingsFile, category, keyValue.Value, keyValue.Key);
                    }
                }
            }
            else if (node.NodeType == YamlNodeType.Scalar || node.NodeType == YamlNodeType.Sequence)
            {
                EditorGUILayout.BeginHorizontal();
                if (labelNode != null)
                {
                    EditorGUILayout.LabelField(labelNode.ToString());
                }
                EditorGUILayout.HelpBox(node.ToString(), MessageType.None);
                DrawSaveRevert(revertAction, saveAction);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel--;
        }
示例#17
0
 public void RemoveVariant(IBuildVariant buildVariant)
 {
     File.Delete(Path.Combine(_buildVariantsPath, buildVariant.Guid + VariantFileExtension));
 }
 public void SaveVariant(IBuildVariant buildVariant)
 {
     _buildVariantsStorage.SaveVariant(buildVariant);
 }
 public void RemoveVariant(IBuildVariant buildVariant)
 {
     _buildVariants.Remove((BuildVariant)buildVariant);
     _buildVariantsStorage.RemoveVariant((BuildVariant)buildVariant);
 }