- Home /
SceneView GUI - Add "Gizmos" IN Scene (not Overlay)
Hi,
I'm currently working on an Custom SceneView Editor for 3D tile-maps. I need it because I create my full map in Maya and (want to) use this tool to tell Unity where a walkable tile is an where not. It's working greate but I have an annoying probleme. I couldn't figure out a way to render something in the scene and not over the scene (See the picture). I'm currently using Gizmos, because this is the only way I could find to render 3D GUI in the Scene View. Is there another way I'm not aware of?
Second question: Can I deaktivate the standard unity grid and object-selection in my script?
Best Regards, Théo
Here is my Editor code:
PS: I replaced some code with comments to make it easyer for you to read.
PPS: It's intentional that I'm not saving any data in the moment.
//using ...
public class TileEditor : Editor {
static bool running = false;
static int height = 10;
static int width = 10;
static List<Vector2> aktiveTiles = new List<Vector2>();
public static void OnSceneGUI(SceneView view)
{
Ray ray = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition);
Plane plane = new Plane(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
float distance;
plane.Raycast(ray, out distance);
Vector3 point = ray.GetPoint(distance);
//Code to check if point is in grid and to add new Vector2 in aktiveTiles
//Code to add IntFields for width & height
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
//Code to generate Vector[] points
Handles.DrawPolyLine(points);
}
}
foreach(Vector2 tile in aktiveTiles)
{
//Code to generate Vector[] points
Handles.DrawAAConvexPolygon(points);
}
}
[MenuItem("Tools/Tile Editor")]
public static void Trigger()
{
running = !running;
if(running)
SceneView.onSceneGUIDelegate += OnSceneGUI;
else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
SceneView.RepaintAll();
}
}
Here is the picture: