public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var textComponent = currentInstanceTransform.GetComponentInChildren <Text>(); if (attributesToApply.ContainsKey("text")) { textComponent.text = attributesToApply["text"]; } if (attributesToApply.ContainsKey("textColor")) { textComponent.color = attributesToApply["textcolor"].ToColor(); } if (attributesToApply.ContainsKey("backgroundColor")) { var propertyInfo = primaryComponent.GetType().GetProperty("targetGraphic"); if (propertyInfo != null) { var targetGraphic = propertyInfo.GetValue(primaryComponent, null) as Image; if (targetGraphic != null) { targetGraphic.color = attributesToApply["backgroundColor"].ToColor(); } } } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var toggleComponent = currentInstanceTransform.GetComponent <Toggle>(); if (attributesToApply.ContainsKey("colors")) { toggleComponent.colors = attributesToApply["colors"].ToColorBlock(); } if (attributesToApply.ContainsKey("ison")) { toggleComponent.isOn = attributesToApply["ison"].ToBoolean(); } if (ToggleGroupTagHandler.CurrentToggleGroupInstance != null) { var xmlLayoutToggleGroupInstance = ToggleGroupTagHandler.CurrentToggleGroupInstance; xmlLayoutToggleGroupInstance.AddToggle(toggleComponent); xmlLayoutToggleGroupInstance.UpdateToggleElement(toggleComponent); toggleComponent.onValueChanged.AddListener((e) => { if (e) { var value = xmlLayoutToggleGroupInstance.GetValueForElement(toggleComponent); xmlLayoutToggleGroupInstance.SetSelectedValue(value); } }); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var textComponent = currentInstanceTransform.GetComponentInChildren <Text>(); /*if (attributesToApply.ContainsKey("text")) * { * textComponent.text = StringExtensions.DecodeEncodedNonAsciiCharacters(attributesToApply["text"]); * }*/ if (attributesToApply.ContainsKey("textColor")) { textComponent.color = attributesToApply["textcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("backgroundColor")) { var propertyInfo = primaryComponent.GetType().GetProperty("targetGraphic"); if (propertyInfo != null) { var targetGraphic = propertyInfo.GetValue(primaryComponent, XmlLayoutUtilities.BindingFlags, null, null, null) as Image; if (targetGraphic != null) { targetGraphic.color = attributesToApply["backgroundColor"].ToColor(currentXmlLayoutInstance); } } } }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { if (value.Equals("None", StringComparison.OrdinalIgnoreCase)) { return; } if (!elementAttributes.ContainsKey("outline")) { return; } var elementTransform = xmlElement.rectTransform; var outlineColor = elementAttributes["outline"].ToColor(); var outline = elementTransform.GetComponent <Outline>(); if (outline == null) { outline = elementTransform.gameObject.AddComponent <Outline>(); } outline.effectColor = outlineColor; if (elementAttributes.ContainsKey("outlinesize")) { outline.effectDistance = elementAttributes["outlinesize"].ToVector2(); } }
public override void ApplyAttributes(AttributeDictionary attributes) { base.ApplyAttributes(attributes); if (attributes.ContainsKey("selecteddates")) { try { var datePicker = (primaryComponent as DatePicker); var dates = attributes["selecteddates"].Split(' ', '|', ',') .Select(d => new SerializableDate(DateTime.Parse(d))) .ToList(); datePicker.SelectedDates = dates; // this will automatically put the DatePicker into multiple date selection mode if the user specifies 'SelectedDates' // (unless they have specified otherwise) if (!attributes.ContainsKey("dateselectionmode")) { datePicker.DateSelectionMode = DateSelectionMode.MultipleDates; } } catch { Debug.LogWarning("[XmlLayout][DatePicker][Warning] Error parsing selectedDates value '" + attributes["selecteddates"] + "'."); } } }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { if (value.Equals("None", StringComparison.OrdinalIgnoreCase)) { return; } if (!elementAttributes.ContainsKey("shadow")) { return; } var elementTransform = xmlElement.rectTransform; var shadowColor = elementAttributes["shadow"].ToColor(); var shadow = elementTransform.GetComponent <Shadow>(); if (shadow == null) { shadow = elementTransform.gameObject.AddComponent <Shadow>(); } shadow.effectColor = shadowColor; if (elementAttributes.ContainsKey("shadowdistance")) { shadow.effectDistance = elementAttributes["shadowdistance"].ToVector2(); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { // reset XmlElement values to their default (except for new values provided) // the reason we do this is because unlike most XmlElements, the XmlLayout's XmlElement is not destroyed before a rebuild // if we don't reset the values here, then if you were to clear an existing attribute value (e.g. showAnimation), then it would still be there after the rebuild attributesToApply = XmlLayoutUtilities.MergeAttributes(defaultAttributeValues, attributesToApply); base.ApplyAttributes(attributesToApply); if (!Application.isPlaying) { return; } if (attributesToApply.ContainsKey("cursor")) { XmlLayoutTimer.AtEndOfFrame(() => { XmlLayoutCursorController.Instance.SetCursorForState(XmlLayoutCursorController.eCursorState.Default, attributesToApply["cursor"].ToCursorInfo(), true); }, currentXmlElement); } if (attributesToApply.ContainsKey("cursorClick")) { XmlLayoutTimer.AtEndOfFrame(() => { XmlLayoutCursorController.Instance.SetCursorForState(XmlLayoutCursorController.eCursorState.Click, attributesToApply["cursorClick"].ToCursorInfo(), true); }, currentXmlElement); } }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { var elementTransform = xmlElement.rectTransform; //var alignment = xmlElement.HasAttribute("rectAlignment") ? GetRectAlignment(xmlElement.GetAttribute("rectAlignment")) : RectAlignment.MiddleCenter; var alignment = RectAlignment.MiddleCenter; if (xmlElement.HasAttribute("rectAlignment")) { alignment = GetRectAlignment(xmlElement.GetAttribute("rectAlignment")); } else if (elementAttributes.ContainsKey("rectAlignment")) { alignment = GetRectAlignment(elementAttributes.GetValue("rectAlignment")); } if (elementAttributes.ContainsKey("position")) { elementTransform.position = elementAttributes["position"].ToVector2(); } var position = elementTransform.position; var width = float.Parse(value.Replace("%", String.Empty)); var originalHeight = elementTransform.rect.height; if (value.Contains("%")) { // Use a percentage-based width value elementTransform.sizeDelta = Vector2.zero; var workingWidth = width / 100f; var vector = ApplyAlignment(new Vector2(workingWidth, 0), alignment); elementTransform.anchorMin = new Vector2(vector.x, elementTransform.anchorMin.y); elementTransform.anchorMax = new Vector2(vector.x + workingWidth, elementTransform.anchorMax.y); } else { // Use a fixed width value var alignmentStruct = GetAlignmentStruct(width, 0, position, alignment); elementTransform.anchorMin = new Vector2(alignmentStruct.AnchorMin.x, elementTransform.anchorMin.y); elementTransform.anchorMax = new Vector2(alignmentStruct.AnchorMax.x, elementTransform.anchorMax.y); elementTransform.pivot = new Vector2(alignmentStruct.Pivot.x, elementTransform.pivot.y); elementTransform.sizeDelta = new Vector2(width, elementTransform.sizeDelta.y); } // preserve height elementTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, originalHeight); }
public override void ApplyAttributes(AttributeDictionary attributes) { base.ApplyAttributes(attributes); var textComponent = currentInstanceTransform.GetComponentInChildren <Text>(); var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributes.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributes.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributes["textshadow"]); } if (attributes.ContainsKey("textoutline")) { textAttributes.Add("outline", attributes["textoutline"]); } if (attributes.ContainsKey("textcolor")) { textAttributes.Add("color", attributes["textcolor"]); } if (attributes.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributes["textalignment"]); } tagHandler.ApplyAttributes(textAttributes); // preserve aspect for button background var imageComponent = currentInstanceTransform.GetComponent <Image>(); if (attributes.ContainsKey("preserveaspect")) { imageComponent.preserveAspect = attributes["preserveaspect"].ToBoolean(); } // I've encountered a bit of a problem where the XmlElement object added to the PaginationButton's text object by ApplyAttributes->tagHandler->SetInstance // is intercepting and preventing click events from being fired for these buttons // I've tried to figure out a way to prevent this from happening entirely, as it is an issue I'd like to resolve, but I haven't had any luck // so instead, what we're going to do, for now, is disable the XmlElement object on the text object (as we don't need it anyway once the attributes have been applied) var xmlElement = textComponent.GetComponent <XmlElement>(); if (xmlElement != null) { xmlElement.enabled = false; } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var inputField = primaryComponent as InputField; var textComponents = new List <Text> { inputField.textComponent }; if (inputField.placeholder != null) { var placeholderText = inputField.placeholder.GetComponent <Text>(); if (placeholderText != null) { textComponents.Add(placeholderText); } if (attributesToApply.ContainsKey("placeholdertext")) { placeholderText.text = attributesToApply["placeholdertext"]; } } foreach (var textComponent in textComponents) { var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } if (attributesToApply.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributesToApply["textalignment"]); } tagHandler.ApplyAttributes(textAttributes); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { if (!attributesToApply.ContainsKey("width") && !attributes.ContainsKey("width")) { attributesToApply.Add("width", "100%"); } if (!attributesToApply.ContainsKey("height") && !attributes.ContainsKey("height")) { attributesToApply.Add("height", "100%"); } base.ApplyAttributes(attributesToApply); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { bool applyX = true, applyY = true; // if an explicit width is defined, then this will be handled by the width attribute if (elementAttributes.ContainsKey("width") || xmlElement.HasAttribute("width")) { applyX = false; } // if an explicit height is defined, then this will be handled by the height attribute if (elementAttributes.ContainsKey("height") || xmlElement.HasAttribute("height")) { applyY = false; } // If a content size fitter is present, then it may override defined width/height values if (!applyX || !applyY) { if (elementAttributes.ContainsKey("contentSizeFitter") || xmlElement.HasAttribute("contentSizeFitter")) { string contentSizeFitter = xmlElement.HasAttribute("contentSizeFitter") ? xmlElement.GetAttribute("contentSizeFitter") : elementAttributes.GetValue("contentSizeFitter"); if (contentSizeFitter == "horizontal" || contentSizeFitter == "both") { applyX = true; } if (contentSizeFitter == "vertical" || contentSizeFitter == "both") { applyY = true; } } } var alignment = GetRectAlignment(value); var alignmentStruct = GetRectAlignmentStruct(alignment); var elementTransform = xmlElement.rectTransform; if (applyX ^ applyY) { elementTransform.anchorMin = new Vector2(applyX ? alignmentStruct.AnchorMin.x : elementTransform.anchorMin.x, applyY ? alignmentStruct.AnchorMin.y : elementTransform.anchorMin.y); elementTransform.anchorMax = new Vector2(applyX ? alignmentStruct.AnchorMax.x : elementTransform.anchorMax.x, applyY ? alignmentStruct.AnchorMax.y : elementTransform.anchorMax.y); } elementTransform.pivot = new Vector2(applyX ? alignmentStruct.Pivot.x : elementTransform.pivot.x, applyY ? alignmentStruct.Pivot.y : elementTransform.pivot.y); }
public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { var elementTransform = xmlElement.rectTransform; var alignment = RectAlignment.MiddleCenter; if (xmlElement.HasAttribute("rectAlignment")) { alignment = GetRectAlignment(xmlElement.GetAttribute("rectAlignment")); } else if (elementAttributes.ContainsKey("rectAlignment")) { alignment = GetRectAlignment(elementAttributes.GetValue("rectAlignment")); } if (elementAttributes.ContainsKey("position")) { elementTransform.position = elementAttributes["position"].ToVector2(); } var position = elementTransform.position; var height = float.Parse(value.Replace("%", String.Empty)); var originalWidth = elementTransform.rect.width; if (value.Contains("%")) { // Use a percentage-based width value elementTransform.sizeDelta = Vector2.zero; var workingHeight = height / 100f; var vector = ApplyAlignment(new Vector2(0, workingHeight), alignment); elementTransform.anchorMin = new Vector2(elementTransform.anchorMin.x, vector.y); elementTransform.anchorMax = new Vector2(elementTransform.anchorMax.x, vector.y + workingHeight); } else { // Use a fixed width value var alignmentStruct = GetAlignmentStruct(0, height, position, alignment); elementTransform.anchorMin = new Vector2(elementTransform.anchorMin.x, alignmentStruct.AnchorMin.y); elementTransform.anchorMax = new Vector2(elementTransform.anchorMax.x, alignmentStruct.AnchorMax.y); elementTransform.pivot = new Vector2(elementTransform.pivot.x, alignmentStruct.Pivot.y); elementTransform.sizeDelta = new Vector2(elementTransform.sizeDelta.x, height); } elementTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, originalWidth); }
public static AttributeDictionary MergeAttribute( this AttributeDictionary attributes, string key, object value) { if (value == null) { return(attributes); } var newValue = AttributeValueToString(value); string mergedValue; if (attributes.ContainsKey(key)) { if (key == "class" || key == "aria-describedby") { mergedValue = attributes[key] + " " + newValue; } else { throw new InvalidOperationException($"Don't know how to merge attributes with key '{key}'."); } } else { mergedValue = newValue; } attributes[key] = mergedValue; return(attributes); }
private static void HandleShaderKeywords(Material material, AttributeDictionary materialAttributes) { if (materialAttributes.Any(a => a.Key.Contains("bevel"))) { material.EnableKeyword("BEVEL_ON"); } if (materialAttributes.Any(a => a.Key.StartsWith("underlay"))) { var underlayType = materialAttributes.GetValue("underlayType"); if (underlayType == "Inner") { material.EnableKeyword("UNDERLAY_INNER"); } else if (underlayType != "None") { material.EnableKeyword("UNDERLAY_ON"); } } if (materialAttributes.Any(a => a.Key.StartsWith("glow"))) { material.EnableKeyword("GLOW_ON"); } if (materialAttributes.ContainsKey("bevelType")) { var type = Enum.Parse(typeof(BevelType), materialAttributes["bevelType"]); material.SetFloat("_ShaderFlags", (int)type); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { // this should never happen, but just in case if (TextMeshProDropdownTagHandler.CurrentHandler == null) { return; } attributesToApply.AddIfKeyNotExists("alignment", "Left"); attributesToApply.AddIfKeyNotExists("dontMatchParentDimensions", "true"); var dropdown = TextMeshProDropdownTagHandler.CurrentHandler.CurrentDropdown; var TMPHandler = XmlLayoutUtilities.GetXmlTagHandler("TextMeshPro"); TMPHandler.SetInstance(dropdown.itemText.rectTransform, currentXmlLayoutInstance); TMPHandler.ApplyAttributes(attributesToApply); if (attributesToApply.ContainsKey("padding")) { var padding = attributesToApply["padding"].ToRectOffset(); dropdown.itemText.rectTransform.offsetMin = new Vector2(padding.left, padding.bottom); dropdown.itemText.rectTransform.offsetMax = new Vector2(-padding.right, -padding.top); } var xmlElement = dropdown.itemText.GetComponent <XmlElement>(); //xmlElement.attributes = xmlElement.attributes.Merge(attributesToApply); xmlElement.attributes.Merge(attributesToApply); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var toggleComponent = currentInstanceTransform.GetComponent <Toggle>(); if (attributesToApply.ContainsKey("colors")) { toggleComponent.colors = attributesToApply["colors"].ToColorBlock(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("ison")) { toggleComponent.isOn = attributesToApply["ison"].ToBoolean(); } if (attributesToApply.ContainsKey("selectedicon")) { var xmlLayoutToggleButton = toggleComponent.GetComponent <XmlLayoutToggleButton>(); xmlLayoutToggleButton.SelectedIconSprite = attributesToApply["selectedicon"].ToSprite(); xmlLayoutToggleButton.DeselectedIconSprite = xmlLayoutToggleButton.IconComponent.sprite; } if (ToggleGroupTagHandler.CurrentToggleGroupInstance != null) { var xmlLayoutToggleGroupInstance = ToggleGroupTagHandler.CurrentToggleGroupInstance; xmlLayoutToggleGroupInstance.AddToggle(toggleComponent); xmlLayoutToggleGroupInstance.UpdateToggleElement(toggleComponent); toggleComponent.onValueChanged.AddListener((e) => { if (e) { var value = xmlLayoutToggleGroupInstance.GetValueForElement(toggleComponent); xmlLayoutToggleGroupInstance.SetSelectedValue(value); } }); } XmlLayoutTimer.AtEndOfFrame(() => { var xmlLayoutToggleButton = toggleComponent.GetComponent <XmlLayoutToggleButton>(); xmlLayoutToggleButton.UpdateDisplay(); }, toggleComponent); }
internal void StoreLocal(string index, IodineObject obj) { if (parentLocals.ContainsKey(index)) { parentLocals [index] = obj; } locals [index] = obj; }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); if (attributesToApply.ContainsKey("text")) { (primaryComponent as Text).text = StringExtensions.DecodeEncodedNonAsciiCharacters(attributesToApply["text"]); } }
public void HandleAnimationNode(AttributeDictionary attributes) { if (!attributes.ContainsKey("name")) { return; } animations.SetValue(attributes["name"], new XmlLayoutAnimation(attributes)); }
public override void Open(AttributeDictionary attributes) { base.Open(attributes); if (attributes.ContainsKey("templateType")) { currentTemplateType = attributes["templateType"]; } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { if (currentXmlElement.name == "GameObject") { currentXmlElement.name = "TextMesh Pro"; } var tmp = currentInstanceTransform.gameObject.GetComponent <TextMeshProUGUI>() ?? currentInstanceTransform.gameObject.AddComponent <TextMeshProUGUI>(); // If we don't add a LayoutElement component, TextMeshPro will use up any layout parameters (as it uses the ILayoutElement interface) // and it doesn't use them in the same way as a LayoutElement so things like, for example, 'flexibleWidth' will not work as expected // by adding a LayoutElement, we ensure that the TMP element responds to layout attributes in the same way as other elements var layoutElement = tmp.GetComponent <LayoutElement>(); if (layoutElement == null) { tmp.gameObject.AddComponent <LayoutElement>(); } if (!attributesToApply.ContainsKey("dontMatchParentDimensions")) { MatchParentDimensions(); } // default alignment, as per standard UI text if (!attributesToApply.ContainsKey("alignment") && !currentXmlElement.attributes.ContainsKey("alignment")) { tmp.alignment = TextAlignmentOptions.Center; } // default font size, as per standard UI text if (!attributesToApply.ContainsKey("fontSize") && !currentXmlElement.attributes.ContainsKey("fontSize")) { tmp.fontSize = 14f; } base.ApplyAttributes(attributesToApply); if (attributesToApply.ContainsKey("colorGradient")) { tmp.enableVertexGradient = true; } }
public static AttributeDictionary Merge(this AttributeDictionary attributes, string name, string value, bool replaceExisting = false) { Guard.NotEmpty(name, nameof(name)); if (replaceExisting || !attributes.ContainsKey(name)) { attributes[name] = value; } return(attributes); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var uiObject3D = primaryComponent as UIObject3D; if (attributesToApply.ContainsKey("targetOffset")) { uiObject3D.TargetOffset = attributesToApply["targetOffset"].ToVector2(); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { // By default, the rotator has rotateY set to true - for XmlLayout, we don't want that if (!attributesToApply.ContainsKey("rotateY") && !currentXmlElement.attributes.ContainsKey("rotateY")) { var rotateObject = primaryComponent as RotateUIObject3D; rotateObject.RotateY = false; } base.ApplyAttributes(attributesToApply); }
public override AttributeDictionary Convert(string value, AttributeDictionary attributes, XmlElement xmlElement) { var result = new AttributeDictionary(); // if allowDragging has been set, then raycastTarget must also be true (unless specified otherwise by the user) if (value.ToBoolean() && !attributes.ContainsKey("raycastTarget")) { result.Add("raycastTarget", "true"); } return(result); }
// Called by XmlLayout.HandleTextMeshProMaterialNode // (Which processes TextMeshProMaterial elements in <Defaults />) public static Material CreateMaterial(XmlLayout xmlLayout, AttributeDictionary materialAttributes) { if (!materialAttributes.ContainsKey("name")) { Debug.LogError("[XmlLayout][TextMeshProMaterial] Warning: no name defined."); return(null); } // We need either a font or an existing material to base our new material on if (!materialAttributes.ContainsKey("font") && !materialAttributes.ContainsKey("baseMaterial")) { Debug.LogError("[XmlLayout][TextMeshProMaterial] Warning: no font or baseMaterial defined."); return(null); } Material baseMaterial = null; if (materialAttributes.ContainsKey("font")) { var font = materialAttributes["font"].ChangeToType <TMP_FontAsset>(); if (font == null) { return(null); } baseMaterial = font.material; } if (materialAttributes.ContainsKey("baseMaterial")) { if (xmlLayout.textMeshProMaterials.ContainsKey(materialAttributes["baseMaterial"])) { baseMaterial = xmlLayout.textMeshProMaterials[materialAttributes["baseMaterial"]]; } else { baseMaterial = materialAttributes["baseMaterial"].ToMaterial(); } } var material = new Material(baseMaterial); material.shaderKeywords = material.shaderKeywords; material.name = materialAttributes["name"]; if (materialAttributes.ContainsKey("shader")) { material.shader = Shader.Find(materialAttributes["shader"]); } HandleShaderProperties(xmlLayout, material, materialAttributes); HandleShaderKeywords(material, materialAttributes); return(material); }
public void AttributeDictionary_ContainsKey_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair <string, string>("zero", "0")); attributes.Add(new KeyValuePair <string, string>("one", "1")); attributes.Add(new KeyValuePair <string, string>("two", "2")); // Act var result = attributes.ContainsKey("one!"); // Assert Assert.False(result); }
public override void ApplyAttributes(AttributeDictionary attributes) { base.ApplyAttributes(attributes); if (attributes.ContainsKey("showPagination")) { if (!attributes.GetValue <bool>("showPagination")) { var viewportRectTransform = (RectTransform)currentInstanceTransform.GetComponentInChildren <Viewport>().transform; viewportRectTransform.offsetMax = Vector2.zero; viewportRectTransform.offsetMin = Vector2.zero; pagedRect.Pagination.gameObject.SetActive(false); } } }
public static AttributeDictionary Merge(this AttributeDictionary attributes, IDictionary <string, object> source, bool replaceExisting = false) { Guard.NotNull(attributes, nameof(attributes)); if (source != null) { foreach (var kvp in source) { if (replaceExisting || !attributes.ContainsKey(kvp.Key)) { attributes[kvp.Key] = kvp.Value.ToString(); } } } return(attributes); }
public void AttributeDictionary_ContainsKey_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.ContainsKey("one!"); // Assert Assert.False(result); }