Editor Mouse Cursor Tracking

Hello! I have been fidgeting around with this all night and have pretty much exhausted my thoughts on the matter, as well as any information I thought I could find here.

I am designing a basic tile based 2D game-a-ma-bob, and to make designing levels for it less psychosis inducing, I am creating a little something for the Editor. The main part of this Editor script involves painting a texture onto the tiles, so the designer doesn’t have to go piecemeal, clicking every single tile and manually selecting their texture; with a few thousand tiles, that could get a tad tiresome. Simply select the texture to paint on, track the mouse over the 3D port, and report the objects it traces over. Easy, right?

Well, I thought so too, at first. It seems all the methods I have tried work only during Runtime. For example, while I did find methods of getting an accurate cursor position, I have yet to find a way to get accurate click events/inputs, and none of the unit conversions work to translate the mouse coords to world coords (no active cameras due to not being in runtime, for example). I literally went through every related class I could think of to find possible solutions, and couldn’t seem to whip one up.

While I obviously missed something, I know at least one of you can help me figure this out!

Is there any trick to working with the mouse in the Editor? A way to get good XY coordinates for finding world objects, a way to detect the apparently indetectable left click (Mouse is technically outside the custom window), and of course a way to prevent the mouse from selecting everything it traces over? If anyone can help steer me to the right classes, functions, and techniques, I would be quite grateful!

Hi, welcome to the forum!

Have you tried Camera.current? I think it is supposed to return the scene camera when you are in the editor. Assuming it works then ScreenPointToRay or ScreenToWorldPoint should still work OK.

I’m using raycasting for tracking a mouse in my level editor.

You may have to alter this code, but this is mine. I do have it stuck on one Z-axis, so you will have to program that.
(Javascript)

if (Physics.Raycast (rayObject, hitObject, 100)) {
    Debug.DrawLine (rayObject.origin, hitObject.point);
    var placedObject = Instantiate(objectType,Vector3(hitObject.point.x,hitObject.point.y,0),objectRotation) as GameObject;
}