Files
Simulation/Assets/Generic Client/UIExtensions.cs
2025-05-27 10:13:49 +09:00

40 lines
965 B
C#

using System;
using Best.MQTT.Packets;
using UnityEngine.UI;
namespace Best.MQTT.Examples
{
public static class UIExtensions
{
public static string GetValue(this InputField field)
{
var value = field.text;
return value;
}
public static string GetValue(this InputField field, string defaultValue)
{
var value = field.text;
return string.IsNullOrEmpty(value) ? defaultValue : value;
}
public static int GetIntValue(this InputField field, int defaultValue)
{
return int.TryParse(field.text, out var value) ? value : defaultValue;
}
public static bool GetBoolValue(this Toggle toggle)
{
return toggle.isOn;
}
public static QoSLevels GetQoS(this Dropdown dropdown)
{
return ((QoSLevels[])Enum.GetValues(typeof(QoSLevels)))[dropdown.value];
}
}
}