Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

2 canvas based navigations, but only 1 event system permitted??????

Discussion in 'UGUI & TextMesh Pro' started by FBFrog, Sep 1, 2014.

  1. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    Hi, thanks for reading / helping!

    I made 2 canvas's.

    The first canvas has a navigation for a typical point and click adventure style nav.. examine, speak, open, close etc. this uses the up/down/left/right explicit option enabled. Within this canvas is an eventsystem which makes exam the first highlighted button (unity selected) button. this works fine.



    then i have another canvas with 5 buttons: items, keys, docs, options, save.



    The interaction is if botton nav is on, the top nav is off, this toggles via keypress.

    I can get it to show just fine but, the first active button needs to be items. I can't get any of them to activate unless
    I add another event system. then the highlighted button shows but i get problems :

    1. error about multiple event systems in 1 scene
    2. the buttons end up working, but if i close that 2nd canvas and try to open it again,
    none of the buttons are selected.

    how do i do this correctly??????????????

    I took off the 2nd eventsystem, no errors but i can't turn the item's button into active. HELP!
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    Do you really need more than one canvas? Why not place each group of buttons inside a panel, and call SetActive() on the panels as required?
     
  3. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    okay that sound good, but when i activate the buttons on panel 2, how do i get the first button on panel 2 to be activated at the moment set active is set to true?

    panel 1 start --> exam button is hightighted and panel 2 is off
    panel 2 start --> inventory button is hightlighted and panel 1 is off

    that's basically what i want.
     
  4. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    There's a SetSelectedGameObject() method on the EventSystem class. Get the active one from EventSystemManager.currentSystem.
     
  5. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    what you just said flew right over my head :(

    I'm fairly new to coding and I've been using unity java script.

    code sample for switching gameobjects as they are now, cavases:
    Code (JavaScript):
    1.                         // handles the switches between screen nave and inventory screen
    2.                         if(screen_nav_on == true)
    3.                             {
    4.                                 if(Input.GetButtonDown("Inventory") && top_bar_on == false)
    5.                                     {
    6.                                         screen_nav_on = false;
    7.                                         top_bar.SetActive(true);
    8.                                         screen_nav.SetActive(false);
    9.                                         char_motor.enabled = false;  
    10.                                     }
    11.                             }
    12.                         else
    13.                         if(screen_nav_on == false)
    14.                             {
    15.                                 if(Input.GetButtonDown("Cancel") || Input.GetButtonDown("Inventory"))
    16.                                 {
    17.                                     screen_nav_on = true;
    18.                                     top_bar.SetActive(false);
    19.                                     screen_nav.SetActive(true);
    20.                                     char_motor.enabled = true;  
    21.                                 }
    22.                             }
     
  6. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    is this right ?

    to declare the variable in JS:
    var event_system : UnityEngine.EventSystems.EventSystem;

    in start:
    event_system = event_object.GetComponent(EventSystems.EventSystem);

    so far so good but i get a read only error:
    on input command:
    event_system.currentSelectedObject = item_button;

    i guess that wont exactly work :confused:
     
  7. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    You need to import the right functionality:
    Code (JavaScript):
    1. import UnityEngine.EventSystems;
    Then get the event system and use it to select something:
    Code (JavaScript):
    1. var es : EventSystem = EventSystemManager.currentSystem;
    2. es.SetSelectGameObject(go, null);
    100% untested, because I only write C#. Also 100% undocumented at the moment, it seems. I've found this out only through trial and error.
     
  8. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    I think they're using our trial-and-error discovery process to figure out where the documentation needs most to be improved first.
     
  9. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    That's similar to the engine itself!
     
    Kurt-Dekker likes this.
  10. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    the declatations for these new systems are not as the videos show for c#..

    example:

    @script RequireComponent(UnityEngine.UI.Text)
    var text_component : UnityEngine.UI.Text;

    this is how i got the ui.text using javascript

    start :
    text_component = chat_box.GetComponent(UI.Text);

    So i should replace null with the button gameobject? i will try this now.
    I am also saddened by the lack of unity javascript instructions.
    I mean it's called unityscript and everything lol.
     
  11. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    Code (JavaScript):
    1. #pragma strict
    2. // this script only handles menu visibilities
    3. import UnityEngine.EventSystems;
    4.  
    5. private var player_one : GameObject;
    6.  
    7. var screen_nav : GameObject;
    8. var top_bar : GameObject;
    9.  
    10. private var screen_nav_on : boolean;
    11. private var top_bar_on : boolean;
    12. private var tab_pressed : boolean;
    13. private var cancel_pressed : boolean;
    14.  
    15. private var char_motor : CharacterMotor;
    16. private var event_object : GameObject;
    17.  
    18. var item_button : GameObject;
    19. var exam_button : GameObject;
    20.  
    21. var es : EventSystem = EventSystemManager.currentSystem;
    22.  
    23. function Start ()
    24.     {
    25.         screen_nav_on = true;
    26.         top_bar_on = false;
    27.         tab_pressed = false;
    28.         cancel_pressed = false;
    29.      
    30.         player_one = GameObject.FindGameObjectWithTag("Player");
    31.         exam_button = GameObject.FindGameObjectWithTag("SNexam");
    32.         item_button = GameObject.FindGameObjectWithTag("TBitem");
    33.      
    34.         char_motor = player_one.GetComponent(CharacterMotor);
    35.         top_bar.SetActive(false);
    36.  
    37.     }
    38.  
    39. function Update ()
    40.     {
    41.                         // handles the switches between screen nave and inventory screen
    42.                         if(screen_nav_on == true)
    43.                             {
    44.                                 if(Input.GetButtonDown("Inventory") && top_bar_on == false)
    45.                                     {
    46.                                         es.SetSelectedGameObject(go, null);
    47.                                         es.SetSelectedGameObject(go, item_button);
    48.                                      
    49.                                         screen_nav_on = false;
    50.                                         top_bar.SetActive(true);
    51.                                         screen_nav.SetActive(false);
    52.                                         char_motor.enabled = false;
    53.                                     }
    54.                             }
    55.                         else
    56.                         if(screen_nav_on == false)
    57.                             {
    58.                                 if(Input.GetButtonDown("Cancel") || Input.GetButtonDown("Inventory"))
    59.                                 {
    60.                                     es.SetSelectedGameObject(go, null);
    61.                                     es.SetSelectedGameObject(go, exam_button);
    62.                                  
    63.                                     screen_nav_on = true;
    64.                                     top_bar.SetActive(false);
    65.                                     screen_nav.SetActive(true);
    66.                                     char_motor.enabled = true;
    67.                                 }
    68.                             }
    69.                  
    70.          
    71.  
    72.     }
     
  12. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    ERROR
    InvMenuTabLogic.js(61,98): BCE0005: Unknown identifier: 'go'.
     
  13. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    if i take out "go"

    Assets/NickScript/Inventory V3/TopBarNavLogics/InvMenuTabLogic.js(47,105): BCE0017: The best overload for the method 'UnityEngine.EventSystems.EventSystem.SetSelectedGameObject(UnityEngine.GameObject, UnityEngine.EventSystems.BaseEventData)' is not compatible with the argument list '(UnityEngine.GameObject)'.

    no help on the api scripting docs
     
  14. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    "go" refers to the GameObject you're trying to use. You of course have to replace it with the correct one :)

    And you're not importing the functionality you need; USE the import statement! This is tedious:
    Code (JavaScript):
    1. var text_component : UnityEngine.UI.Text;
    This is much better:
    Code (JavaScript):
    1. import UnityEngine.UI;
    2. var text_comp : Text;
    That way you don't type your fingers bloody ;)
     
  15. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28

    Sorry to keep bugging you but.. lol
    es.SetSelectedGameObject(exam_button, null);

    this works in deactivating the exam button but unity says it needs a pointer after that, i dont understand what that means.

    i tried :
    es.SetSelectedGameObject(exam_button, active );
    but this game me a boolean error.

    i cant find any resources besides what i find when i type in monodevelop, it wants a gameobject, ( the button, and a pointer ???). how do i activate or make it selected. Im dumb.
     
  16. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,043
    I'm not sure how that works in UnityScript. The second parameter should be an event, though. If you use MonoDevelop you should be seeing hints for the parameters while typing. This is the only documentation you have for now.
     
  17. FBFrog

    FBFrog

    Joined:
    Sep 4, 2013
    Posts:
    28
    thank you so much for your help orb, i will keep working on the setselectedobject(). thank you for pointing me the right way. I have a feeling it's more of a syntax issue rather than anything. i'll update if i figure it out :D