Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I use EditorWindow.titleContent()

Discussion in 'Immediate Mode GUI (IMGUI)' started by elmar1028, Sep 9, 2015.

  1. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,355
    Documentation doesn't say whether it's a functions or a static variable.

    Any example on how do I use it?

    Thanks in advance :)
     
  2. edwardrowe

    edwardrowe

    Joined:
    Feb 11, 2014
    Posts:
    52
    I've only used these a bit, but here's what I know. I hope someone else can chime in with more info, but this will hopefully get you started.

    GUIContent is a class used to store more info than just the title. You can also give it an icon and a tooltip. Each EditorWindow stores an instance called titleContent. So to assign a title and an icon you would do this:

    Code (CSharp):
    1. [MenuItem ("RedBlueTools/RBSettings")]
    2. public static void  ShowWindow ()
    3. {
    4.    // Shows an instance of custom window, RBSettings
    5.    RBSettings window = EditorWindow.GetWindow<RBSettings> ();
    6.    // Loads an icon from an image stored at the specified path
    7.    Texture icon = AssetDatabase.LoadAssetAtPath<Texture> ("Assets/Sprites/Gear.png");
    8.    // Create the instance of GUIContent to assign to the window. Gives the title "RBSettings" and the icon
    9.    GUIContent titleContent = new GUIContent ("RBSettings", icon);
    10.    window.titleContent = titleContent;
    11. }
    Oh and just for convenience here's the docs on GUIContent (which are admittedly pretty sparse): http://docs.unity3d.com/ScriptReference/GUIContent.html
     
    Kolgrima and godsinmyroom like this.
  3. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,355
    Got it working. Thanks a lot!

    However my icon is too small. What are the requirements in terms of size?
     
  4. edwardrowe

    edwardrowe

    Joined:
    Feb 11, 2014
    Posts:
    52
    It looks like they shrink it down to 20x20 or so. I'm not sure you can make it bigger in the tab, though, if that's what you are meaning. I suspect Unity wants EditorWindows to look and behave consistently.
     
    elmar1028 likes this.
  5. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,355
    Thanks! Will try it :)
     
  6. Hermes_Zum

    Hermes_Zum

    Joined:
    Aug 29, 2014
    Posts:
    7
    edwardrowe likes this.
  7. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    how would you add icon to non dockable or floating window?