using System; using System.Globalization; namespace UnityEngine.UIElements { /// /// Describes a XML int attribute. /// class UxmlUIntAttributeDescription : TypedUxmlAttributeDescription { /// /// Constructor. /// public UxmlUIntAttributeDescription() { type = "int"; typeNamespace = "http://www.w3.org/2001/XMLSchema"; defaultValue = 0; } /// /// The default value for the attribute, as a string. /// public override string defaultValueAsString => defaultValue.ToString(CultureInfo.InvariantCulture.NumberFormat); /// /// /// Retrieves the value of this attribute from the attribute bag. Returns it if it is found, otherwise return /// defaultValue. /// /// /// The bag of attributes. /// The context in which the values are retrieved. /// /// The value of the attribute. /// public override uint GetValueFromBag(IUxmlAttributes bag, CreationContext cc) { return GetValueFromBag(bag, cc, (s, i) => ConvertValueToUInt(s, i), defaultValue); } public bool TryGetValueFromBag(IUxmlAttributes bag, CreationContext cc, ref uint value) { return TryGetValueFromBag(bag, cc, (s, i) => ConvertValueToUInt(s, i), defaultValue, ref value); } static uint ConvertValueToUInt(string v, uint defaultValue) { return v == null || !uint.TryParse(v, out uint result) ? defaultValue : result; } } }