Jump to content

Need to select specific part in editor


Recommended Posts

I'm a bit stumped.  I have this situation:

  • Mod window opened
  • Mod internally identifies the selected part
  • Part selected using one of the Gizmos (rotate, move)
  • Click a button in the mod window

The selected part gets deselected because (I believe) Unity changes the focus/active object to the button.

So, I need to do one of the following:

  1. Prevent part from being deselected
  2. Select part by mod after button is pressed

Any suggestions or ideas?

FYI, for various reasons, I can't do this in a MultiOptionDialog, which I think might work (PreciseEditor uses that)

Link to comment
Share on other sites

I guess you're using an IMGUI button.
KSP will reset the selected part if any mouse click happen outside of the gizmo / selected part, unless the mouse is over an UGUI element : the EditorLogic FSM checks EventSystem.current.IsPointerOverGameObject() in the on_offsetDeselect.OnCheckCondition KSMEvent update delegate.

There isn't any out-of-the-box solution to do what you want. It's doable but will involve quite a bit of reflection.
Something that might be worth trying would be to instantiate a dummy transparent UGUI panel the size of your window.

I don't think there is any way to prevent the deselection, beside replacing the KSMEvent instance by your own with a custom delegate in the EditorLogic FSM (which is doable, but arguably a bit hacky).

Re-selecting the part is also gonna be a bit tricky.
First step would be to save a reference to EditorLogic.SelectedPart when your IMGUI window/button is hovered.
To restore it (properly) after the button has been clicked, you will need to call a bunch of private stuff.

I won't extend further on the exact steps, since this is forbidden knowledge that will attract moderators like bees to honey.

The real fix is to ditch IMGUI and to use an UGUI based UI for your mod.

Edited by Gotmachine
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...