Heya friends! 🙋‍♀️💖 Have you noticed this new* button thats been on your Unity toolbar and wondered what the hell it is? 🛠 WELL ITS ACTUALLY SUPER COOL! ITS CUSTOM EDITOR TOOLS TIME LETS LEARN ✨ALL✨ABOUT THEM!!

(*well, new since 2019.1)
So this new Custom Editor Tools system lets us write our own tools that are treated as first class tools, just like the inbuilt tools (Move, Rotate or whatever). They can draw UI to the scene view aswell as use the Handle API to manipulate objects…or whatever you want them to do
So, we got two types of tool - Global and Context tools.
Global tools show up on that main toolbar button and can effect any kind of object. Context tools obvs only show up for objects with a component they target, these show up in the tool panel.
🎉 SO THE FUN PART 🎉 Lets build one 🎵TOGETHER🎵
So, the most simple (but also actually useful) example i could think of is something im calling the LookAt tool - heres a lil video showing how it works. Basically, when we activate this tool we can easily keep objects in frame!
So lets make a new file called LookatTool.cs in an editor folder.All editor tools need to inherit from the EditorTool class and should get tagged with the EditorTool attribute. The attribute is super important!This lets us specify if its a global or context tool and as set a name
Unity knows we are building a global tool because we didnt pass in a target type into the EditorTool attribute (dont worry, we can make a context tool together later!) The name is used in editor UI on the editor tool button when were picking what tool to use 👩‍💻
So, in our EditorTool class we have two overrides defined
- OnToolGUI() is where the brains of our tool lives
- toolbarIcon, which is a hyper important property unity uses to style our tool! theres a bunch of boilerplate code here to grab an icon.
You can use the AssetDatabase APIs to load up a custom texture and pass that back, or use a inbuilt editor icon like i did (you should look at this useful list of unitys inbuilt icons! Hyper useful✨ github.com/halak/unity-ed…)
Okay, so the goal is to make the camera center and frame the currently selected object in the scene view, kinda like an orbit cam so we can get a good look at our stuff. The simplest way to do that is to grab the selected object and use SceneView.LookAt to frame it.. EASY!
(We could have used EditorTool.target to get a reference to the selected object, but then we would have had to cast it a Transform anyways, the Selection API already does that for us!) docs.unity3d.com/ScriptReferenc…
Okay... but what if we have multiple object selected? lets do a little bit of maths to figure out the center and ask the scene view to frame that point instead!

This is a great opportunity to use the Handles API to draw something in the scene view (like the center point)!
You can grab the full code here if you wanna try it yourself! gist.github.com/LotteMakesStuf…

with these basic building blocks we can build pretty much any tool we want~
(going on a quick coffee break, buuuuut lets make some more tools when im back k? oh yeah if you find this useful you could always GetLotte.Coffee ✨☕💖)
OKAY LETS HAVE A LOOK AT ANOTHER TOOL! I call this one the PhysicsDrop tool! This time its a Context tool, it only works on objects with a Rigidbody. Basically, we can select some phyiscs object and then run the physics engine on them for a number of frames!
This is a great tool for scattering things around an environment or warming up the state of physics objects in your scene, you know, make sure everything is resting right!

So, the big difference between this and a global tool is the target type we pass in the attribute
You can find all the code this Gist, but the important bit is that we can use Handles.BeginGUI(); to tell unity we want to draw some UI on the Scene view. We can use all the layout tools and everything gist.github.com/LotteMakesStuf…
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Lotte 'just an idiot' May 💖🍓🌈🐹🎮☕🍫🍩
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!