1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using UnityEngine;
- using UnityEngine.UIElements;
- using UnityEditor.UIElements;
- namespace UnityEditor.VFX.UI
- {
- class VFXStringField : ValueControl<string>
- {
- protected TextField m_TextField;
- public TextField textfield
- {
- get { return m_TextField; }
- }
- void CreateTextField()
- {
- m_TextField = new TextField(-1, false, false, '*');
- m_TextField.AddToClassList("textfield");
- m_TextField.RegisterCallback<ChangeEvent<string>>(OnTextChanged);
- m_TextField.value = "";
- }
- public VFXStringField(string label) : base(label)
- {
- CreateTextField();
- style.flexDirection = FlexDirection.Row;
- Add(m_TextField);
- }
- public VFXStringField(Label existingLabel) : base(existingLabel)
- {
- CreateTextField();
- Add(m_TextField);
- }
- void OnTextChanged(ChangeEvent<string> e)
- {
- if (m_Value != m_TextField.text)
- {
- m_Value = m_TextField.text;
- if (OnValueChanged != null)
- {
- OnValueChanged();
- }
- }
- }
- bool m_Indeterminate;
- public bool indeterminate
- {
- get
- {
- return m_Indeterminate;
- }
- set
- {
- m_Indeterminate = value;
- ValueToGUI(true);
- }
- }
- protected override void ValueToGUI(bool force)
- {
- if (indeterminate)
- {
- m_TextField.value = "_";
- m_TextField.SetEnabled(false);
- }
- m_TextField.value = m_Value != null ? m_Value : "";
- }
- }
- }
|