Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ng93 · Jun 25, 2011 at 12:57 PM · editormenuwindowmenu-item

Editor Menu Item open Window

I have a c# script which creates a menu item in the editor. How would I make it so that when clicked it opens a window with a textbox and OK button, then uses the text boxes text in the script?

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

2 Replies

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

Answer by Joshua · Jun 25, 2011 at 01:45 PM

It's all explained here. This script should serve as an example of how to use a textbox and a button. A textbox will appear when you select something in the hierarchy, you can then change the name and press ok to apply the changes.

 class MyWindow extends EditorWindow 
 {
     @MenuItem ( "Window/My Window" )
     static function ShowWindow () 
     {
         EditorWindow.GetWindow ( MyWindow );
     }
     
     var newName : String;
     
     function OnGUI () 
     {
         GUILayout.Label( "Select an object in the hierarchy view" );
         if( Selection.activeGameObject )
         {
             newName = EditorGUILayout.TextField( "Object Name: ", newName );
             if( newName == "" )
             {
                 newName = Selection.activeGameObject.name;
             }
             if( GUILayout.Button( "Ok" ) )
             {
                 Selection.activeGameObject.name = newName;
             }
         }
         else
         {
             newName = "";
         }
         
         
         this.Repaint();
     }
 }

Comment
Add comment · Show 4 · 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 Bunny83 · Jun 25, 2011 at 01:57 PM 0
Share

:D it's funny, you check if there's an activeGameObject but when you press the O$$anonymous$$ button you just set the name even if there's no GameObject selected.

Also it's kinda useless to call this.Repaint(); every GUI event. It just marks the window to get repainted but usually that happens automatically when it's needed. You only need a constant repaint if you want to display something animated.

avatar image Joshua · Jun 25, 2011 at 02:15 PM 0
Share

Hah, you're right, I'll fix that, Bunny. I did the repaint so it would instantly show when you (de)select something from the hierarchy ins$$anonymous$$d of only when the window regains focus. I guess it would've been better to check if something got (de)selected and only then repaint, but I didn't bother :p

avatar image Bunny83 · Jun 25, 2011 at 04:19 PM 1
Share

There's a nice event for that case ;)

EditorWindow.OnSelectionChange

avatar image Joshua · Jun 25, 2011 at 04:33 PM 0
Share

Good to know, thanks!

avatar image
0
Wiki

Answer by Theinsanekiller · Jan 22, 2015 at 06:24 AM

I need a help. I dont want my window to open via Menu. I want it to open on some event or a editor button click. Is it possible to do? In short I dont want my window to become a menu Item.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Separator in custom Editor MenuItem 1 Answer

How would you go about showing an editor preferences panel in the inspector? 1 Answer

How to add a menu item to the window's right side pop-up? 1 Answer

MenuItem in EditorWindow 1 Answer

How can I change color in GUI text? I have problem 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