• 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 /
  • Help Room /
avatar image
Question by IronBeard · Jan 08, 2017 at 05:09 AM · editor-scripting

Draw label on editor or change MenuItem name dynamically

I've searched all over and tried many approaches and still haven't found a suitable solution. What I have is a custom menu named Build with the menu items Server and Client. When either is clicked it sets the define symbols for compiling to either SERVER or CLIENT. What I want is some indicator which mode I'm currently in. Ex. Am I in SERVER mode or CLIENT mode?

What I would ultimately like is a simple label in the editor that I can programmatically set when either menu item is clicked that will tell me what mode I am in but I couldn't find a good way to do this. GUI.Label only draws while in play mode, EditorGUI and EditorGUILayout is only used for custom editor windows, Handel.Label is only for the scene view while in play mode. I then tried to find a way to change the menu name it self but it seems you can't once the menu is created. I may have missed something so if any one has any ideas or the proper way to display a label somewhere in the editor it would be much appreciated.

Comment

People who like this

0 Show 2
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 Adam-Mechtley · Jan 08, 2017 at 09:50 AM 0
Share

What I would ultimately like is a simple label in the editor

Can you clarify where you would want this label to appear exactly?

avatar image IronBeard Adam-Mechtley · Jan 08, 2017 at 05:55 PM 0
Share

I apologize, I should of clarified where I wanted it. I was originally wanting something in the space between the transform tool buttons and the play button. Though if it's not possible to modify that part of the editor then maybe in the scene window or game window in the top left corner but I would want it to show even when not in play mode.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by steo · Jan 14, 2017 at 03:38 PM

If "Build/Server" menu declares SERVER and undeclares CLIENT and "Build/Client" menu item declares CLIENT and undeclares SERVER, you can write code:

 #if SERVER [MenuItem ("Server")]
 #else [MenuItem ("Cliend")] #endif
 static void ShowBuildState(){
 }
 
 #if SERVER [MenuItem ("Server", true)]
 #else [MenuItem ("Cliend", true)] #endif
 static bool SetBuildStateMenuItemInactive(){
     return false
 }

It will show you current build state by changind MenuItem name dynamically =)

Comment

People who like this

0 Show 0 · 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

Answer by Adam-Mechtley · Jan 14, 2017 at 02:27 PM

It's not documented, but there is a delegate to which you can add a listener, SceneView.onSceneGUIDelegate. I leave the precise details up to you, but you could consider something like:

  1. Create a static class with InitializeOnLoadAttribute and add an event handler to EditorApplication.update in its class initializer

  2. In your update event handler, look for scene views in the current layout (e.g., undocumented static property SceneView.currentDrawingSceneView or SceneView.lastActiveSceneView) and if you find one you have not encountered before, cache it and add your onSceneGUIDelegate event handler. If any of the SceneViews in your cache are null during this update event handler, remove them your cache so you don't hang onto the managed wrapper for a window that has been destroyed.

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

95 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 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 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 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

BeginVertical weird width behaviour 0 Answers

Process Terrain and Water in Editor? 0 Answers

why can't we set lighting parameter by script 0 Answers

I really need some help and it's frustrating 1 Answer

GUI.Window. Wanting to allow clickthrough 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