您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
52 行
1.9 KiB
52 行
1.9 KiB
using System;
|
|
using System.Globalization;
|
|
|
|
namespace UnityEngine.UIElements
|
|
{
|
|
/// <summary>
|
|
/// <para>Describes a XML int attribute.</para>
|
|
/// </summary>
|
|
public class UxmlUIntAttributeDescription : TypedUxmlAttributeDescription<uint>
|
|
{
|
|
/// <summary>
|
|
/// <para>Constructor.</para>
|
|
/// </summary>
|
|
public UxmlUIntAttributeDescription()
|
|
{
|
|
type = "int";
|
|
typeNamespace = "http://www.w3.org/2001/XMLSchema";
|
|
defaultValue = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>The default value for the attribute, as a string.</para>
|
|
/// </summary>
|
|
public override string defaultValueAsString => defaultValue.ToString(CultureInfo.InvariantCulture.NumberFormat);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Retrieves the value of this attribute from the attribute bag. Returns it if it is found, otherwise return
|
|
/// defaultValue.
|
|
/// </para>
|
|
/// </summary>
|
|
/// <param name="bag">The bag of attributes.</param>
|
|
/// <param name="cc">The context in which the values are retrieved.</param>
|
|
/// <returns>
|
|
/// <para>The value of the attribute.</para>
|
|
/// </returns>
|
|
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;
|
|
}
|
|
}
|
|
}
|