/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/UI_Logic/MainMenuPart/InputFields/InputFieldFloatView.cs
76 строк
2 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using System; using System.Globalization; using TMPro; using UnityEngine; namespace UI_Logic.InputFields { public class InputFieldFloatView<TDataType> : MonoBehaviour where TDataType : Enum { private TMP_InputField _field; [SerializeField] private TDataType _type; private void Awake() { EnsureField(); if (_field != null) { _field.contentType = TMP_InputField.ContentType.DecimalNumber; } } public float GetValue() { EnsureField(); if (_field == null) { return 0f; } string text = _field.text.Replace(',', '.'); if (float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out float result)) { return result; } return 0f; } public void SetValue(float value) { EnsureField(); if (_field == null) { return; } _field.text = value.ToString(CultureInfo.InvariantCulture); } private void EnsureField() { if (_field != null) { return; } _field = GetComponentInChildren<TMP_InputField>(true); if (_field == null) { Debug.LogError("[UI_Logic.InputFields.InputFieldFloatView] TMP_InputField not found in children."); } } public TDataType GetTypeData() { if (Convert.ToInt32(_type) == 0) { Debug.LogWarning("[UI_Logic.InputFields.InputField] Input field type is None"); } return _type; } } }