- Home /
Keep multiple custom handles visible in the Scene view
Hi, I have created a custom Editor to create a path system with waypoint with custom Handles which works fine.
My problem is that my custom handles are hidden when I am not selecting my gameobject which is a normal behavior but I didn't managed to make it work properly in my case.
This is what I tried to do :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PathCreator))]
public class PathEditor : Editor
{
public override void OnInspectorGUI()
{
// Show some button in my Inspector window
}
private void OnSceneGUI(SceneView sv)
{
Input();
Draw();
}
void Input()
{
// Adding or removing some waypoint
}
void Draw()
{
// Add the custom handles
}
private void OnEnable()
{
SceneView.duringSceneGui += OnSceneGUI;
// Some code to create my path
}
private void OnDisable()
{
SceneView.duringSceneGui -= OnSceneGUI;
}
private void OnDestroy()
{
SceneView.duringSceneGui -= OnSceneGUI;
}
}
The two method OnDisable
and OnDestroy
are being called every time I am unselecting my game object while I thought only OnDisable
would've been called.
If I do not add the SceneView.duringSceneGui -= OnSceneGUI;
in those two method above, the handles stays and it's kinda fine but I have a couple of issue :
The first one is that I have a "Reset" button in my custom Editor that reset the position of the path like so :
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("Reset")) { creator.CreatePath(); path = creator.path; checkpoints = creator.checkpoints; for (int i = 0; i < path.NumPoints; i++) { checkpoints.AddCheckpoint(Vector3.zero); } selectedPoint = -1; SceneView.RepaintAll(); } }
I don't think you need to get all the code here but I do a SceneView.RepaintAll();
once my path is being reset and this works when I am not using SceneView.duringSceneGui -= OnSceneGUI;
, it doesn't remove the older path and add a new (the reset) one. What should I do in that case ?
The second issue is that, I will need to show multiple path at the same time in my Scene window. How does that works with adding
OnSceneGUI
toSceneView.duringSceneGui
?
Thanks for the help
Your answer
Follow this Question
Related Questions
How to read the current PivotRotation or PivotMode ? 1 Answer
Select object by selecting gizmo or handle? 1 Answer
Handles.ScaleValueHandle and values < 0 0 Answers
PositionHandle causing problems 0 Answers
Using Handles.DrawAAPolyLine 1 Answer