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

Reusing GUIStyle: Inconsistent?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Joe ByDesign, Oct 12, 2007.

  1. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    It seems declaring GUIStyle as a var always creates a new style; it is not a project resource. This makes re-using existing styles a PITA (and is inconsistent with other resource usage in Unity).

    Example: Typically if i access a resource of var type Texture2D, then the inspector for that var sees all objects of type Texture2D in the project. However, this is not the case when declaring a var as type GUIStyle... it creates a new GUIStyle right then and there.

    Consistency is a big part of what makes a good interface (more than is often realized) so naturally I wish to make a few styles and reuse them in various GUI scripts.

    The current "non-project resource" implementation of GUIStyle seems to encourage that if I wish to reuse a style I must:
    • - create a GUI script with the GUIStyle, setting all the many vars as I desire
      - in my other GUI script, manually recreate the style, manually copying all the settings (did I mention there are many variables!?)
      - recreate it again for each individual GUI script
      - repeat ad nauseum
    E.g. it gets inefficient very quickly if I want to reuse styles.

    To avoid this, I'm currently creating GUIStyles in a single GUIManager class, then using an helper function GetGUIStyle() to access them in individual GUI scripts, via string parsing.

    Although it "works" this seems a very primitive way to deal with such a resource, in contrast to how Unity otherwise adeptly deals with resources (adding, the current approach also makes using @script ExecuteInEditMode() useless for GUI scripts, creating yet another step between creating the GUI and seeing the result).

    Why is GUIStyle not a project resource? Am I missing a fundamental aspect of the new GUI paradigm here?

    It's not much of an issue if you always use the default style, but as nice as it is, I don't always want to use Arial and do not want my GUI looking like every other Unity game, so the default is not very interesting as a creator.

    Why the inconsistency?
     
  2. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    Just use Asset->Create->GUI Skin, and work with that.

    The default one is just for convenience, so you don't have to create the look before beginning to work... of course we don't expect that many games will be re-using the default skin, good looking as it is.

    d.
     
    codestage and dpw like this.
  3. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Thanks for the tip David. I'll look into it.

    Curious, why isn't the default skin re-created when using Asset->Create->GUI Skin?

    It would seem that extending the existing GUISkin would be more useful than a base one, at least to get started.
     
  4. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    Not sure what you mean --

    Asset->Create->GUI Skin will create a duplicate of the stock base skin in your project folder that you can customize.

    If you want to duplicate your customized skin to make further modifications (say to re-skin custom styles), you can just duplicate it in the Project view like any other asset (and package it to copy between projects, etc.)

    Is that what you're talking about?
     
  5. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Sorry I wasn't more specific. Was referring more to the fact that the images used in the default skin cannot be accessed otherwise (try it).

    It's "there" in the default skin you created, but you cannot access it directly or restore it if you try another image, and want to switch back.

    A quick look seems that the default skin images are not in the Unity.app package either, so extending from it is also out of the question (until the images are released publically).


    It seems strange the new GUI system doesn't encourage a trial refine flow (the heart of all good interactive content), as much as the rest of Unity encourages it (the most major and useful selling point imo).

    It's the same with the default particle texture... just quirky that it's "there" but "not there".
     
  6. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    Ah, OK. Here's the built-in skin (distributed during the testing phase of 2.0). You can install it in your project to revert back to it, as well as to modifiy the individual elements.

    EDIT: file comments are Nicholas'
     

    Attached Files:

  7. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Yes I have that as well Steve, but my question remains...
     
  8. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    I see your point. But if you instantiate a new copy of the GUISkin, and install the source images in your project, you can swap textures around to your heart's content. It's true that there's no automatic "revert" to the "original copy", but with the source images, you can pretty quickly reset them to the same image as used in the default skin.

    I don't mean to dismiss your issue, but I have felt very free to experiment and haven't had too much trouble putting things back if I needed.
     
  9. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Sorry about the late reply.

    Yes, Once that was made clear, I'm finding that is true also.

    I guess we can say feature wise, it's rocking... but workflow-wise, uh... "needs work" :)
     
  10. dpw

    dpw

    Joined:
    May 20, 2014
    Posts:
    6
    Thanks, i had no idea! :))))))))))))))) That's really helpful!