Search Unity

Focus control on custom inspector after selecting a handle on the scene

Discussion in 'Editor & General Support' started by nanocba83, Feb 17, 2019.

  1. nanocba83

    nanocba83

    Joined:
    Feb 20, 2018
    Posts:
    10
    I'm working on a custom inspector for one of my types where it's basically a grid built from number of rows and columns. It creates an array of world positions given those parameters and I draw a handle on the scene for each of them and also a custom inspector for this world positions that allow me to specify attributes on each of them. So far so good. I also managed to get the focused item (world position) on the inspector and highlight it on the scene, but I now need the opposite: if I click on one of this world positions (drawn as a sphere handle) I want to be able to select the corresponding element in the inspector.

    Here's what I'm trying to do: while drawing the sphere handles I check if one of them is touched and then I do

    Code (CSharp):
    1.        
    2.        if (touchedHandle != null) {
    3.             this.focusedControl = touchedHandle;
    4.             this.Repaint();
    5.         }
    6.  
    That causes the OnInspectorGUI to be called and in there, after drawing the custom properties, I do

    Code (CSharp):
    1.  
    2.         if (this.focusedControl != null) {
    3.             GUI.FocusControl(this.focusedControl);  
    4.         }
    5.  
    Somehow that is not working since the custom property on the inspector is not being focused. I double checked control names match as expected so there must be something else I'm doing wrong. Am I missing something? How could I achieve what I'm looking for?