AssetBundleGraph.IntegratedGUIBundleConfigurator.ValidateVariantName C# (CSharp) Method

ValidateVariantName() public static method

public static ValidateVariantName ( string variantName, List names, System.Action NullOrEmpty, System.Action ContainsSpace, System.Action NameAlreadyExists ) : void
variantName string
names List
NullOrEmpty System.Action
ContainsSpace System.Action
NameAlreadyExists System.Action
return void
        public static void ValidateVariantName(string variantName, List<string> names, Action NullOrEmpty, Action ContainsSpace, Action NameAlreadyExists)
        {
            if (string.IsNullOrEmpty(variantName)) {
                NullOrEmpty();
            }
            if(Regex.IsMatch(variantName, "\\s")) {
                ContainsSpace();
            }
            var overlappings = names.GroupBy(x => x)
                .Where(group => 1 < group.Count())
                .Select(group => group.Key)
                .ToList();

            if (overlappings.Any()) {
                NameAlreadyExists();
            }
        }

Usage Example

        private void DoInspectorBundleConfiguratorGUI(NodeGUI node)
        {
            if (node.Data.BundleNameTemplate == null)
            {
                return;
            }

            EditorGUILayout.HelpBox("BundleConfigurator: Create asset bundle settings with given group of assets.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = DrawOverrideTargetToggle(node, node.Data.BundleNameTemplate.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                    using (new RecordUndoScope("Remove Target Bundle Name Template Setting", node, true)){
                        if (enabled)
                        {
                            node.Data.BundleNameTemplate[currentEditingGroup] = node.Data.BundleNameTemplate.DefaultValue;
                        }
                        else
                        {
                            node.Data.BundleNameTemplate.Remove(currentEditingGroup);
                        }
                    }
                });

                using (disabledScope) {
                    var bundleNameTemplate = EditorGUILayout.TextField("Bundle Name Template", node.Data.BundleNameTemplate[currentEditingGroup]).ToLower();

                    if (bundleNameTemplate != node.Data.BundleNameTemplate[currentEditingGroup])
                    {
                        using (new RecordUndoScope("Change Bundle Name Template", node, true)){
                            node.Data.BundleNameTemplate[currentEditingGroup] = bundleNameTemplate;
                        }
                    }
                }
            }

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                GUILayout.Label("Variants:");
                var     variantNames = node.Data.Variants.Select(v => v.Name).ToList();
                Variant removing     = null;
                foreach (var v in node.Data.Variants)
                {
                    using (new GUILayout.HorizontalScope()) {
                        if (GUILayout.Button("-", GUILayout.Width(30)))
                        {
                            removing = v;
                        }
                        else
                        {
                            GUIStyle s             = new GUIStyle((GUIStyle)"TextFieldDropDownText");
                            Action   makeStyleBold = () => {
                                s.fontStyle = FontStyle.Bold;
                                s.fontSize  = 12;
                            };

                            IntegratedGUIBundleConfigurator.ValidateVariantName(v.Name, variantNames,
                                                                                makeStyleBold,
                                                                                makeStyleBold,
                                                                                makeStyleBold);

                            var variantName = EditorGUILayout.TextField(v.Name, s);

                            if (variantName != v.Name)
                            {
                                using (new RecordUndoScope("Change Variant Name", node, true)){
                                    v.Name = variantName;
                                }
                            }
                        }
                    }
                }
                if (GUILayout.Button("+"))
                {
                    using (new RecordUndoScope("Add Variant", node, true)){
                        node.Data.AddVariant(AssetBundleGraphSettings.BUNDLECONFIG_VARIANTNAME_DEFAULT);
                    }
                }
                if (removing != null)
                {
                    using (new RecordUndoScope("Remove Variant", node, true)){
                        // event must raise to remove connection associated with point
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_DELETED, node, Vector2.zero, removing.ConnectionPoint));
                        node.Data.RemoveVariant(removing);
                    }
                }
            }
        }