- Home /
[Editor] Get Scroll Wheel while dragging
Hi, I'm creating a custom editor window in which you can drag and drop specifics prefabs in the scene view. I've added a snap system on top of it and everything works fine at this point. What I'd like to do now is to allow prefab rotation while dragging, using the mouse scroll wheel, but no madder what I've tried I can't get the scroll wheel value. I'm not familiar with Events, and I think that why I'm struggling. Here is the code i'm using :
private void DuringSceneGui()
{
if (_IsDragging)
{
if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
{
if (_draggedClone == null)
_draggedClone = (GameObject)UnityEngine.Object.Instantiate(DragAndDrop.objectReferences[0]);
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
Vector3 mousePos = Event.current.mousePosition;
mousePos.y = SceneView.lastActiveSceneView.camera.pixelHeight - mousePos.y;
RaycastHit hit;
Ray ray = SceneView.lastActiveSceneView.camera.ScreenPointToRay(mousePos);
if (Physics.Raycast(ray, out hit))
{
if (FG_Processor.TagIsValid(hit.transform.tag))
{
Selection.activeGameObject = hit.collider.gameObject;
_draggedClone.transform.position = hit.collider.transform.position;
}
else
{
Selection.activeGameObject = null;
if (_draggedClone != null)
DestroyImmediate(_draggedClone);
}
}
else
{
if (_draggedClone != null)
DestroyImmediate(_draggedClone);
}
Event.current.Use();
}
if (Event.current.type == EventType.DragExited)
{
Debug.Log("Drag Exit");
_IsDragging = false;
_draggedClone.GetComponent<Collider>().enabled = true;
}
}
}
So I've tried several types of approach, first the classic input way :
if (Input.GetAxis("Mouse ScrollWheel") != 0) { Debug.Log(Input.GetAxis("Mouse ScrollWheel")); }
and then, the event way :
if(Event.current.type == EventType.ScrollWheel) { Debug.Log(Event.current.delta); }
In both case, nothing came out while calling them in the isDragging if statement. Did I miss something obvious ?
Your answer
Follow this Question
Related Questions
Override Editor Controls 1 Answer
Dynamic skill system with scriptable objects 2 Answers
C# Delegates, a question 1 Answer