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
  3. Dismiss Notice

Trapping if Unity Editor is foreground...

Discussion in 'Scripting' started by LightStriker, Sep 30, 2014.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Sounds easy, right? Find if the Unity Editor process is the currently focused foreground window.

    For the love of all that is holy, I can't find a way to do it.
     
  2. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    Uhm. The way I would go about this is using windows APIs, but that wouldn't be a great production solution.
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I tried, can't even do that. The Managed code, for some reason, doesn't have a valid MainWindow handle, so I can't compare it to the current foreground window handle.
     
  4. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    You'd find it by process ID, get the main window IntPtr handle of Unity itself.
     
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Yes, I know that, but the MainWindowHandle always returns 0 for some reason with Unity. I'll look at it again tonight, but I pretty much ran out of idea while using GetForegroundWindow.
     
  6. novashot

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
  7. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
  8. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    Any news on this? Didn't find it too :(
     
  9. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    Just curious. Why do you need to know this?
     
  10. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    In my custom editor script, I change the android keystore path to be at the correct location on the machine (in my team several people compile the project). I'd like when I switch to a new window (mostly git) revert this change so it's not pushed and won't make conflict.
     
  11. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    Isn't it easier to throw it in .ignore?
     
  12. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    Unfortunately a ProjectSettings.asset shouldn't be ignored at all by the team ;)