miepzerino
2025-03-29 ad79d9ca49274cc660fc2030a071b24314f0f210
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#if UNITY_TMPRO
 
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
 
namespace Flexalon.Samples
{
    // Provides the text of an TMP_InputField as a data source which can be assigned to a FlexalonCloner.
    [AddComponentMenu("Flexalon Samples/Input Field Data Source")]
    public class InputFieldDataSource : MonoBehaviour, DataSource
    {
        [SerializeField]
        private TMP_InputField _inputField;
        public TMP_InputField InputField
        {
            get => _inputField;
            set
            {
                _inputField = value;
                UpdateData(_inputField.text);
            }
        }
 
        public event Action DataChanged;
 
        private List<string> _data = new List<string>();
        public IReadOnlyList<object> Data => _data;
 
        void OnEnable()
        {
            _inputField.onValueChanged.AddListener(UpdateData);
            UpdateData(_inputField.text);
        }
 
        void OnDisable()
        {
            _inputField.onValueChanged.RemoveListener(UpdateData);
        }
 
        private void UpdateData(string text)
        {
            _data.Clear();
            foreach (char c in text)
            {
                _data.Add(c.ToString());
            }
 
            DataChanged?.Invoke();
        }
    }
}
 
#endif