Jump to content

Getting screen space of App Button?


Recommended Posts

I want to get the screen space coordinates of my button in the app launcher so that I can position the open window relative to the button just like the stock GUI does.

However I can't seem to figure out how to do this. I can grab the button's transform, but that appears to be in world 3d space, and I can't figure out how to get the proper camera to translate them, I tried this code, but it just throws NRE's all over the place.


internal void CalculateWindowBounds()
{
if (appLauncherButton == null)
return;
Transform buttonTransform = appLauncherButton.transform;
Debug.Log("TestFlight MasterStatusDisplay: buttonTransform = " + buttonTransform.localPosition);
Vector3 buttonCoords = HighLogic.fetch.camera.WorldToScreenPoint(buttonTransform.localPosition);
Debug.Log("TestFlight MasterStatusDisplay: buttonCoords = " + buttonCoords);
}

Link to comment
Share on other sites

This will get you there, but you do need to get the right camera. So in the editor or flight mode it works, but in the SC scene its not the right camera.

gives you the bottom right corner of the button if ApplicationLauncher.isPositionedAtTop is true or the top right corner is the app launcher is at the bottom

Camera.current.WorldToScreenPoint(appLauncherButton.GetAnchor())

Link to comment
Share on other sites

Thanks, so it looks like I am on the right track, I just need to figure out how to get the proper camera. Like you said in Flight mode its easy, but not sure about the other scenes. Guess I have some API digging ahead of me.

For now I'm just going to cop out and use a fixed position relative to the corner of the screen I think.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...