Search Unity

Can't use GUI.changed with GUI.Textfield, GUI.Button... ??

Discussion in 'Immediate Mode GUI (IMGUI)' started by grojguy, Jan 25, 2010.

  1. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    I realy hope I'm not being a complete maroon here, and yes I've searched....but, it seems that GUI.changed does not flag clicks or changes to GUI.Textfield? It seems to me that would be real handy, just like it is for the other GUI controls.

    Code (csharp):
    1.     void OnGUI()
    2.     {
    3.         text1 = GUI.TextField(new Rect(50, 50, 100, 100), text1);
    4.  
    5.         if( GUI.changed )
    6.             print( "text field change");
    7.     }
    8.  
     
  2. wisly

    wisly

    Joined:
    Jan 18, 2010
    Posts:
    12

    I don't think the method GUI.changed is a good idea, what if you have lots of GUI components with different types?
    I prefer codes like this:
    Code (csharp):
    1.  
    2. TextField myText1=new GUI.TextField();
    3. myText1.setLocation(new Rect(0,0,100,100));
    4. myText1.setTexture(myTexture);
    5. string content="show here";
    6. myText1.setContent(content);
    7. myText1.Show();//show the textfield on the screen
    8. if(myText1.isChanged)
    9. {
    10.   Debug.Log("new textField content:"+content);
    11. }
    12.  
     
  3. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    wisly, thank you, I appreciate the reply. I like your idea. However, in your example, you are using TextField as a type, which it is not (it is a method). And you are using "setLocation" and those other methods, which I can find nowhere, expecially not "isChanged". ??? Am I missing something?
     
  4. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
    I would do something like:
    Code (csharp):
    1.  
    2. private string typedText;
    3.  
    4. void OnGUI()
    5. {
    6.     string newText = GUI.Textfield(new Rect(),typedText);
    7.  
    8.     if(newText != typedText)
    9.     {
    10.         Debug.Log("Textfield changed!");
    11.     }
    12.  
    13.     typedText = newText;
    14. }
    15.  
     
  5. wisly

    wisly

    Joined:
    Jan 18, 2010
    Posts:
    12
    No, you are not.
    That kind of method is just what I think.
    it's not really provided by the unity3d at this time.
    In fact,
    Lukas 's suggestion is really useful and possible.
    or maybe you can create a custom class to implement that.