Search Unity

  1. Dismiss Notice
  2. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    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,638
    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. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    441
    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,638
    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. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    441
    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,638
    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,638
  8. -Aymeric-

    -Aymeric-

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

    Boz0r

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

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    109
    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:
    412
    Isn't it easier to throw it in .ignore?
     
  12. -Aymeric-

    -Aymeric-

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