How do I add a custom inputfield control to the Unity UI menu?

We need to extend the Unity InputField, so we derived a class CustomInputField : InputField

I can’t figure out how to add this to the Unity /UI menu.

I have looked at the MenuItem attribute and can get this to respond.

However, when using: GameObjectUtility.SetParentAndAlign I can’t pass my CustomInputField type, as this only takes a GameObject and we have derived from InputField, not GameObject. InputField does not derive from GameObject.

In the below script you can see me trying to use AddComponent but his only adds the script to a GameObject.

What steps do I need to take to take to get my CustomInputField in the Unity Menu AND when I add it, it will be added to the Hierarchy correctly.

Thank you!

Karl

public class CustomizeMenu : MonoBehaviour {

[MenuItem(“GameObject/Logical Advantage/Keyboard Aware Input Field”, false)]
static void CreateKeyboardAwareInputField(MenuCommand menuCommand) {
// Create a custom game object
var go = new GameObject(“Keyboard Aware Input Field”);
go.AddComponent();
// Ensure it gets reparented if this was a context click (otherwise does nothing)
GameObjectUtility.SetParentAndAlign( go, menuCommand.context as GameObject);

// Register the creation in the undo system
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
Selection.activeObject = go;
}
}

Your problem is that it isn’t a PUBLIC static function.

If you check the options we add in the community driven UI Extensions project, we add loads of additional options :smile:
https://bitbucket.org/ddreaper/unity-ui-extensions/src/3456cfee9b5531fc6070299dc3599258b622d467/Scripts/Editor/UIExtensionsMenuOptions.cs?at=default

Thank you for a very fast reply.

I didn’t understand that you have to build up the UI. Got it.

Much appreciated!

Karl

1 Like