Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Only one menu-point should be active and visible...

Discussion in 'Immediate Mode GUI (IMGUI)' started by alexander, Apr 10, 2008.

  1. alexander

    alexander

    Joined:
    Mar 28, 2008
    Posts:
    180
    Hi

    up to now my code is looking like that:
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. import UnityEngine.GUILayout;
    5.  
    6. var Hmm : Texture;
    7. var title = "MainMenu";
    8. var instructions  = "";
    9.  
    10. function OnGUI () {
    11.     BeginArea (Rect (10, Screen.height - 80, 700, 50), "MainMenu", GUI.skin.window);
    12.    
    13.     BeginHorizontal();
    14.         for (var i : MonoBehaviour in GetComponents (MonoBehaviour)) {
    15.             if (i != this)
    16.                 i.enabled = Toggle (i.enabled, i.GetType().ToString (), "button"); 
    17.         }
    18.     EndHorizontal();
    19.  
    20.     Label (instructions);
    21.  
    22.     EndArea ();
    23. }
    24.  
    Perhaps someone recognize this code.
    This script creates a menu which is filled with buttons. The title of the buttons were taken from names of other attached scripts.
    e.g. I've got Scripts with following names: Banana, Strawberry and Citrus --> so with the code you get a menu with three buttons labeled with Banana, Strawberry, Citrus.
    But my problem is now, if I click on Banana and Citrus both scripts were active and you also can see both. But you want to see certainly either banana or citrus...
    So, which command do I need instead of "toggle" in my if-loop?

    Or is it a completely different way I have to go?

    Thanks
     
  2. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Bascially what you are trying to achieve is the equivalent of a radio button grid where only on can button can be active at a time?
     
  3. alexander

    alexander

    Joined:
    Mar 28, 2008
    Posts:
    180
    Hmm, yes right.
    But how to manage?
    "button" instead of "toggle" isn't the solution.
    I've changed this line:
    i.enabled = Toggle (i.enabled, i.GetType().ToString (), "button");
    by
    i.enabled = Button (i.GetType().ToString (), "button");

    But when I'm clicking on a button, I see only for a millisecond what I want too see.
    With the "banana"-example explained:
    If a picture of the respectivly fruit will be shown,
    in my case the picture is shown only fpr a little time.
    Ideas?
     
  4. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Maybe you're looking for GUILayout.SelectionGrid.
    Code (csharp):
    1. CurrentSelection = GUILayout.SelectionGrid(CurrentSelection, SelectionGuiContents);
    It takes an array of GUIContent's. The Active/Inactive GUIStyles can be controlled in the GUISkin or created on the fly and assigned to the SelectionGrid.
     
  5. alexander

    alexander

    Joined:
    Mar 28, 2008
    Posts:
    180
    @ shaun

    Hi
    and at which place in the code I've got to insert it?
    Or instead of which part?
    Haven't heard about SelectionGrid up to now.
     
  6. alexander

    alexander

    Joined:
    Mar 28, 2008
    Posts:
    180
    Hmm, I "solved" the problem now with individual adjusting of the buttons, cause the selectionGrid respectivly the toolbar (1-row is enough) didn't work.

    I've got now an if-loop, but I don't know, how to open another script, when I click a button.
    e.g. I wanna see a map with 1400x1400 px.
    In my main menu I've got the button "MAP" and when I click it, it should show me a sub menu with functions like "lens", "up-down-left-right" above the main and a map in my content area in original size.

    How would you solve it? With an extra script or everything in one big script?
    And if an extra scipt, how would you "jump"?

    Is there anywhere a script in the big unity-forum/-wiki?

    Thank you for your help
    :)
    alex