πŸ“¦Game Object Create Menu

Editor system that makes easy to create game objects by templates like Unity Button and etc

What for?

In Assets\_Main\Scripts\Editor\ you can find CustomGameObjectCreateMenu.cs that is used to fill GameObject create menu that looks like this:

Game Object create menu (right mouse click on scene Hierarchy)

Vibro Button above is created by template and other objects should too. You can find templates here: Assets\_Main\Prefabs\Common\GameObjectTemplates.

How to add new create menu items?

1) Add prefab in Assets\_Main\Prefabs\Common\GameObjectTemplates that you want to create from GameObject menu. You should make unique name, because CustomGameObjectCreateMenu.cs finds templates by names or by class. Name should be "nameTemplate";

2) Add label "GameObjectTemplate" to your prefab in right down corner of editor:

Adding GameObjectTemplate label to your GameObject prefab

3) Open CustomGameObjectCreateMenu.cs and add method that will fill up GameObject create menu with new item. for example here is Vibro Button add method:

[MenuItem("GameObject/UI/Vibro Button")]
public static void VibroButtonCreate() {
    var btn = CreateGameObject("btnVibroTemplate", "btnVibro");
    CreateCanvasIfNoYet(btn);
}
  • in 1 line [MenuItem()] defines location of create button in GameObject menu and you must start it with "GameObject/";

  • in 3 line CreateGameObject method takes "btnVibroTemplate" as template prefab name and "btnVibro" as output gameObject name;

  • in 4 line creates canvas if there is no yet (specific case for UI elements)

Like this you can speed up creating objects by templates in the future.

Last updated