Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 22, 2024 11:47
Show Gist options
  • Save baba-s/fe00a972049ae0886a9d728557376540 to your computer and use it in GitHub Desktop.
Save baba-s/fe00a972049ae0886a9d728557376540 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
internal static class Example
{
static Example()
{
SceneView.beforeSceneGui -= OnDuringSceneGui;
SceneView.beforeSceneGui += OnDuringSceneGui;
static void OnDuringSceneGui( SceneView sceneView )
{
var position = Event.current.mousePosition;
var currentDrawingSceneView = SceneView.currentDrawingSceneView;
var camera = currentDrawingSceneView.camera;
position.y = camera.pixelHeight - position.y;
position = camera.ScreenToWorldPoint( position );
position.y = -position.y;
var outObjectList = new List<Object>();
HandleUtility.GetOverlappingObjects( position, outObjectList );
foreach ( var outObject in outObjectList )
{
Debug.Log( outObject );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment