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
2
Question by Thieum · Jul 06, 2011 at 01:44 PM · guiinspectormonobehaviour

Add a button in the component inspector

Hi,

I have a MonoBehaviour script and I would like to add a button to it in the inspector tab when it is added to an editor-only GameObject. Like the terrain script that has a customized inspector GUI.

All that I have found is to add a button in the GUILayer of the camera by calling GUI.Button(). I think I could create an EditorWindow but I would like to attach this window to a GameObject like I can attach a script to a GameObject

Is it possible and how can I do it ? 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

2 Replies

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

Answer by Bunny83 · Jul 06, 2011 at 02:14 PM

You have to create a custom inspector for your class.

Just create a new script in an editor folder and derive your class from Editor. Add the CustomEditor attribute with your inspected class. OnInspectorGUI is the "event" that you need. Keep in mind that the default inspector will no longer show your public variables. You have to implement the whole inspector for your class yourself or call DrawDefaultInspector at the end.

You might want to take a look at how to extend the editor

Comment
Add comment · Show 3 · 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 Thieum · Jul 06, 2011 at 03:58 PM 0
Share

Thanks, it is nearly working. The only problem is that EditorGUILayout and EditorGUI don't have a Button method. I have to use GUI.Button and the position of the bottom is relative from the top of the inspector of the GameObject, not from the top of the inspector of the component.

avatar image Bunny83 · Jul 06, 2011 at 05:01 PM 0
Share

Don't use the GUI or EditorGUI stuff in the inspector. The Inspector window is layouted. GUILayout and EditorGUILayout are your firends in the inspector ;).

Btw. EditorGUILayout is just an extention of GUILayout that is only available in the editor.

avatar image Thieum · Jul 06, 2011 at 05:12 PM 0
Share

Yes I understand more the relation between the classes. Thank you, that is perfect

avatar image
2

Answer by Zbyl · Dec 08, 2012 at 05:29 PM

See an answer "Create a Button in the inspector" here for JavaScript and C# examples: http://answers.unity3d.com/questions/126048/create-a-button-in-the-inspector.html#answer-360940

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

Using different custom inspectorscripts 1 Answer

Use of the inspector along with a custom editorwindow 1 Answer

Customize arrays and classes in inspector window 2 Answers

Can i extend or customise editor for all MonoBehaviours? 3 Answers

GUI Editor Drag and Drop (Inspector) 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