If you came here only to have inspector methods working on your project, just skip to the bold and underlined text before images. Also keep in mind this only works with methods that have either none or ONE parameter.

 

After using a tool for very long you start noticing there are tasks that you end up doing over and over.

In my case, for a long time if I wanted to test a new method that I was working on in Unity, I had to call that method on the built-in Start or Awake. However, not always if not very often I just wanted to call it once instead of seeing the method work during a run time environment. This is where inspector methods come in handy.

I won’t go into full detail on editor scripting as there are several online tutorials to learn the ropes on them. But I will instead tell you how to set-up the scripts and how to use them.

 

(I recommend having the following two scripts on a separate folder.)

First, create a C# script called “InspectorMethodAttribute.cs

 

Then, inside a folder called “Editor” (Yes, it HAS to be called this) create another C# script called “InspectorMethodDrawer.cs

 

And now you are pretty much ready to use them, the usage is pretty straightforward:

 

This will result in a very interesting looking inspector:

 

As a disclaimer, I didn’t actually came up with having method calls inside the unity inspector, but it gives an overall idea of the power of editor scripting for those that are interested in it.

Anyway, hope it becomes useful to someone in the future.

 

Without anything else to say,

Thank you very much for reading my blog.~

GDCR - Juice It Or Lose It

While working in a game, ever felt like your progress is kinda bland? That it is missing something. That something might be juice, so keep an eye on this talk. Continue reading

Software Suggestion - Hootsuite

Published on April 05, 2018

Unity Tip - Built-In Primitive Sprites

Published on April 04, 2018