How to draw a line in the Scene View
from an EditorWindow
?
I was expecting there to be simple way to this, but I can’t seem to find it.
How do I do this?
Gizmos
, Handles
and Debug.DrawLine
all don’t seem to work.
How to draw a line in the Scene View
from an EditorWindow
?
I was expecting there to be simple way to this, but I can’t seem to find it.
How do I do this?
Gizmos
, Handles
and Debug.DrawLine
all don’t seem to work.
GLDraw.Line( startPoint , endPoint , duration );
GLDraw.cs can be found here:
this is 2020.3 URP example (not tested elsewhere)
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Rendering;
using UnityEditor;
using UnityEditor.UIElements;
public class MyEditorWin : EditorWindow
{
Vector3Field A, B;
void OnEnable ()
{
RenderPipelineManager.endCameraRendering += EndCameraRendering;
A = new Vector3Field("Point A"){ value = new Vector3(-100,-100,-100) };
rootVisualElement.Add(A);
B = new Vector3Field("Point B"){ value = new Vector3(100,100,100) };
rootVisualElement.Add(B);
}
void OnDisable () => RenderPipelineManager.endCameraRendering -= EndCameraRendering;
void EndCameraRendering ( ScriptableRenderContext context , Camera camera )
{
if( camera.name!="SceneCamera" ) return;// Scene view only
Material material = AssetDatabase.GetBuiltinExtraResource<Material>("Sprites-Default.mat");
material.SetPass(0);
GL.PushMatrix();
GL.Begin( GL.LINES );
{
GL.Color( new Color32(0,0,255,255) );
GL.Vertex(A.value);
GL.Color( new Color32(255,0,0,255) );
GL.Vertex(B.value);
}
GL.End();
GL.PopMatrix();
}
[MenuItem("Tools/"+nameof(MyEditorWin))]
static void CalculateLightProbes () => GetWindow<MyEditorWin>().titleContent = new GUIContent("(= ФェФ=)");
}