Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by basklein_ · Apr 12, 2016 at 04:34 PM · editor-scriptingscene-loadinggenerationautomaticmenuitem

(Editor Scripting) Is it possible to generate MenuItems?

Hello reader!

I've been experimenting with Unity Editor scripting and I was wondering if it is possible to generate MenuItems with code. As in, not having to write:

 [MenuItem("Open Scene/TestScene1")]
      public static void OpenTestScene1()
      {
          OpenScene ("TestScene1", "Levels");
      }

For every single MenuItem I want to create.

I want to be able to automatically generate a Menu Item to open any specific scene in my project, without having to navigate to them or having to add them to the script manually.

I already have this script:

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using System.IO;
 
 public class EDEX_SceneMenuItem : Editor 
 {
     [MenuItem("Open Scene/Opening", false, 10)]
     public static void OpenOpening ()
     {
         OpenScene ("OpeningScene", "Menus");
     }
 
     [MenuItem("Open Scene/Credits")]
     public static void OpenCredits ()
     {
         OpenScene ("Credits", "Menus");
     }
 
     [MenuItem("Open Scene/Gallery")]
     public static void OpenGallery ()
     {
         OpenScene ("Gallery", "Menus");
     }
 
     [MenuItem("Open Scene/Menus/Character Select")]
     public static void OpenCharacterSelect ()
     {
         OpenScene ("CharacterSelect", "Menus");
     }
 
     [MenuItem("Open Scene/Menus/Level Select")]
     public static void OpenLevelSelect ()
     {
         OpenScene ("LevelSelect", "Menus");
     }
 
     [MenuItem("Open Scene/Menus/Main Menu")]
     public static void OpenMainMenu ()
     {
         OpenScene ("Menu", "Menus");
     }
 
     [MenuItem("Open Scene/Menus/Custom Game")]
     public static void OpenCustomGame ()
     {
         OpenScene ("CustomGame", "Menus");
     }
 
     [MenuItem("Open Scene/Menus/Options")]
     public static void OpenOptions ()
     {
         OpenScene ("Options", "Menus");
     }
 
     [MenuItem("Open Scene/Menus/Title")]
     public static void OpenTitle ()
     {
         OpenScene ("Title", "Menus");
     }
 
     static void OpenScene (string name, string subfolder)
     {
         if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
         {
             EditorApplication.OpenScene("Assets/Scenes/" + subfolder + "/" + name + ".unity");
         }
     }
 }

Thanks in advance.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gjf · Apr 12, 2016 at 01:16 PM 0
Share

if you mean a keyboard shortcut, the docs show you how... if not, what do you mean?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by basklein_ · Apr 13, 2016 at 11:29 AM

Nevermind, I just made a script to write the above script for me. It works by detecting all scenes in the project and then writing a C# editor script with the correct functions.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image K-16Games · Dec 04, 2017 at 03:39 AM 0
Share

Sooooo, I'll upvote you if you share how you did it?

avatar image
-2

Answer by aditya · Apr 13, 2016 at 05:29 AM

I just googled unity c# menu item and got this

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Editor scripting - How to show the Assets menu as a context menu 1 Answer

How can I detect collision with a text mesh without manually creating a polygon collider? 3 Answers

Why does Frame Selected toggle between position and bounds for procedural and imported meshes? 1 Answer

Tiles pre-built or generated? 2 Answers

What is the correct syntax for UnityEditor.VersionControl.Provider.GetAssetByPath? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges