SHARE
TWEET

Untitled

a guest Dec 12th, 2018 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEditor;
  2. using UnityEngine;
  3. [InitializeOnLoad]
  4. public static class ExtendedHotkeys
  5. {
  6.     public static GameObject go;
  7.     public static Vector3 goPos;
  8.  
  9.  
  10.     public static bool Ldown = false;
  11.  
  12.     static ExtendedHotkeys()
  13.     {
  14.        
  15.         SceneView.onSceneGUIDelegate += view =>
  16.         {
  17.            
  18.             var e = Event.current;
  19.             if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.L)
  20.             {
  21.                 Ldown = true;
  22.                 e.Use();
  23.             }
  24.             if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.L)
  25.             {
  26.                 Ldown = false;
  27.                 e.Use();
  28.             }
  29.             if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Ldown)
  30.             {
  31.                 Vector2 mousePos = Event.current.mousePosition;
  32.                 mousePos.y = SceneView.currentDrawingSceneView.camera.pixelHeight - mousePos.y;
  33.                
  34.                 Vector3 pos = new Vector3(mousePos.x, mousePos.y, SceneView.currentDrawingSceneView.camera.nearClipPlane+2.0f  );
  35.                 AddSpotlight(pos);
  36.                 e.Use();
  37.             }
  38.         };
  39.     }
  40.  
  41.     static void AddSpotlight(Vector3 pos)
  42.     {
  43.         go = new GameObject("Pointlight");
  44.         go.AddComponent<Light>().type = LightType.Point;
  45.         go.transform.eulerAngles = new Vector3(0, 0, 0);
  46.         AfterCreation( pos);
  47.     }
  48.     static void AfterCreation(Vector3 pos)
  49.     {
  50.         goPos = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(pos);
  51.         Debug.Log(pos);
  52.        
  53.         go.transform.position = goPos;
  54.         Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
  55.         Selection.activeObject = go;
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top