public override void Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { Selectable s = xmlElement.GetComponent <Selectable>(); if (s == null) { return; } s.spriteState = new SpriteState() { disabledSprite = elementAttributes.GetValue("disabledSprite").ToSprite(), highlightedSprite = elementAttributes.GetValue("highlightedSprite").ToSprite(), pressedSprite = elementAttributes.GetValue("pressedSprite").ToSprite() }; }
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 Apply(XmlElement xmlElement, string value, AttributeDictionary elementAttributes) { Selectable s = xmlElement.GetComponent <Selectable>(); if (s == null) { return; } s.animationTriggers = new AnimationTriggers() { normalTrigger = elementAttributes.GetValue("normalTrigger") ?? "Normal", highlightedTrigger = elementAttributes.GetValue("highlightedTrigger") ?? "Highlighted", pressedTrigger = elementAttributes.GetValue("pressedTrigger") ?? "Pressed", disabledTrigger = elementAttributes.GetValue("disabledTrigger") ?? "Disabled" }; }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var progressBar = primaryComponent as XmlLayoutProgressBar; var textComponent = progressBar.ref_text; 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); var fillImage = progressBar.ref_fillImage; if (attributesToApply.ContainsKey("fillImage")) { fillImage.sprite = attributesToApply.GetValue <Sprite>("fillImage"); } if (attributesToApply.ContainsKey("fillImageColor")) { fillImage.color = attributesToApply.GetValue <Color>("fillImageColor"); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { // necessary for elements which don't use a prefab MatchParentDimensions(); currentXmlElement.name = "ChildXmlLayout"; base.ApplyAttributes(attributesToApply); var viewPath = attributesToApply.GetValue <string>("viewPath"); if (String.IsNullOrEmpty(viewPath)) { Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: The 'viewPath' attribute is required."); return; } // validate viewPath var xmlFile = XmlLayoutResourceDatabase.instance.GetResource <TextAsset>(viewPath); if (xmlFile == null) { Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: View '" + viewPath + "' not found. Please ensure that the view is accessible via an XmlLayout Resource Database (or is in a Resources folder)."); return; } Type controllerType = null; var controllerTypeName = attributesToApply.GetValue <string>("controller"); if (!String.IsNullOrEmpty(controllerTypeName)) { controllerType = Type.GetType(controllerTypeName, false, true); if (controllerType == null) { Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: Controller Type '" + controllerTypeName + "' not found. Please ensure that the full class name (including the namespace, if the class is located within one). For example: MyNamespace.MyLayoutControllerType"); } } var newXmlLayout = XmlLayoutFactory.Instantiate(currentInstanceTransform, viewPath, controllerType); currentXmlElement.AddChildElement(newXmlLayout.XmlElement, false); }
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 attributesToApply) { base.ApplyAttributes(attributesToApply); var padding = attributesToApply.GetValue <RectOffset>("padding"); if (padding != null) { var layoutGroup = primaryComponent as SimpleLayoutGroup; layoutGroup.padding = padding; layoutGroup.enabled = true; } }
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 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 override void ApplyAttributes(AttributeDictionary attributesToApply) { if (currentXmlElement.HasAttribute("image") && !currentXmlElement.HasAttribute("raycastTarget")) { attributesToApply.Add("raycastTarget", "true"); currentXmlElement.SetAttribute("raycastTarget", "true"); } base.ApplyAttributes(attributesToApply); var padding = attributesToApply.GetValue <RectOffset>("padding"); if (padding != null) { var layoutGroup = primaryComponent as SimpleLayoutGroup; layoutGroup.padding = padding; layoutGroup.enabled = true; } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { // this should never happen, but just in case if (TextMeshProDropdownTagHandler.CurrentHandler == null) { return; } var text = ElementHasAttribute("text", attributesToApply) ? attributesToApply.GetValue("text") : string.Empty; var selected = ElementHasAttribute("selected", attributesToApply) ? currentXmlElement.GetAttribute("selected").ToBoolean() : false; var dropdown = TextMeshProDropdownTagHandler.CurrentHandler.CurrentDropdown; var optionData = new TMP_Dropdown.OptionData { text = text }; dropdown.options.Add(optionData); if (selected) { dropdown.value = dropdown.options.IndexOf(optionData); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { // necessary for elements which don't use a prefab MatchParentDimensions(); // If multiple child layouts are nested, then ApplyAttributes() will be called for each before this method has finished executing // This becomes an issue, because tag handlers are singletons intended to deal with a single element in one go, // which means that the 'currentXmlElement' reference will be replaced with the child, which causes several issues // this is also true of all other references, although in this case only 'currentXmlElement' causes any trouble // It may be necessary in future to modify the way tag handlers work such that each XmlLayout reference has its own collection of tag handlers, // although that will require a small amount of additional memory and processing var _currentXmlElement = currentXmlElement; _currentXmlElement.name = "ChildXmlLayout"; base.ApplyAttributes(attributesToApply); // Don't pass 'id' on attributesToApply.Remove("id"); attributesToApply.Remove("internalId"); // if we've already been initialized, don't repeat the process if (_currentXmlElement.GetAttribute("initialized") != null) { // attempt to apply the attributes to the child // I've removed this for the time being; as there are potential issues with properties e.g. width="50%" would make // the container use width="50%" and then the child would be 50% width of that // // var _childXmlLayout = _currentXmlElement.childElements.FirstOrDefault(t => t.tagType == "XmlLayout"); // if(_childXmlLayout != null) _childXmlLayout.ApplyAttributes(attributesToApply); return; } var viewPath = attributesToApply.GetValue <string>("viewPath"); if (String.IsNullOrEmpty(viewPath)) { Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: The 'viewPath' attribute is required."); return; } // validate viewPath var xmlFile = XmlLayoutResourceDatabase.instance.GetResource <TextAsset>(viewPath); if (xmlFile == null) { Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: View '" + viewPath + "' not found. Please ensure that the view is accessible via an XmlLayout Resource Database (or is in a Resources folder)."); return; } Type controllerType = null; var controllerTypeName = attributesToApply.GetValue <string>("controller"); if (!String.IsNullOrEmpty(controllerTypeName)) { // controllerType = Type.GetType(controllerTypeName, false, true); controllerType = GetTypeFromStringName(controllerTypeName); if (controllerType == null) { Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: Controller Type '" + controllerTypeName + "' not found. Please ensure that the full class name (including the namespace, if the class is located within one). For example: MyNamespace.MyLayoutControllerType"); } } bool passEventsToParentController = false; if (controllerType == null) { controllerType = typeof(XmlLayoutController); passEventsToParentController = true; } var childXmlLayout = XmlLayoutFactory.Instantiate(currentInstanceTransform, viewPath, controllerType); childXmlLayout.ParentLayout = _currentXmlElement.xmlLayoutInstance; childXmlLayout.ForceRebuildOnAwake = false; if (passEventsToParentController) { childXmlLayout.XmlLayoutController.EventTarget = currentXmlLayoutInstance.XmlLayoutController; } // Adding a sub-canvas may (slightly) improve performance if (_currentXmlElement.gameObject.GetComponent <Canvas>() == null) { _currentXmlElement.gameObject.AddComponent <Canvas>(); } if (_currentXmlElement.gameObject.GetComponent <GraphicRaycaster>() == null) { _currentXmlElement.gameObject.AddComponent <GraphicRaycaster>(); } childXmlLayout.XmlElement.tagType = "XmlLayout"; _currentXmlElement.AddChildElement(childXmlLayout.XmlElement, false); _currentXmlElement.SetAttribute("initialized", "true"); childXmlLayout.XmlElement.ApplyAttributes(attributesToApply); // For some reason, the child XmlLayout offset Min/Max values are incorrect, so we need to force them to be zero if (!attributesToApply.ContainsKey("offsetMax")) { childXmlLayout.XmlElement.rectTransform.offsetMax = Vector2.zero; } if (!attributesToApply.ContainsKey("offsetMin")) { childXmlLayout.XmlElement.rectTransform.offsetMin = Vector2.zero; } }
public override void ApplyAttributes(AttributeDictionary attributes) { var type = attributes.GetValue("type"); if (type != null) { type = type.ToLower(); } DatePickerDayButtonConfig[] buttonsToApplyTo = new DatePickerDayButtonConfig[] { }; DatePickerDayConfig daysConfig = ConfigObject as DatePickerDayConfig; if (!string.IsNullOrEmpty(type) && !type.Equals("all", System.StringComparison.OrdinalIgnoreCase)) { switch (type) { case "currentmonth": buttonsToApplyTo = new DatePickerDayButtonConfig[] { daysConfig.CurrentMonth }; break; case "othermonths": buttonsToApplyTo = new DatePickerDayButtonConfig[] { daysConfig.OtherMonths }; break; case "selectedday": buttonsToApplyTo = new DatePickerDayButtonConfig[] { daysConfig.SelectedDay }; break; case "today": buttonsToApplyTo = new DatePickerDayButtonConfig[] { daysConfig.Today }; break; } } else { buttonsToApplyTo = new DatePickerDayButtonConfig[] { daysConfig.CurrentMonth, daysConfig.OtherMonths, daysConfig.SelectedDay, daysConfig.Today }; } foreach (var button in buttonsToApplyTo) { foreach (var attribute in attributes) { if (attribute.Key.Equals("type", System.StringComparison.OrdinalIgnoreCase)) { continue; } if (attribute.Key.Equals("backgroundColorFadeDuration", System.StringComparison.OrdinalIgnoreCase)) { button.BackgroundColors.fadeDuration = attribute.Value.ChangeToType <float>(); continue; } if (attribute.Key.Equals("backgroundColorMultiplier", System.StringComparison.OrdinalIgnoreCase)) { button.BackgroundColors.colorMultiplier = attribute.Value.ChangeToType <float>(); continue; } SetPropertyValue(button, attribute.Key, attribute.Value); } } }
public override void ApplyAttributes(AttributeDictionary attributes) { //base.ApplyAttributes(attributes); var type = attributes.GetValue("type"); if (type != null) { type = type.ToLower(); } DatePickerButtonConfig[] buttonsToApplyTo = new DatePickerButtonConfig[] { }; DatePickerHeaderConfig headerConfig = ConfigObject as DatePickerHeaderConfig; if (!string.IsNullOrEmpty(type) && !type.Equals("all", System.StringComparison.OrdinalIgnoreCase)) { switch (type) { case "nextmonth": buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.NextMonthButton }; break; case "previousmonth": buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.PreviousMonthButton }; break; case "nextyear": buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.NextYearButton }; break; case "previousyear": buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.PreviousYearButton }; break; case "months": buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.NextMonthButton, headerConfig.PreviousMonthButton }; break; case "years": buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.NextYearButton, headerConfig.PreviousYearButton }; break; } } else { // this applies to all four buttons buttonsToApplyTo = new DatePickerButtonConfig[] { headerConfig.NextMonthButton, headerConfig.PreviousMonthButton, headerConfig.NextYearButton, headerConfig.PreviousYearButton }; } foreach (var button in buttonsToApplyTo) { foreach (var attribute in attributes) { if (attribute.Key.Equals("type", System.StringComparison.OrdinalIgnoreCase)) { continue; } if (attribute.Key.Equals("fadeDuration", System.StringComparison.OrdinalIgnoreCase)) { button.Colors.fadeDuration = attribute.Value.ChangeToType <float>(); continue; } if (attribute.Key.Equals("colorMultiplier", System.StringComparison.OrdinalIgnoreCase)) { button.Colors.colorMultiplier = attribute.Value.ChangeToType <float>(); continue; } SetPropertyValue(button, attribute.Key, attribute.Value); } } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { var dropdownTransform = currentXmlElement.rectTransform.Find("Template") as RectTransform; var layoutElement = currentInstanceTransform.GetComponent <LayoutElement>(); if (layoutElement == null) { layoutElement = currentInstanceTransform.gameObject.AddComponent <LayoutElement>(); } // apply attributes as per usual base.ApplyAttributes(attributesToApply); if (ElementHasAttribute("dropdownheight", attributesToApply)) { dropdownTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, float.Parse(attributesToApply["dropdownheight"])); } var itemTemplate = CurrentDropdown.itemText.rectTransform.parent as RectTransform; if (ElementHasAttribute("itemHeight", attributesToApply)) { var itemHeight = float.Parse(currentXmlElement.GetAttribute("itemheight")); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); // it's also necessary to set the height of the content transform, otherwise we end up with weird issues var contentTransform = currentXmlElement.rectTransform.Find("Template/Viewport/Content") as RectTransform; contentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); } if (attributesToApply.ContainsKey("itemWidth")) { var itemWidth = attributesToApply["itemWidth"].ToFloat(); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, itemWidth); } var arrow = currentXmlElement.rectTransform.Find("Arrow").GetComponent <Image>(); if (attributesToApply.ContainsKey("arrowImage")) { arrow.sprite = attributesToApply["arrowImage"].ToSprite(); } if (attributesToApply.ContainsKey("arrowColor")) { arrow.color = attributesToApply["arrowColor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("arrowOffset")) { arrow.rectTransform.anchoredPosition = attributesToApply["arrowOffset"].ToVector2(); } if (attributesToApply.ContainsKey("itemBackgroundColors")) { var toggle = itemTemplate.GetComponent <Toggle>(); toggle.colors = attributesToApply["itemBackgroundColors"].ToColorBlock(currentXmlLayoutInstance); } var dropdownBackground = dropdownTransform.GetComponent <Image>(); if (attributesToApply.ContainsKey("dropdownBackgroundColor")) { dropdownBackground.color = attributesToApply["dropdownBackgroundColor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("dropdownBackgroundImage")) { dropdownBackground.sprite = attributesToApply["dropdownBackgroundImage"].ToSprite(); } var scrollbar = dropdownTransform.GetComponentInChildren <Scrollbar>(); var scrollbarImage = scrollbar.targetGraphic as Image; if (attributesToApply.ContainsKey("scrollbarColors")) { scrollbar.colors = attributesToApply["scrollbarColors"].ToColorBlock(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarImage")) { scrollbarImage.sprite = attributesToApply["scrollbarImage"].ToSprite(); } var scrollbarBackground = scrollbar.GetComponent <Image>(); if (attributesToApply.ContainsKey("scrollbarBackgroundColor")) { scrollbarBackground.color = attributesToApply["scrollbarBackgroundColor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("scrollbarBackgroundImage")) { scrollbarBackground.sprite = attributesToApply["scrollbarBackgroundImage"].ToSprite(); } if (attributesToApply.ContainsKey("scrollbarWidth")) { scrollbar.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, attributesToApply["scrollbarWidth"].ToFloat()); } if (attributesToApply.ContainsKey("padding")) { var padding = attributesToApply["padding"].ToVector4(); var itemLabelTransform = currentInstanceTransform.Find("Label") as RectTransform; itemLabelTransform.offsetMin = new Vector2(padding.x, padding.w); itemLabelTransform.offsetMax = new Vector2(-padding.y, -padding.z); } var checkMark = itemTemplate.Find("Item Checkmark").GetComponent <Image>(); if (attributesToApply.ContainsKey("checkColor")) { checkMark.color = attributesToApply["checkColor"].ToColor(currentXmlLayoutInstance); } else { checkMark.color = new Color(0, 0, 0); } if (attributesToApply.ContainsKey("checkImage")) { checkMark.sprite = attributesToApply["checkImage"].ToSprite(); } else { checkMark.sprite = XmlLayoutUtilities.LoadResource <Sprite>("Sprites/Elements/Checkmark"); } if (attributesToApply.ContainsKey("checkSize")) { var size = attributesToApply["checkSize"].ToFloat(); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size); } if (attributesToApply.ContainsKey("checkImagePreserveAspect")) { checkMark.preserveAspect = attributesToApply["checkMarkImagePreserveAspect"].ToBoolean(); } // data source #if !ENABLE_IL2CPP && MVVM_ENABLED if (attributesToApply.ContainsKey("vm-options")) { var xmlLayoutDropdown = currentXmlElement.GetComponent <XmlLayoutDropdown>(); xmlLayoutDropdown.optionsDataSource = attributesToApply["vm-options"]; } if (attributesToApply.ContainsKey("vm-dataSource")) { HandleDataSourceAttribute(attributesToApply.GetValue("vm-dataSource"), attributesToApply.GetValue("vm-options")); } #endif }
public override void ApplyAttributes(AttributeDictionary attributes) { var pagedRectTagHandler = PagedRectTagHandler.CurrentPagedRectTagHandler; if (pagedRectTagHandler == null) { Debug.Log("[XmlLayout] Error: Pagination: Unable to locate PagedRect instance."); } else { var pagedRectInstance = pagedRectTagHandler.currentInstanceTransform.GetComponent <PagedRect>(); var sizeAttributes = new string[] { "width", "height" }; if (attributes.Any(a => sizeAttributes.Contains(a.Key))) { // try and preserve default positioning of the pagination container if width or height attributes are provided if (!attributes.ContainsKey("rectAlignment")) { if (pagedRectTagHandler.tagType.Contains("Vertical")) { attributes.Add("rectAlignment", "MiddleLeft"); } else { attributes.Add("rectAlignment", "LowerCenter"); } } var viewportRectTransform = (RectTransform)pagedRectInstance.GetComponentInChildren <Viewport>().transform; // try and resize the viewport if the pagination container size changes if (pagedRectTagHandler.tagType.Contains("Vertical")) { if (attributes.ContainsKey("width")) { var rectAlignment = attributes.GetValue("rectAlignment") ?? "MiddleLeft"; if (rectAlignment.Contains("Left")) { viewportRectTransform.offsetMin = new Vector2(attributes.GetValue <float>("width"), viewportRectTransform.offsetMin.y); viewportRectTransform.offsetMax = new Vector2(0, viewportRectTransform.offsetMax.y); } else if (rectAlignment.Contains("Right")) { viewportRectTransform.offsetMin = new Vector2(0, viewportRectTransform.offsetMin.y); viewportRectTransform.offsetMax = new Vector2(-attributes.GetValue <float>("width"), viewportRectTransform.offsetMax.y); } } } else { if (attributes.ContainsKey("height")) { var rectAlignment = attributes.GetValue("rectAlignment") ?? "LowerCenter"; if (rectAlignment.Contains("Lower")) { viewportRectTransform.offsetMin = new Vector2(viewportRectTransform.offsetMin.x, attributes.GetValue <float>("height")); viewportRectTransform.offsetMax = new Vector2(viewportRectTransform.offsetMax.x, 0); } else if (rectAlignment.Contains("Upper")) { viewportRectTransform.offsetMin = new Vector2(viewportRectTransform.offsetMin.x, 0); viewportRectTransform.offsetMax = new Vector2(viewportRectTransform.offsetMax.x, -attributes.GetValue <float>("height")); } } } } var pagination = pagedRectInstance.Pagination; var backupTransform = this.currentInstanceTransform; this.SetInstance(pagination.transform as RectTransform, this.currentXmlLayoutInstance); base.ApplyAttributes(attributes); this.SetInstance(backupTransform, this.currentXmlLayoutInstance); } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var dropdown = primaryComponent as Dropdown; var templateComponent = dropdown.template.GetComponent <Image>(); var itemTemplateComponent = dropdown.template.GetComponentInChildren <Toggle>(); var textComponent = dropdown.captionText; var textTagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); textTagHandler.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"]); } textTagHandler.ApplyAttributes(textAttributes); // disable the XmlElement component, it can interfere with mouse clicks/etc. textComponent.GetComponent <XmlElement>().enabled = false; var xmlLayoutDropdown = dropdown.GetComponent <XmlLayoutDropdown>(); var arrow = xmlLayoutDropdown.Arrow; if (attributesToApply.ContainsKey("arrowimage")) { arrow.sprite = attributesToApply["arrowimage"].ToSprite(); } if (attributesToApply.ContainsKey("arrowcolor")) { arrow.color = attributesToApply["arrowcolor"].ToColor(); } // dropdownHeight property if (attributesToApply.ContainsKey("dropdownheight")) { dropdown.template.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, float.Parse(attributesToApply["dropdownheight"])); } // Apply text attributes to the item template var itemTemplate = xmlLayoutDropdown.ItemTemplate; var itemTagHandler = XmlLayoutUtilities.GetXmlTagHandler("Toggle"); var itemAttributes = attributesToApply.Clone(); if (attributesToApply.ContainsKey("itemheight")) { var itemHeight = float.Parse(attributesToApply["itemheight"]); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); // it's also necessary to set the height of the content transform, otherwise we end up with weird issues var contentTransform = templateComponent.GetComponentInChildren <ScrollRect>().content; contentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); } if (attributesToApply.ContainsKey("checkcolor")) { itemAttributes.Add("togglecheckmarkcolor", attributesToApply["checkcolor"]); } if (attributesToApply.ContainsKey("checksize")) { itemAttributes.Add("togglecheckmarksize", attributesToApply["checksize"]); } if (attributesToApply.ContainsKey("checkimage")) { itemAttributes.Add("togglecheckmarkimage", attributesToApply["checkimage"]); } if (attributesToApply.ContainsKey("checkimagepreserveaspect")) { itemAttributes.Add("togglecheckmarkimagepreserveaspect", attributesToApply["checkimagepreserveaspect"]); } // don't attempt to apply data source attributes to the item template itemAttributes.Remove("vm-dataSource"); itemAttributes.Remove("vm-options"); itemAttributes.Remove("color"); itemAttributes.Remove("colors"); // this attribute is checked by the Toggle to see if changes to the background should be permitted // (used by regular toggles to center the background if there is no text) itemAttributes.Add("dontModifyBackground", ""); var itemXmlElement = itemTemplate.transform.GetComponent <XmlElement>(); if (itemXmlElement == null) { itemTagHandler.SetInstance(itemTemplate.transform as RectTransform, this.currentXmlLayoutInstance); itemTagHandler.ApplyAttributes(itemAttributes); itemXmlElement = itemTemplate.transform.GetComponent <XmlElement>(); } else { itemXmlElement.ApplyAttributes(itemAttributes); } if (itemXmlElement != null) { itemXmlElement.enabled = false; } if (attributesToApply.ContainsKey("itembackgroundcolors")) { itemTemplateComponent.colors = attributesToApply["itembackgroundcolors"].ToColorBlock(); } if (attributesToApply.ContainsKey("dropdownbackgroundcolor")) { dropdown.template.GetComponent <Image>().color = attributesToApply["dropdownbackgroundcolor"].ToColor(); } if (attributesToApply.ContainsKey("dropdownbackgroundimage")) { dropdown.template.GetComponent <Image>().sprite = attributesToApply["dropdownbackgroundimage"].ToSprite(); } if (attributesToApply.ContainsKey("itemtextcolor")) { var itemTextComponent = dropdown.itemText; itemTextComponent.color = attributesToApply["itemtextcolor"].ToColor(); } if (attributesToApply.ContainsKey("scrollbarcolors")) { xmlLayoutDropdown.DropdownScrollbar.colors = attributesToApply["scrollbarcolors"].ToColorBlock(); } if (attributesToApply.ContainsKey("scrollbarimage")) { xmlLayoutDropdown.DropdownScrollbar.image.sprite = attributesToApply["scrollbarimage"].ToSprite(); } if (attributesToApply.ContainsKey("scrollbarbackgroundcolor")) { xmlLayoutDropdown.DropdownScrollbar.GetComponent <Image>().color = attributesToApply["scrollbarbackgroundcolor"].ToColor(); } if (attributesToApply.ContainsKey("scrollbarbackgroundimage")) { xmlLayoutDropdown.DropdownScrollbar.GetComponent <Image>().sprite = attributesToApply["scrollbarbackgroundimage"].ToSprite(); } foreach (var attribute in attributesToApply) { SetPropertyValue(templateComponent, attribute.Key, attribute.Value); } // data source #if !ENABLE_IL2CPP if (attributesToApply.ContainsKey("vm-options")) { xmlLayoutDropdown.optionsDataSource = attributesToApply["vm-options"]; } if (attributesToApply.ContainsKey("vm-dataSource")) { HandleDataSourceAttribute(attributesToApply.GetValue("vm-dataSource"), attributesToApply.GetValue("vm-options")); } #endif }
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 ApplyAttributes(AttributeDictionary attributes) { var pagedRectTagHandler = PagedRectTagHandler.CurrentPagedRectTagHandler; if (pagedRectTagHandler == null) { Debug.Log("[XmlLayout] Error: PaginationButtonTemplate: Unable to locate PagedRect instance."); } else { var pagedRectInstance = pagedRectTagHandler.currentInstanceTransform.GetComponent <PagedRect>(); var type = attributes.GetValue("type"); Button buttonInstance = null; switch (type.ToLower()) { case "currentpage": if (pagedRectInstance.ButtonTemplate_CurrentPage != null) { buttonInstance = pagedRectInstance.ButtonTemplate_CurrentPage.Button; } break; case "otherpages": if (pagedRectInstance.ButtonTemplate_OtherPages != null) { buttonInstance = pagedRectInstance.ButtonTemplate_OtherPages.Button; } break; case "disabledpages": if (pagedRectInstance.ButtonTemplate_DisabledPage != null) { buttonInstance = pagedRectInstance.ButtonTemplate_DisabledPage.Button; } break; case "next": if (pagedRectInstance.Button_NextPage != null) { buttonInstance = pagedRectInstance.Button_NextPage.Button; } break; case "previous": if (pagedRectInstance.Button_PreviousPage != null) { buttonInstance = pagedRectInstance.Button_PreviousPage.Button; } break; case "first": if (pagedRectInstance.Button_FirstPage != null) { buttonInstance = pagedRectInstance.Button_FirstPage.Button; } break; case "last": if (pagedRectInstance.Button_LastPage != null) { buttonInstance = pagedRectInstance.Button_LastPage.Button; } break; } if (buttonInstance == null) { Debug.Log("[XmlLayout][PaginationButtonTemplate] Unable to locate button template for '" + type + "'"); } else { var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("PaginationButton"); tagHandler.SetInstance(buttonInstance.transform as RectTransform, this.currentXmlLayoutInstance); attributes.Remove("type"); tagHandler.ApplyAttributes(attributes); } } }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { var dropdownTransform = currentXmlElement.rectTransform.Find("Template") as RectTransform; // apply attributes as per usual base.ApplyAttributes(attributesToApply); if (ElementHasAttribute("dropdownheight", attributesToApply)) { dropdownTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, float.Parse(attributesToApply["dropdownheight"])); } var itemTemplate = CurrentDropdown.itemText.rectTransform.parent as RectTransform; if (ElementHasAttribute("itemHeight", attributesToApply)) { var itemHeight = float.Parse(currentXmlElement.GetAttribute("itemheight")); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); // it's also necessary to set the height of the content transform, otherwise we end up with weird issues var contentTransform = currentXmlElement.rectTransform.Find("Template/Viewport/Content") as RectTransform; contentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); } var arrow = currentXmlElement.rectTransform.Find("Arrow").GetComponent <Image>(); if (attributesToApply.ContainsKey("arrowImage")) { arrow.sprite = attributesToApply["arrowImage"].ToSprite(); } if (attributesToApply.ContainsKey("arrowColor")) { arrow.color = attributesToApply["arrowColor"].ToColor(); } if (attributesToApply.ContainsKey("itemBackgroundColors")) { var toggle = itemTemplate.GetComponent <Toggle>(); toggle.colors = attributesToApply["itemBackgroundColors"].ToColorBlock(); } var dropdownBackground = dropdownTransform.GetComponent <Image>(); if (attributesToApply.ContainsKey("dropdownBackgroundColor")) { dropdownBackground.color = attributesToApply["dropdownBackgroundColor"].ToColor(); } if (attributesToApply.ContainsKey("dropdownBackgroundImage")) { dropdownBackground.sprite = attributesToApply["dropdownBackgroundImage"].ToSprite(); } var scrollbar = dropdownTransform.GetComponentInChildren <Scrollbar>(); var scrollbarImage = scrollbar.targetGraphic as Image; if (attributesToApply.ContainsKey("scrollbarColors")) { scrollbar.colors = attributesToApply["scrollbarColors"].ToColorBlock(); } if (attributesToApply.ContainsKey("scrollbarImage")) { scrollbarImage.sprite = attributesToApply["scrollbarImage"].ToSprite(); } var scrollbarBackground = scrollbar.GetComponent <Image>(); if (attributesToApply.ContainsKey("scrollbarBackgroundColor")) { scrollbarBackground.color = attributesToApply["scrollbarBackgroundColor"].ToColor(); } if (attributesToApply.ContainsKey("scrollbarBackgroundImage")) { scrollbarBackground.sprite = attributesToApply["scrollbarBackgroundImage"].ToSprite(); } // data source #if !ENABLE_IL2CPP if (attributesToApply.ContainsKey("vm-options")) { var xmlLayoutDropdown = currentXmlElement.GetComponent <XmlLayoutDropdown>(); xmlLayoutDropdown.optionsDataSource = attributesToApply["vm-options"]; } if (attributesToApply.ContainsKey("vm-dataSource")) { HandleDataSourceAttribute(attributesToApply.GetValue("vm-dataSource"), attributesToApply.GetValue("vm-options")); } #endif }