Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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,371
    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:
    381
    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,371
    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:
    381
    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,371
    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,371
  8. -Aymeric-

    -Aymeric-

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

    Boz0r

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

    -Aymeric-

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

    -Aymeric-

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