Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: JasonABentley on November 20, 2014, 03:15:51 PM

Title: UIInput: Use the current label value as Starting Value
Post by: JasonABentley on November 20, 2014, 03:15:51 PM
My label represents a length value and changes as the user moves the end points.

The user clicks on the Collider for the UIInput and because the StartingValue is empty, it makes the label.text empty.

I had hoped to that it was as simple as creating a new class that inherits from UIInput and overrides the OnSelect or OnPress and assigns the mDefaultText to label.text before the UpdateLabel but that doesn't work.

Anyone attempted something like this before and have any suggestions?


  1. public class UIInput_LengthIndicator : UIInput {
  2.         protected override void OnPress (bool isPressed)
  3.         {
  4.                
  5.                
  6.                 mDefaultText = label.text;
  7.  
  8.                 if (isPressed && isSelected && label != null && UICamera.currentScheme == UICamera.ControlScheme.Mouse)
  9.                 {
  10.                         mSelectionEnd = GetCharUnderMouse();
  11.                         if (!Input.GetKey(KeyCode.LeftShift) &&
  12.                             !Input.GetKey(KeyCode.RightShift)) mSelectionStart = mSelectionEnd;
  13.  
  14.                         UpdateLabel();
  15.                 }
  16.         }
  17. }
Title: Re: UIInput: Use the current label value as Starting Value
Post by: JasonABentley on November 24, 2014, 01:02:47 PM
Ok, no responses.

Does that mean that people find it odd to want to do this or that they consider the question incredibly easy to solve?
Title: Re: UIInput: Use the current label value as Starting Value
Post by: ArenMook on November 25, 2014, 01:27:06 AM
I don't understand your question. If you want the input field to start with some value, then give it a value.

input.value = "Some text";
Title: Re: UIInput: Use the current label value as Starting Value
Post by: JasonABentley on November 25, 2014, 11:19:46 AM
Got it.

I was attempting to change the "DefaultText" rather than just setting the value directly.

Thank you.