Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- [InitializeOnLoad]
- public static class ExtendedHotkeys
- {
- public static GameObject go;
- public static Vector3 goPos;
- public static bool Ldown = false;
- static ExtendedHotkeys()
- {
- SceneView.onSceneGUIDelegate += view =>
- {
- var e = Event.current;
- if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.L)
- {
- Ldown = true;
- e.Use();
- }
- if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.L)
- {
- Ldown = false;
- e.Use();
- }
- if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Ldown)
- {
- Vector2 mousePos = Event.current.mousePosition;
- mousePos.y = SceneView.currentDrawingSceneView.camera.pixelHeight - mousePos.y;
- Vector3 pos = new Vector3(mousePos.x, mousePos.y, SceneView.currentDrawingSceneView.camera.nearClipPlane+2.0f );
- AddSpotlight(pos);
- e.Use();
- }
- };
- }
- static void AddSpotlight(Vector3 pos)
- {
- go = new GameObject("Pointlight");
- go.AddComponent<Light>().type = LightType.Point;
- go.transform.eulerAngles = new Vector3(0, 0, 0);
- AfterCreation( pos);
- }
- static void AfterCreation(Vector3 pos)
- {
- goPos = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(pos);
- Debug.Log(pos);
- go.transform.position = goPos;
- Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
- Selection.activeObject = go;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement