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
2 weeks ago 02:00:54 1
Syria Falls And No It’s Not A Good Thing | Candace Ep 116
3 weeks ago 00:27:46 1
Kill Team | Approved Ops 2024 Map Pack
4 weeks ago 00:23:16 2
TPMP Cris du coeur de Géraldine MAILLET, Les français ne méritent pas MACRON
1 month ago 00:04:28 1
💸 HOW TO ALWAYS WIN AND PROFIT ON CRASH ROOBET! BEST ROOBET CRASH STRATEGY! ROOBET PROMOCODE 2024 💸
1 month ago 00:03:28 1
Nemo - The Code (LIVE) | Switzerland🇨🇭| Grand Final | Eurovision 2024
2 months ago 00:04:20 2
Still Here | Season 2024 Cinematic - League of Legends (ft. Forts, Tiffany Aris, and 2WEI)
2 months ago 06:17:49 1
LIVE: President Trump Holds a Rally in Albuquerque, NM - 10/31/24
2 months ago 01:09:16 1
Бонус и Гамовер про главные игры 2000 г.
2 months ago 00:06:37 1
Dikengyuan Village With Underground Houses Thousands Of Years Old
2 months ago 00:15:42 1
WAKING UP AT 3 am? Warning🚨 THIS IS SERIOUS!!
2 months ago 00:34:31 5
Dragon Age: The Veilguard Shills Don’t Receive Review Codes Because They Weren’t Positive Enough
2 months ago 01:27:35 1
Understand Women by using Ai - Boss level unlocked
2 months ago 00:00:00 1
LIVE: Trump Holds a Rally at the Iconic Madison Square Garden in New York - 10/27/24
2 months ago 00:09:56 1
Life Inside the Vietcong Tunnels (Cross Section)
2 months ago 01:02:16 1
SINISTER - Dark Techno / Cyberpunk / Industrial Bass / EBM / Dark Clubbing Mix
2 months ago 00:28:22 1
АНТИСКУФ НЕ СДАЕТСЯ / НАКАЧАТЬСЯ В НАТУРАХУ 4.0
2 months ago 00:05:07 1
Hitomi Kuroishi - Code Geass OST - If I were a bird (Boku wa Tori ni naru) (live)
2 months ago 00:11:10 1
“Spoilt & self centred!” Massive row between Esther Rantzen & Wes Streeting over assisted dying
2 months ago 00:23:03 1
NGANNOUN pense aux femmes dans la rue, Pour FINKIELKRAUT le rap fait l’apologie du V***
2 months ago 02:10:39 1
Aliens In Egypt: Investigating The Ancient Gods Of The Underworld
2 months ago 01:01:33 1
Shamisen 三味線 x piano x drum | Background Music for Working or Study ⛩
2 months ago 00:22:00 1
🎃 The SheWolf of Woodland. A True Story.
2 months ago 01:38:16 1
Live: Tommy Robinson due in court for hearing over contempt of court claims
2 months ago 01:21:56 1
Top Radha Krishna Bhajans Nonstop Playlist No Mid-Adds Devotional Jukebox by Madhavas Rock Band