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

Borderless unitys

Discussion in 'Made With Unity' started by Pixelstudio_nl, Jun 20, 2011.

  1. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    Hello people,

    Im looking for a sollution to have multiple unity's running and having them borderless.
    Here is a example of what i have now :



    The code :
    Code (csharp):
    1.  
    2. /*
    3.  
    4.  * Custom fullscreen and Borderless window script by Martijn Dekker (Pixelstudio)
    5.  
    6.  * For questions pls contact met at martijn.pixelstudio@gmail.com
    7.  
    8.  * version 0.1
    9.  
    10.  *
    11.  
    12.  */
    13.  
    14.  
    15.  
    16. using System;
    17.  
    18. using System.Collections;
    19.  
    20. using System.Runtime.InteropServices;
    21.  
    22. using System.Diagnostics;
    23.  
    24. using UnityEngine;
    25.  
    26.  
    27.  
    28. public class WindowMod : MonoBehaviour
    29.  
    30. {
    31.  
    32.     public Rect screenPosition;
    33.  
    34.    
    35.  
    36.     [DllImport("user32.dll")]
    37.  
    38.     static extern IntPtr SetWindowLong (IntPtr hwnd,int  _nIndex ,int  dwNewLong);
    39.  
    40.     [DllImport("user32.dll")]
    41.  
    42.     static extern bool SetWindowPos (IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    43.  
    44.     [DllImport("user32.dll")]
    45.  
    46.     static extern IntPtr GetForegroundWindow ();
    47.  
    48.    
    49.  
    50.     // not used rigth now
    51.  
    52.     //const uint SWP_NOMOVE = 0x2;
    53.  
    54.     //const uint SWP_NOSIZE = 1;
    55.  
    56.     //const uint SWP_NOZORDER = 0x4;
    57.  
    58.     //const uint SWP_HIDEWINDOW = 0x0080;
    59.  
    60.        
    61.  
    62.     const uint SWP_SHOWWINDOW = 0x0040;
    63.  
    64.     const int GWL_STYLE = -16;
    65.  
    66.     const int WS_BORDER = 1;
    67.  
    68.        
    69.  
    70.     void Start ()
    71.  
    72.     {
    73.  
    74.         SetWindowLong(GetForegroundWindow (), GWL_STYLE, WS_BORDER);
    75.  
    76.         bool result = SetWindowPos (GetForegroundWindow (), 0,(int)screenPosition.x,(int)screenPosition.y, (int)screenPosition.width,(int) screenPosition.height, SWP_SHOWWINDOW);
    77.  
    78.     }
    79.  
    80.  
    81.  
    82. }
    83.  
    84.  
     
  2. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    Hi,

    this might sound like a stupid question, but... What is the use of this?
     
  3. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    erm, what if you have multiple monitors and want multiple instances of unity running.. ?
     
  4. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    why don't you just open the application (if you're on windows) twice, then move on to one screen, one to the other?
    Not sure about macs, maybe duplicate the unity editor application, and run them both?
     
  5. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Not all graphics cards support two full screen apps to run on two separate monitors, so in order to run two apps in separate screens you have to run them with borders and then drag them into position. I'm guessing that with PixelStudio's code, you can size the borderless window to the size of the monitor and then position it on each monitor. If it works, this is -very- useful, in fact, it should be part of Unity's built in functionality! :)
     
  6. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    currently there is no way to run 2 or more unity's fullscreen on two monitors.
    i dont want to have the window borders around my unity and dont want to position it manualy.
    Thus i tried it this way and it seems to work. as a result you can make multiple unity instances running on different monitors, and thats what i need :). cause i would like to try out creating multiple projects instead of one large unity project.

    a other solution for multi monitor is using a ATI card and eyeFinity technology to have one mega large desktop streched over multiple monitors. but then only one instance of unity can run, fullscreen (this setup i have working on 5 monitors, 1 comp)
     
  7. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    That's exactly what I thought. This is excellent, thanks for sharing!
     
  8. VolureDarkAngel

    VolureDarkAngel

    Joined:
    Jun 27, 2013
    Posts:
    10
    For those doing Macintosh. Here have a look at this.

    NSWindow *win = [NSApplication sharedApplication].mainWindow;
    NSRect frame = win.frame;
    // Update Frame
    [win setFrame:frame display:YES];
    [with setStyleMask:NSBorderlessWindowMask];


    Yes the message -[NSApplication mainWindow] does return the unity window.
     
  9. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    There is only one real use for having multiple instances.

    client/server versions

    This doesnt belong under showcase though.
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Multiple monitor support is currently only achievable via multiple instances. So there are at least two real uses.
     
  11. Justei

    Justei

    Joined:
    Aug 31, 2012
    Posts:
    133
    Can't you techincally do the following?
    -adapter N

    Code (csharp):
    1.  
    2. -adapter N (Windows only) Allows the game to run full-screen on another display. The N maps to a Direct3D display adaptor. In most cases there is a one-to-one relationship between adapters and video cards. On cards that support multi-head (they can drive multiple monitors from a single card) each “head” may be its own adapter.
    3.  
    and run one instance on one screen and the other on the other?

    Source: http://docs.unity3d.com/Manual/CommandLineArguments.html
     
  12. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Not sure what you mean by that... you mean a game viewport that is over two screens? I use dual monitors all the time, so you must be talking about something else.
     
  13. UltraTM

    UltraTM

    Joined:
    Dec 8, 2013
    Posts:
    221
    Does someone have the modified code to have the Window in the Center?
    caus thats what im looking for.
    To center it and also be moveable :)
     
    Last edited: Aug 24, 2014