public string SetInputText(string inputText, ref int insertPt) { // Validate our input: if (!multiline) { int idx; // Check for Enter: if ((idx = inputText.IndexOf('\n')) != -1) { inputText = inputText.Remove(idx, 1); UIManager.instance.FocusObject = null; } if ((idx = inputText.IndexOf('\r')) != -1) { inputText = inputText.Remove(idx, 1); UIManager.instance.FocusObject = null; } } // Apply custom validation if (validationDelegate != null) { inputText = validationDelegate(this, inputText); } if (inputText.Length > maxLength && maxLength > 0) { // Set our changed delegate to null so we can // assign to our Text property without firing // it in order that the delegate gets the // correct value for maxLengthExceeded: EZValueChangedDelegate tempDel = changeDelegate; changeDelegate = null; Text = inputText.Substring(0, maxLength); insert = Mathf.Clamp(insertPt, 0, maxLength); maxLengthExceeded = true; changeDelegate = tempDel; if (changeDelegate != null) { changeDelegate(this); } if (fieldFullSound != null) { fieldFullSound.PlayOneShot(fieldFullSound.clip); } } else { Text = inputText; insert = insertPt; if (typingSoundEffect != null) { typingSoundEffect.PlayOneShot(typingSoundEffect.clip); } if (changeDelegate != null) { changeDelegate(this); } } /* * if (text.Length > 0) * { * if (caret != null) * if (caret.IsHidden()) * ShowCaret(); * } * else * HideCaret(); */ if (caret != null) { if (caret.IsHidden() && hasFocus) { caret.Hide(false); } } // It's okay, PositionCaret() checks to see // if caret is null, and it performs some // non-caret functions too: PositionCaret(); // See if enter was pressed and we didn't already handle it: if (UIManager.instance.FocusObject == null && !commitOnLostFocus) { Commit(); } return(text); }
public string SetInputText(string inputText, ref int insertPt) { // Validate our input: if (!multiline) { int idx; // Check for Enter: if ((idx = inputText.IndexOf('\n')) != -1) { inputText = inputText.Remove(idx, 1); UIManager.instance.FocusObject = null; } if ((idx = inputText.IndexOf('\r')) != -1) { inputText = inputText.Remove(idx, 1); UIManager.instance.FocusObject = null; } } if (inputText.Length > maxLength && maxLength > 0) { Text = inputText.Substring(0, maxLength); insert = Mathf.Clamp(insertPt, 0, maxLength); if (fieldFullSound != null) { fieldFullSound.PlayOneShot(fieldFullSound.clip); } } else { Text = inputText; insert = insertPt; if (typingSoundEffect != null) { typingSoundEffect.PlayOneShot(typingSoundEffect.clip); } if (changeDelegate != null) { changeDelegate(this); } } /* * if (text.Length > 0) * { * if (caret != null) * if (caret.IsHidden()) * ShowCaret(); * } * else * HideCaret(); */ if (caret != null) { if (caret.IsHidden() && hasFocus) { caret.Hide(false); } PositionCaret(); } // See if enter was pressed: if (UIManager.instance.FocusObject == null) { Commit(); } return(text); }