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);
        }
Ejemplo n.º 2
0
        public void Draw()
        {
            _frameAction = () => { };
            var inspectedBuildVariant = _buildVariantsController.BuildVariants.
                                        FirstOrDefault(buildVariant => buildVariant.Guid == _buildInfoController.BuildInfo.SelectedVariantGuid);

            if (inspectedBuildVariant == null)
            {
                return;
            }
            var isInspectedVariantActive = inspectedBuildVariant.Guid == _buildInfoController.BuildInfo.ActiveVariantGuid;

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            GUI.enabled = !isInspectedVariantActive;
            if (GUILayout.Button("Make active"))
            {
                _buildInfoController.ActivateBuildVariant(inspectedBuildVariant);
            }
            if (GUILayout.Button("Remove"))
            {
                _frameAction += () => _buildVariantsController.RemoveVariant(inspectedBuildVariant);
            }
            GUI.enabled = true;
            if (GUILayout.Button("Create child"))
            {
                _buildVariantsController.CreateVariant(inspectedBuildVariant);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Space();
            inspectedBuildVariant.VariantName = EditorGUILayout.TextField("Variant name:", inspectedBuildVariant.VariantName);

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("GUID:");
            EditorGUILayout.LabelField(inspectedBuildVariant.Guid);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            var possibleParents = _buildVariantsController.BuildVariants.Where(v => v != inspectedBuildVariant &&
                                                                               v.Parent != inspectedBuildVariant).
                                  Select(v => new GUIContent(string.Format("{0} ({1})", v.VariantName, v.Guid), v.Guid)).ToList();

            possibleParents.Insert(0, new GUIContent("No parent", ""));
            var selectedParent = -1;

            for (var i = 0; i < possibleParents.Count; i++)
            {
                if (possibleParents[i].tooltip !=
                    (inspectedBuildVariant.Parent == null ? "" : inspectedBuildVariant.Parent.Guid))
                {
                    continue;
                }
                selectedParent = i;
                break;
            }
            var newSelectedParent = EditorGUILayout.Popup(new GUIContent("Parent:"),
                                                          selectedParent,
                                                          possibleParents.ToArray());

            if (newSelectedParent != selectedParent)
            {
                _buildVariantsController.SetVariantParent(inspectedBuildVariant, possibleParents[newSelectedParent].tooltip);
            }

            EditorGUILayout.Space();
            inspectedBuildVariant.BuildPath = EditorGUILayout.TextField("Build path:", inspectedBuildVariant.BuildPath);

            EditorGUILayout.Space();
            inspectedBuildVariant.MakeZip = EditorGUILayout.Toggle("Make zip:", inspectedBuildVariant.MakeZip);

            EditorGUILayout.Space();
            var nonObsoleteBuildTargetFields = typeof(BuildTarget)
                                               .GetFields(BindingFlags.Public | BindingFlags.Static)
                                               .Where(fieldInfo => !Attribute.IsDefined(fieldInfo, typeof(ObsoleteAttribute)));
            var nonObsoleteEnumValues = nonObsoleteBuildTargetFields
                                        .Select(fieldInfo => ((BuildTarget)fieldInfo.GetValue(null)).ToString()).ToArray();
            var buildTargetIndex = Array.IndexOf(nonObsoleteEnumValues, Enum.GetName(typeof(BuildTarget),
                                                                                     inspectedBuildVariant.BuildTarget));
            var newBuildTargetIndex = EditorGUILayout.Popup("Build target", buildTargetIndex, nonObsoleteEnumValues);

            if (newBuildTargetIndex != buildTargetIndex)
            {
                inspectedBuildVariant.BuildTarget =
                    (BuildTarget)Enum.Parse(typeof(BuildTarget), nonObsoleteEnumValues[newBuildTargetIndex]);
            }
            if (newBuildTargetIndex != buildTargetIndex)
            {
                inspectedBuildVariant.BuildTarget =
                    (BuildTarget)Enum.Parse(typeof(BuildTarget), nonObsoleteEnumValues[newBuildTargetIndex]);
            }

            EditorGUILayout.Space();
            inspectedBuildVariant.BuildOptions =
                (BuildOptions)EditorGUILayout.EnumMaskPopup("Build options:", inspectedBuildVariant.BuildOptions);

            EditorGUILayout.Space();
            DrawFilesList(inspectedBuildVariant, inspectedBuildVariant.MoveFiles);

            EditorGUILayout.Space();
            DrawSettings(inspectedBuildVariant,
                         isInspectedVariantActive ? SettingsCategory.ActualRevertableSettingsDiff : SettingsCategory.ActualSettingsDiff);

            EditorGUILayout.Space();
            DrawSettings(inspectedBuildVariant, SettingsCategory.VariantDiff);

            _frameAction();

            if (EditorGUI.EndChangeCheck())
            {
                _buildVariantsController.SaveVariant(inspectedBuildVariant);
            }

            EditorGUILayout.EndScrollView();
        }