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

Bring window into focus when an app is standalone?

Discussion in 'Scripting' started by csciguy, Dec 28, 2006.

  1. csciguy

    csciguy

    Joined:
    Dec 13, 2006
    Posts:
    22
    All,

    I have a button. This button launches a local html page. This local page displays correctly when I view my scene in unity (via pressing the play button inside unity).

    However, when I build and run my scene outside of unity, the window will not launch.

    Do I need to do anything special to launch an external app (such as a browser) when I am running my scene standalone?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    What does the button do? Have a snippet of what you are doing?
     
  3. csciguy

    csciguy

    Joined:
    Dec 13, 2006
    Posts:
    22
    The button notifies it's parent controller that it has been clicked, upon being clicked, it does this (borrowed from this forum).

    Code (csharp):
    1.  
    2. var filePath = String.Format("{0}/index.html",Application.dataPath);
    3.         switch(Application.platform) {        
    4.         case RuntimePlatform.WindowsPlayer:
    5.             System.Diagnostics.Process.Start(filePath);
    6.                  break;
    7.         default:
    8.             System.Diagnostics.Process.Start(String.Format("open \"{0}\"",filePath));
    9.         break;
    10.         }
    11.  
    Now, "index.html" contains this code.
    Code (csharp):
    1.  
    2. <script type="text/javascript">
    3. var WindowObjectReference;
    4. function openRequestedPopup(strUrl, strWindowName)
    5. {
    6. if(WindowObjectReference == null || WindowObjectReference.closed)
    7.     {
    8.     WindowObjectReference = window.open(strUrl, strWindowName,
    9.     "resizable=yes,scrollbars=yes,status=yes");
    10.     }
    11. else
    12.     {
    13.     WindowObjectReference.focus();
    14.     };
    15. }
    16. </script>
    17.  
    18. (...)
    19.  
    20.  
    21.  
    22. [url="http://www.unity3d.com/"]test[/url]</p>
    23.  
    This pops up a web browser window with a simple url. However, when I launch this from a standalone player, the page never launches.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  5. csciguy

    csciguy

    Joined:
    Dec 13, 2006
    Posts:
    22
    That very well could be it. I'll try it and get back with you. Thanks!
     
  6. csciguy

    csciguy

    Joined:
    Dec 13, 2006
    Posts:
    22
    Okay, that was the problem. The file was not included in the bundle when it was run standalone. What do I need to set to make sure this file is included in every build I'm doing now? In order to test this, I have had to manually drag the index.html file in to the package.

    Also, opening a browser works fine when the screen is windowed. Is it possible to either minimize a fullscreen window, or to bring focus to this new browser window I want to display when I am running my game in fullscreen?
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  8. csciguy

    csciguy

    Joined:
    Dec 13, 2006
    Posts:
    22
    Writing a perl/sh script would do the trick I think.

    Is there any way to make it so that if I am in displaying in fullscreen, to minimize this view and display my window?

    As it works now, it is opening the window, but since I'm in fullscreen, I can't see that is actually happening (until I exit out).
     
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Screen.isFullScreen can be used to both check in what mode you are and also be used set to false to switch to window mode:
    Screen.isFullScreen = false;
     
  10. csciguy

    csciguy

    Joined:
    Dec 13, 2006
    Posts:
    22
    Thank you! That worked great.