/InputFieldAddon.cs Secret
Last active
June 30, 2023 13:33
[Unity/Android] InputField 와 친해지기 (part. 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool keepOldTextInField; | |
private string oldText; | |
private string editText; | |
public void SetInputFieldListener(TMP_InputField input) | |
{ | |
input.onSelect.AddListener(OnSelect); | |
input.onValueChanged.AddListener(OnValueChanged); | |
input.onTouchScreenKeyboardStatusChanged.AddListener(OnStatusChanged); | |
input.onDeselect.AddListener((value) => { | |
if (keepOldTextInField) | |
{ | |
input.text = oldText; | |
keepOldTextInField = false; | |
} | |
}); | |
} | |
private void OnSelect(string currentText) | |
{ | |
oldText = currentText; | |
} | |
private void OnValueChanged(string currentText) | |
{ | |
oldText = editText; | |
editText = currentText; | |
} | |
private void OnStatusChanged(TouchScreenKeyboard.Status status) | |
{ | |
if (status == TouchScreenKeyboard.Status.Canceled) | |
{ | |
keepOldTextInField = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment