Search Unity

GUI Texture color

Discussion in 'Immediate Mode GUI (IMGUI)' started by whittlong, Dec 19, 2007.

  1. whittlong

    whittlong

    Joined:
    Nov 17, 2006
    Posts:
    14
    Am i correct in understanding that the ability to change the color of an individual GUI texture in runtime (not a global tint), which was part of the old GUITexture class, is currently not part of the new UnityGUI system?

    If this is the case, has anyone come across a clean workaround?
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Well, you can apply the "global" tint to a single control :) If you want to only color the background graphic and not the text on top, try something like this:

    Code (csharp):
    1.  
    2. GUI.backgroundColor = Color.Red;
    3. GUILayout.Button ("I'm the Red button");
    4. GUI.backgroundColor = Color.White;
    5. GUILayout.Button ("I'm back to normal");
    6.  
    Now, if you want this as a more general-purpose thing, you just extend UnityGUI... Something like this:

    Code (csharp):
    1.  
    2. static function TintButton (position : Rect, text : string, tintColor : Color) {
    3.   // store the old GUI tint color.
    4.   var oldCol = GUI.backgroundColor;
    5.   GUI.backgroundColor = tintColor;
    6.   var retval = GUI.Button (position, text);
    7.   GUI.backgroundColor = oldCol;
    8.   return retval;
    9. }
    10.  
    Stick this in a class, and you can now do
    Code (csharp):
    1. MyGUI.TintButton (Rect (10,10,200,40), "Why oh why does the GUI not support this out-of-the-box?", Color.Red);
    2.  
     
  3. whittlong

    whittlong

    Joined:
    Nov 17, 2006
    Posts:
    14
    hahaha. i appreciate both the humor and the help Nicholas. That should get me off and running fine for now. thanks.
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Cool! This way of extending UnityGUI small pieces at a time are the way to go...

    When I designed the system, I took a look at what various games did, and found they did just about everything (buttons that wobble on MouseOver? yup, animated rainbow buttons? check, random sound samples? indeed). So I focused on making a solid base that is easy to expand in small pieces for individual games.