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
2
Question by Grimmy · Aug 05, 2010 at 10:24 AM · editorstatic

Where can I learn about editor programming?

There are several features I wish to build in the editor but I'm finding the usage of static functions for menu items a bit bewildering. I understand only the very basics of static functions but as soon as I want to do anything with any real data or references outside of the function itself I run into problems..

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by SteveFSP · Nov 07, 2010 at 04:20 PM

I haven't found any thorough documentation on extending the Unity editor beyond what Joshan mentioned: Extending the Unity Editor. But that article and the scripting reference may be all you need after you understand a couple of core concepts. (That's how it turned out for me, at least.)

In one of your comments you seem to indicate you are trying to create a custom inspector, so that is what I will concentrate on in my answer.

Here are some core concepts that may help you get started:

Associating a Custom Editor with a Unity Object

When you create a custom inspector by extending the 'Editor' class, you need to associate it with another class that inherits from a Unity object. (That is key, that it extends a Unity object.) In the article, it may not be obvious, but the LookAtPoint extends MonoBehaviour. So it qualifies.

// The attribute is what tells the Unity editor when to use the custom inspector.
// In this case, use this custom inspector for LookAtPoint.
@CustomEditor (LookAtPoint)
class LookAtPointEditor 
    extends Editor  
{
   // Since this class extends 'Editor', it can be a custom inspector, assuming
   // you have placed it in the Editor folder.
}

The 'target' Field is the Object Being Edited

To gain access to the object that is being edited, use the 'target' field. If necessary, you can recast it to the class of the actual object. E.g. Recast to LookAtPoint. (This is important to know if you are using C#.)

Remember that you have access to everything within the target object. So if the object is a MonoBehaviour, you can use it to query the rest of the scene.

Intermixing GUI Layout and Code that Does Stuff

Once you get to the point where you can experiment, understanding the use of static methods to generate GUI elements should fall into place. Since the concepts behind GUI scripting is similar both in-game and in-editor, you can get a better understanding of it via the GUI Scripting Guide

An important item to remember is that you can intermix the code that does stuff with the GUI layout code.

if (GUILayout.Button("Build Mesh")
    && EditorUtility.DisplayDialog("Are you sure?"
        , "This will permanently change the mesh."
        , "Build mesh now."
        , "No, I am not ready."))
{
    // If the button is pressed and the OK option is selected in the dialog,
    // then call a horribly complex method that builds a mesh.
    BuildMesh(myMeshData);
}

Hope this helps.

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
avatar image
1

Answer by Skjalg · Feb 08, 2012 at 02:57 PM

There is a great tutorial up at http://active.tutsplus.com/tutorials/workflow/how-to-add-your-own-tools-to-unitys-editor/comment-page-1/#comment-50637

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
avatar image
0

Answer by jashan · Aug 05, 2010 at 10:59 AM

A good starting point for editor programming is: Extending the Editor.

If you're having trouble with static methods, one solution that I'm usually using is instantiating the objects as needed and then working with them. Depending on what kinds of objects you're dealing with, you might prefer to get references to the objects instead of creating new ones.

Comment
Add comment · Show 2 · 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 Grimmy · Aug 05, 2010 at 12:31 PM 0
Share

Cool cheers. I already tried the example in the tutorial/help file, and i just don't understand it. At no point can I read in what object the inspector is supposed to show up in 'yay shiny inspectors' I never get :( . The page says that the inspector created is there all the time but when I cut and paste the code exactly there is nothing showing up in the inspector and the help file doesnt say where I am supposed to find it. And thats where the tutorial ends...so all in all its pretty poor. Thanks anyway.

avatar image jashan · Aug 06, 2010 at 05:01 AM 0
Share

Are you sure you're putting your scripts into the Editor/-folder in your project's Assets folder? So the path would be Assets/Editor/? Probably you do because otherwise you'd get a compilation error but I thought I'd better ask ;-)

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

1 Person is following this question.

avatar image

Related Questions

static objects in android build 0 Answers

How to Instantiate objects while in editor? 1 Answer

Unserialized private variable values from static instance persist when exiting play mode 1 Answer

how to keep static variables or 2d array value 0 Answers

Static materials are lost? 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