Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- public class ObjectPlacer : EditorWindow {
- public GameObject prefab;
- [MenuItem ("Window/Object Placer")]
- static void Init () {
- ObjectPlacer window = (ObjectPlacer)EditorWindow.GetWindow (typeof (ObjectPlacer));
- window.Show();
- }
- void OnGUI() {
- prefab = EditorGUILayout.ObjectField ("Prefab", prefab, typeof(GameObject), true) as GameObject;
- }
- // Setup to be called by OnFocus and OnDestroy
- void OnSceneGUI(SceneView sceneView) {
- if (!prefab)
- return;
- if (Event.current.type == EventType.mouseDown) {
- RaycastHit hit;
- bool didHitSomething = Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out hit);
- if (didHitSomething) {
- GameObject instance = Instantiate (prefab) as GameObject;
- instance.transform.position = hit.point;
- Undo.RegisterCreatedObjectUndo (instance, "Undo Instantiate " + prefab.name);
- }
- }
- }
- void OnFocus() {
- // Add or readd delegate
- SceneView.onSceneGUIDelegate -= OnSceneGUI;
- SceneView.onSceneGUIDelegate += OnSceneGUI;
- }
- void OnDestroy() {
- SceneView.onSceneGUIDelegate -= OnSceneGUI;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement