Custom editor: EditorGui.DrawPreviewTexture in SceneView only works in the top right corner
Good morning,
I have a custom 2D tile editor tool I wrote for Unity. It allows me to "paint" terrain for my 2D games. I have a "brush tool" and a "draw a rectangle" tool to pain this terrain. When using the rectangle tool, the user drags the mouse in the scene view. When he releases, a rectangle of terrain is created, spanning from the origin of the drag to the end of it. As the user drags the mouse around, I would like to give him a visual feedback of the rectangle he is currently forming. To do so, I am trying to use
void OnSceneView(SceneView view) { EditorGui.DrawPreviewTexture(myWorldCoordinateRectangle, myTexture); view.Repaint(); }
Everything is fine as long as the rectangle is drawn in the top right corner of my scene view, like this:
But the scene view will not draw anything in the other corners. If the rectangle is totally in another corner, it will not be drawn. If it is partly in the top right corner, only the top right corner part of my texture will be drawn. I have tried to move my scene view camera around, but wherever I place it or whatever the size of my scene view, it is the same issue: only the top right of my camera is drawn:
I have checked my rectangle size using Debug.DrawLine()
and it is following the drag correctly in the other corners. I also tried "EditorGUI.DrawRect" and it is the same issue.
Anyone got any idea?
Have you had any luck figuring this out? I am having the exact same problem as you whilst trying to draw a custom cursor whilst in the editor
Answer by spacelizardstudio · Dec 15, 2016 at 08:56 AM
No I didn't find how to fix it. I decided to draw 4 debug lines to display my square.
Your answer
Follow this Question
Related Questions
How to access a Custom Editor components 1 Answer
Getting mouseposition outside of Editor Window in Scene View 1 Answer
Editor Camera Issue 0 Answers
Adding custom edits to scene window 0 Answers