Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Solved][WebPlayer] Opening new tab using a button and focus issues

Discussion in 'UGUI & TextMesh Pro' started by AnonDreamer, Nov 3, 2015.

  1. AnonDreamer

    AnonDreamer

    Joined:
    Oct 28, 2014
    Posts:
    30
    Hi there ^^

    So here's my problem, i have a webplayer / webGL project, where i can open new tabs clicking on a button. But when i do, the button is stuck in "pressed mode" (unless i go back to my game tab and click anywhere on the screen), and when i click on the new tab opened, the tab keeps opening again, as if the button still is selected and intercept the mouse click.

    So, i looked a bit in the UI Button documentation, but didn't find how to break the focus on the button, when i click on it so that i can avoid this issue.

    Do you have any idea how to do this ?

    Thank you for reading :)
     
  2. AnonDreamer

    AnonDreamer

    Joined:
    Oct 28, 2014
    Posts:
    30
    Ok so i managed to fix this doing the following things:
    - i added 2 functions in the php page hosting the game using jquery:
    Code (CSharp):
    1. $(window).focus(function()
    2. {
    3.     console.log("we have focus");
    4.  
    5.     var unityObj = retrieveUnityObj();
    6.  
    7.     if(unityObj != undefined && unityObj != null)
    8.     {
    9.         //allow to open links
    10.         retrieveUnityObj().SendMessage("AnswerSheetScreen", "AllowToOpenLink", "");
    11.     }
    12. });
    13.  
    14. $(window).blur(function()
    15. {
    16.     console.log("WE LOST FOCUS");
    17.  
    18.     var unityObj = retrieveUnityObj();
    19.  
    20.     if(unityObj != undefined && unityObj != null)
    21.     {
    22.         //block links
    23.         retrieveUnityObj().SendMessage("AnswerSheetScreen", "BlockAnyLinkOpening", "");
    24.     }
    25. });
    26.    
    So that i can detect when the players leaves the current tab, and when he goes back.
    It solves the issue.

    Also, to get the button out of the "selected state", i just used this to focus another object:
    Code (CSharp):
    1. EventSystem.current.SetSelectedGameObject(_uiText.gameObject);