• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Fattie · Apr 14, 2013 at 05:44 PM · passwordfield

Is GUI.PasswordField buggered ? ... iPad / iPhone

I just noticed that - perhaps on the latest iOS -

GUI.PasswordField really doesn't work. In the (infuriating) small text display attached to the iOS keyboard, it shows •••••••.

BUT in the GUI.PasswordField in your Unity scene, it seems to swap to clear text (as if a GUI.TextField).

Anyone noticed ??


Note it is totally broken as of mid-2013

Google many questions on t$$anonymous$$s eg

http://forum.unity3d.com/threads/65337-GUI-PasswordField-issue

http://answers.unity3d.com/questions/398391/guipasswordfield-display-password-w$$anonymous$$le-editing-.html

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Fattie · Apr 15, 2013 at 09:38 AM

It's true that surprisingly, as of mid-2013,

the function GUI.PasswordField is completely broken and not-usable - just seems to be how it is!

Note too that GUI.TextField is essentially unusable, it has various minor problems.


Here's some workaround code w$$anonymous$$ch who knows may help future readers...

have two normal "buttons" in your scene that work exactly like your other buttons (ie, using 2DToolkit or whatever - i don't mean "GUI buttons" - never use those for any reason)

make them simply flat squares of color - that is exactly as if it looks like a text input field (gray or whatever you want0 -- so literally just a long stretched cube or maybe a simple plain color 2DToolkit sprite stretch to the size you want.

Easy fake input fields!

alt text

 private var positionEmail:GameObject;        // it's a quasi button
 private var positionPassword:GameObject;    // it's a quasi button

 // do t$$anonymous$$s in awake or whatever....
 fieldPositionA = FindUnderHereNamed("positionEmail").gameObject;
 fieldPositionB = FindUnderHereNamed("positionPassword").gameObject;



so, however you treat the other notmal buttons in your scene (say "OK" etc etc) .. treat the two "fake" buttons like t$$anonymous$$s:

 if ( nn == "positionEmail" ) // that's a normal button n a collider, just a square of color
 // i just call them "position" because they're clever position markers
     {
     Debug.Log(" POS EMAIL");
     
     keyboard = TouchScreenKeyboard.Open(
         "", TouchScreenKeyboardType.EmailAddress, false, false, true);
     // the three fields are autocorr, multiline, secure-style
     
     // funnily enough it's best to use "secure style" (t$$anonymous$$rd arguments there)
     // for the username as well as the passwd field - since - that avoids
     // the ridiculous "defaults to caps lock" problem that Apple helpfully offers
     // for clarity recall that we are not seeing the small line of text
     // just above the keyboard that Apple offers (see next line of code)
     // w$$anonymous$$ch would be dots with "secure style" on so that's irrelevant
     // Also remember we're totally drawing the actual text display all on our
     // own so again it's irrelevant for that issue.  so that's why you use
     // secure-style true even for a plain text field like username
     
     keyboard.$$anonymous$$deInput = true;
     
     textInputIsNow = 1;
     // our code is 1 for username, 2 for passie, 0 for, well, nut$$anonymous$$n being entered
     
     transform.localPosition.y = 0.7;
     isElevated = true;
     
     return;
     }
 if ( nn == "positionPassword" )
     {
     Debug.Log(" POS PASSWORD");
     
     keyboard = TouchScreenKeyboard.Open(
         "", TouchScreenKeyboardType.EmailAddress, false, false, true);
     
     // EmailAddress is about the best, for both
     
     keyboard.$$anonymous$$deInput = true;
     
     textInputIsNow = 2;
     
     transform.localPosition.y = 0.7;
     isElevated = true;
     
     return;
     }

next note that in your OTHER CONVENTION BUTTONS (say "ok" or whatever) add t$$anonymous$$s

 if ( nn == "bbOK" )
     {
     if ( isElevated ) return; // turn off conventional buttons when typing
     .. blah
     }

Next, here is basically the code to make it work tidily. Note that in t$$anonymous$$s example (see above and below) I move the whole input area to "0.7" (of course you move it up typically when the user is using the keyboard to more clearly show the user/pass fields on the screen above the keyboard) (Obviously you could use a marker object or somet$$anonymous$$ng to move it to no big deal.)

 //////////////////////////////////////////////////////////////////////////////
 
 private var TFAA:String;
 private var TFBB:String;
 
 private var rectAA:Rect;
 private var rectBB:Rect;
 
 var bigType:GUIStyle;
 
 private var keyboard:TouchScreenKeyboard = null;
 
 private var textInputIsNow:int = 0;        // 1 for username, 2 for pass
 
 private var fieldPositionA:GameObject;
 private var fieldPositionB:GameObject;
 
 function OnGUI ()
     {
     if ( ! UIAvailableHere )
         return;
     
     _setTextFieldRects();
 
     if ( textInputIsNow == 1 ) TFAA = keyboard.text;
     if ( textInputIsNow == 2 ) TFBB = keyboard.text;
     // be careful not to change them if it is zero
     
     GUI.Label( rectAA, TFAA, bigType );
     GUI.Label( rectBB, _dots(TFBB), bigType );
     
     if (    keyboard != null &&
             ( keyboard.done || keyboard.wasCanceled || ( ! keyboard.active) )
             )
         {
         textInputIsNow = 0;
         // and thus don't change them anymore
         
         keyboard = null;
         
         isElevated = false;
         transform.localPosition.y = 0;
         
         _setOKAVailable();
         }
     }
 
 function _dots(ss:String)
     {
     var nn:int = ss.Length;
     var rr:String = "";
     for ( var k:int=0; k<nn; ++k ) rr += "•";
     return rr;
     }
 
 //////////////////////////////////////////////////////////////////////////////

finally t$$anonymous$$s code will basically set it up

note that I use t$$anonymous$$s critical silly trick http://answers.unity3d.com/questions/438098/changing-font-size-per-screen-height-do-you-do-t$$anonymous$$.html to set the !$!#$ing point size of the @#$@#$ guilabel type correctly. So where it says "50" -- simply in Editor (w$$anonymous$$ch is 768 height of course) I found a size i want w$$anonymous$$ch happened to be "50" nominal, t$$anonymous$$s trick will make it look fairly-close to that on all devices. (well all apple touch devices at least :O )

 function beginForm()
     {
     bbCancel.collider.enabled = true;
     bbOK.collider.enabled = true;
     
     TFAA = "username enter it";
     TFBB = "password";
     
     _setOKAVailable();
     
     UIAvailableHere = true;
     
     Debug.Log("start fresh");
     
     var calcSize:float;
     calcSize = (Screen.height * 1.0f) / 768.0f;
     calcSize = calcSize * 50.0f;
     
     bigType.fontSize = Mathf.RoundToInt( calcSize );
     
     Debug.Log("font size settings ... " + bigType.fontSize + " " + Screen.height);
     
     transform.localPosition.y = 0;
     isElevated = false;
     }
 
 var isOKAvailable:boolean;
 
 function _setOKAVailable()
     {
     // note never use proper stateful programming when you
     // can have cheap spaghetti code...
     if ( TFAA == "username enter it" || TFBB == "password"
             || TFAA == "" || TFBB == "" )
         isOKAvailable = false;
     else
         isOKAvailable = true;
     
     if ( isOKAvailable )
         bbOK.GetComponent(tk2dSprite).color.a = 1.0;
     else
         bbOK.GetComponent(tk2dSprite).color.a = 0.4;
     }
 /////////////////////////////////////////////////////////////////////////////
 
 function _setTextFieldRects()
 // magically make label fields (you could also use it for TextField - if that worked)
 // the same size as your fake fields, see image up above
 // you can simply change the fake-fields in your editor (even w$$anonymous$$le running)
 // and it will all work
     {
     var bAA:Bounds = fieldPositionA.renderer.bounds;
     var bBB:Bounds = fieldPositionB.renderer.bounds;
     
     var TL:Vector2;
     var TLgui:Vector2;
     var BIG:Vector2;
     
     ///
     
     TL.y = Camera.main.WorldToScreenPoint( bAA.center + bAA.extents ).y;
     TL.x = Camera.main.WorldToScreenPoint( bAA.center - bAA.extents ).x;
     
     BIG.x =
         Camera.main.WorldToScreenPoint(bAA.max).x -
         Camera.main.WorldToScreenPoint(bAA.min).x;
     BIG.y =
         Camera.main.WorldToScreenPoint(bAA.max).y -
         Camera.main.WorldToScreenPoint(bAA.min).y;
     
     TLgui = TL;
     TLgui.y = Screen.height - TLgui.y;
     
     rectAA = new Rect( TLgui.x, TLgui.y, BIG.x, BIG.y );
     
     ///
     
     TL.y = Camera.main.WorldToScreenPoint( bBB.center + bBB.extents ).y;
     TL.x = Camera.main.WorldToScreenPoint( bBB.center - bBB.extents ).x;
     
     BIG.x =
         Camera.main.WorldToScreenPoint(bBB.max).x -
         Camera.main.WorldToScreenPoint(bBB.min).x;
     BIG.y =
         Camera.main.WorldToScreenPoint(bBB.max).y -
         Camera.main.WorldToScreenPoint(bBB.min).y;
     
     TLgui = TL;
     TLgui.y = Screen.height - TLgui.y;
     
     rectBB = new Rect( TLgui.x, TLgui.y, BIG.x, BIG.y );
     
     ///
     
     // Destroy(fieldPositionA);
     // Destroy(fieldPositionB);
     }
 
 /////////////////////////////////////////////////////////////////////////////

Ultimately when the person clicks your "OK" button it is yourBoss.theyClickedOK( TFAA, TFBB );

What a pain !!!


fakebuttons.png (21.7 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ByteSheep · Apr 14, 2013 at 05:56 PM

Using the following code works fine for me (running in unity 4.0.1 for pc/mac standalone):

 var passwordToEdit : String = "My Password";
 
 function OnGUI () {
     // Make a password field that modifies passwordToEdit.
     passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Apr 14, 2013 at 06:22 PM 0
Share

Ahhh .. I appreciate that report. tragically this is iFone ... perhaps there's a plain bug in iPhone, sucks. Thanks...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

TextFields Android issue: switching between different fields it copies the string 0 Answers

What is Store Password in Android CloudBuild? 1 Answer

How to change Input Field 'Content Type' at runtime to toggle between asterisks and letters? 1 Answer

password filed and text field 2 Answers

Is this a secure way to collect passwords? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges