rimworld-animation-studio/Assets/Scripts/Strings/NumberValidator.cs
AbstractConcept 757badf4f6 Code refactor
2022-10-27 00:56:04 -05:00

30 lines
828 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NumberValidator : MonoBehaviour
{
public InputField.CharacterValidation valiationType = InputField.CharacterValidation.Decimal;
public void Start()
{
InputField inputField = GetComponent<InputField>();
if (inputField)
{
inputField.characterValidation = valiationType;
//if (valiationType == InputField.CharacterValidation.Decimal)
//{ inputField.onEndEdit.AddListener(delegate { MakeDecimal(); }); }
}
}
public void MakeDecimal()
{
InputField inputField = GetComponent<InputField>();
if (inputField)
{ inputField.text = string.Format("{0:0.000}", float.Parse(inputField.text)); }
}
}