There are a few fun ways to make fantastic Editor tools in Unity for your code. Two of those are `Handles` and `GenericMenu`. They enable you to create interactive components inside the Unity Scene View that allow you to more easily interact with your objects. They work as fantastic solutions for building custom editors. The thing is... I’ve never really used them. It’s time that changed.
Lets explore how these features work and how we might use them for our own projects. How do we draw a custom Handle using Unity’s Handle features? How about creating a custom editor with a context menu we can consume? We’ll build both to improve the visualization of our custom Graph code from a previous video.
To draw a basic `Handle` you may use `OnSceneGUI`. A sample of what this kind of editor might look like is below. It will draw a yellow line from the center of the scene to the `GameObject`’s position.
```csharp
using UnityEditor;
[CustomEditor(typeof(MyCustomClass))]
public class MyCustomClassEditor: Editor
{
protected virtual void OnSceneGUI()
{
MyCustomClass customClass = (MyCustomClass)target;
// Safety against selecting a null GameObject
if (customClass == null)
{
return;
}
= ;
(, );
}
}
```
You may draw a custom `GenericMenu` using something like this. It will create a two option menu that prints out the selected option to the Debug Log.
```csharp
GenericMenu menu = new GenericMenu();
(new GUIContent(“The name of a menu option“), false, () ⇒ { (“Picked First Option“); });
(new GUIContent(“The name of a second menu option“), false, () ⇒ { (“Picked Second Option“); });
// once you are done, show your menu
();
```
The documentation for `Handles` is available on Unity’s website:
The documentation for `GenericMenu` is also on Unity’s site. More info here:
Join the World of Zero Discord Server:
1 view
66
15
5 months ago 00:14:45 1
Notre épargne doit payer la dette FRANÇAISE pendant qu’ils ont 5% d’impôt
5 months ago 00:09:06 1
NARUTO: MADARA VS MIGHT GUY - Live Action Fight | RE:Anime
5 months ago 00:00:55 1
Young Girl A in OSU!
5 months ago 00:11:10 1
Pour des MILLIARDS, on a tué des GENS ! (TPMP parle de la m@rt d’un jeune)
5 months ago 03:42:56 1
Art of Melodic Techno & Progressive House DJ set (Trippy Code Music)
5 months ago 00:04:31 1
The Treatment “When Thunder and Lightning Strikes“ - Official Music Video
5 months ago 00:21:39 4
Destiny 2 и инфа по Destiny 3 | Путь к Финальной Форме, календарь контента и эмблема за стрим Bungie
5 months ago 00:05:44 1
Michelle Obama is a MAN?!
5 months ago 00:08:17 1
Shipping Container House - Enjoying Moments
5 months ago 01:10:09 1
VEGANS IN DANGER with LIERRE KEITH [Plant-based Tips]
5 months ago 01:39:20 1
Adele: Live at Royal Albert Hall HD FULL CONCERT
5 months ago 00:11:23 1
Грузины разнесли всех в третий день, золотая медаль Курченко - Большой Шлем Тбилиси 2024
5 months ago 03:32:26 1
🔴ВРЫВАЮСЬ КАК БОЖЕНЬКА...А МОЖЕТ БЫТЬ Я НАЧНУ ДЕЛАТЬ ЭЙСЫ Farlight 84
5 months ago 00:29:33 1
Luxury Stealth Camping & Gaming in Parking Lot
5 months ago 01:51:16 1
Lady Gaga (Live) Piano & Jazz Las Vegas 9-3-2023 Timecodes
5 months ago 00:28:16 1
ТОП 20 фишек и лайфхаков VAG (Полная версия). Jetta, GOLF, Bora, Caddy, passat, Tiguan, Polo
5 months ago 00:06:54 1
Qeight - Forget Me Not
5 months ago 00:36:47 1
A History of BAD Star Wars Products
5 months ago 02:26:11 1
Мамиев Live #16 Числовой код новой матрицы. Аслан Уарзиаты.
5 months ago 00:09:56 1
КАК СКАЧАТЬ БЕТА СЕРВЕР С АЛМАЗАМИ И НОВАЯ ХАЛЯВА И ШТАНЫ АНГЕЛА В ФРИ ФАЕР | фри фаер
5 months ago 00:00:00 1
My Reinsertion Into The Matrix With The Game Genie Cheat Code
5 months ago 00:11:34 1
How Does He Make His Guitar Sound Like That?
5 months ago 02:23:05 1
💎ОБНОВА С МЕГА РАЗДАЧЕЙ ЮНИТОВ 💎 В Toilet Tower Defense В РОБЛОКС💎ROBLOX 💎#shorts #roblox #ttd
5 months ago 00:09:04 1
How to Fix a Neck Hump and Get a Slim Long Neck|No Standing | Get a Slim Face