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;
}
}