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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to get the Window Position of the Unity Application

Discussion in 'Scripting' started by rab, Nov 15, 2010.

  1. rab

    rab

    Joined:
    Nov 13, 2009
    Posts:
    98
    Hi, I use ingame Screenshots as splash screens. It works excellent in fullscreen mode but I cant get it to work in windowed mode because I don't know the position of my application window. Is there any way to get the screen coordinates of the application?

    using this for capturing:
    Code (csharp):
    1.  
    2.  // Read screen contents into the texture
    3.         SplashScreen.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    4.         SplashScreen.Apply();
    5.  
    I need something like Application.getScreenRect() to get the upper left cornor of my application on screen.

    Thank you for any help.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    And why would you need the rect? ReadPixels reads the content within the game window, not behind the game window so the position of the rect on the screen should be of no importance as the coordinates are always 0,0 up to screen width / height
    Also you can't draw outside the unity window with unity functions

    but perhaps I missunderstand why you would need it?
     
  3. rab

    rab

    Joined:
    Nov 13, 2009
    Posts:
    98
    Thanks for the hint. My falt was reusing the texture without generating it new with the new dimensions after changing from full screen to windowed mode. So the size didn't change...
     
  4. Pi_3-14

    Pi_3-14

    Joined:
    May 9, 2012
    Posts:
    168
    I require the window's coordinates in screen space, because I am using a gaze tracker, which returns values in screen space.

    So if I may reopen this thread...

    I found a couple of links giving platform specific (Windows only) techniques:

    http://stackoverflow.com/questions/27631166/access-to-unity3d-created-application-windows-code
    http://answers.unity3d.com/questions/13523/is-there-a-way-to-set-the-position-of-a-standalone.html

    Also, an unanswered four year old question here: http://answers.unity3d.com/questions/168297/absolute-window-position-of-unity-application.html

    Is there any way to do this without using plug-ins?

    π

    PS if I check 'maximise on play', it still isn't quite fullscreen because there is a header and footer. So the problem remains of determining coordinates of the actual drawing surface.