Beispiel #1
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--;
        }
Beispiel #2
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);
                }
            }
        }