jacobdufault / fullinspector

Full Inspector supercharges Unity's inspector
MIT License
110 stars 27 forks source link

Show referenced component name in ObjectField of SerializedAction #130

Closed ShirenY closed 8 years ago

ShirenY commented 9 years ago

I know the ObjectField of Unity only shows the name of the GameObject. This could be confusing when the reference is link to a specific component on the GO. Especially when I'm editing a list of SerializedActions.

So I managed to draw the name of the referenced component on the ObjectFied of SerializedAction by adding code below to line 99 in BaseSerializationDelegateEditor.cs.

            if(element.MethodContainer)
            {
                // Draw the refenreced component on the ObjectField
                Vector2 size = EditorStyles.objectField.CalcSize(new GUIContent(element.MethodContainer.name));
                objectRect.x += size.x - 8f;
                objectRect.width -= size.x + 10f;
                GUI.Label(objectRect, "->" + element.MethodContainer.GetType());
            }

Result is like this, screen shot 2015-09-22 at 3 30 36 pm

It's pretty hacking and hardcoding but it works. Maybe you want to refine it and apply it to all ObjectField by making a wrap function of ObjectField().

jacobdufault commented 8 years ago

Ah! This is brilliant! I've always wanted to improve the object field to show the component name. Thanks! This will be in the next access build.

jacobdufault commented 8 years ago

image