Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Zephrim · Oct 02, 2014 at 07:11 PM · editormenu4.6extension

[Editor Extension] - Menu Helper

Sorry if the title is a bit deceiving and doesn't entirely convey what I'm attempting to do. I wasn't entirely sure what would be best to call it.

What am I attempting to do?

Alright, so I have a Class Type called Menu, which inherits from BaseMenu (Not Important).

If I want to effectively edit a specific menu, I have to make sure that it's the only one enabled. This, is entirely a pain if I have multiple menus. So I thought, hey! This would be a great opportunity for an Editor Script!

What functionality does it need?

So essentially if a Menu's GameObject or it's children are selected, then I want it to be enabled.

Any GameObject that isn't selected should be disabled.

If no GameObjects of the Menu type are selected, then it should try and Find a GameManager in the Scene and get it's CurrentMenu (This is specified in the Inspector).

What have I tried so far?

I've tried a very inefficient method just for testing and trying to figure out the best way to go about it. But I feel as though a CustomEditor or at least in the way I'm using it isn't the best option.

 [CustomEditor(typeof(Menu))]
 public class MenuEditor : Editor
 {
     private Menu[] _menus;
 
     public override void OnInspectorGUI()
     {
         DrawDefaultInspector();
 
         RefreshMenus();
 
         foreach (var menu in _menus)
         {
             menu.gameObject.SetActive(false);
         }
 
         var myMenu = (Menu) target;
         if (myMenu)
         {
             myMenu.gameObject.SetActive(true);
         }
     }
 
     private void RefreshMenus()
     {
         _menus = Resources.FindObjectsOfTypeAll<Menu>();
     }
 }

I know the above code doesn't include all of my functionality, and that's because for what I want to do the CustomEditor isn't a very good options. It only runs when a GameObject of type Menu is selected or it's inspector is modified in some way.

Any help is appreciated, thanks!

Comment
Add comment
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

1 Reply

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

Answer by chechoggomez · Oct 02, 2014 at 08:06 PM

You can create an EditorWindow for this and use OnSelectionChange, Selection.instanceIDs or Selection.activeGameObject for checking what is selected and see if those objects are the Menu Object or it's a child of it.

http://docs.unity3d.com/ScriptReference/EditorWindow.OnSelectionChange.html

http://docs.unity3d.com/ScriptReference/Selection-activeGameObject.html

http://docs.unity3d.com/ScriptReference/Selection-instanceIDs.html

If you don't want to use an EditorWindow, you can try something like this:

http://answers.unity3d.com/questions/644749/onselectionchange-without-editorwindow.html

though I think it's inconvenient for this case.

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 Zephrim · Oct 02, 2014 at 08:13 PM 0
Share

I decided to go the EditorWindow route, I figured I can find a more realistic use for it later.

Thanks for the quick response! You're awesome. :)

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

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can Editor scripts be in external DLL's or assemblies? 1 Answer

Ability to define custom help menu (PDF) 2 Answers

Access game classes from within Editor extension? 1 Answer

Editor extension data saving 1 Answer

Editor extension, How do I Serialized nested class? 0 Answers


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