- Home /
Constantly Update Scene View
Hey, I'm working on a 2D terrain Engine. If "paint mode" is enabled, I use Gizmos.DrawGUITexture in a OnDrawGizmos funtction to show the brush position in the editor scene view. Of course it's based on the mouse position. However, due to the nature of the scene renderer this guitexture only gets updated when a mouse button or the like is pressed. So if I just move my mouse, functions like OnDrawGizmos or Update do not get called. Coroutines don't work since they are based on Unity's internal framerate.
How can I set a constant frame rate in the editor?
Incase this didn't quite make sense, here's my code :
void OnDrawGizmos()
{
Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
var plane = new Plane(upV, point);
float distance;
if (plane.Raycast(ray, out distance))
{
var hitPos = ray.origin + distance*ray.direction;
Gizmos.DrawGUITexture(new Rect(hitPos.x- brushSize/2f,
hitPos.y+brushSize/2f, brushSize, -brushSize),
stencils[stencilIndex].texture, gizmoMaterial);
}
}
which only gets called when a button is pressed, not when I just move my mouse.
Any help would be appreciated.
Answer by Guessmyname · Jan 14, 2015 at 04:57 PM
I had a similar issue; the trick is to use SceneView.RepaintAll and Event.current.
if(Event.current.type == EventType.MouseMove) SceneView.RepaintAll();
This makes the scene views repaint on mouse move events.
Catch is, this has to be done from Editor code (ie it requires UnityEditor as an include), so you're going to have to use a custom inspector and shift all your painting code into its OnSceneGUI function, I'm afraid.
Your answer
Follow this Question
Related Questions
Mouse click in edit mode. ✱✺✸❁ 1 Answer
What is the best way to fix texture z-fighting? 5 Answers
Permanent handles (when object is not selected) 1 Answer
Select object by selecting gizmo or handle? 1 Answer
Turn scene view "full screen" off 0 Answers