How can I register Mouse Events in the Scene window of the Editor?

How can I register Mouse Events in the Scene window of the Editor?

I want to create a custom level editor for the level designers that should allow them to place predefined objects in Unity3d similar to the Terrain wizard.
How can I register Mouse Events in the Scene window of the Editor?

Solutions/Answers:

Answer 1:

Perhaps this is something you are looking for. This allows you to register mouse events in the scene, when a game object with the specified type is selected in the hierarchy.

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(SomeScriptType))]
public class MyEditorPlayer : Editor 
{
    void OnSceneGUI()
    {
        int controlID = GUIUtility.GetControlID(FocusType.Passive);

        switch (Event.current.GetTypeForControl(controlID))
        {
            case EventType.mouseDown:
                GUIUtility.hotControl = controlID;
                Debug.Log("MouseDown");
                Event.current.Use();
                break;

            case EventType.MouseUp:
                GUIUtility.hotControl = 0;
                Event.current.Use();
                break;
        }
    }
}

Answer 2:

You only need to add the [ExecuteInEditMode] attribute to your class to run events in edit mode:

[ExecuteInEditMode]
public class myclass: MonoBehaviour 
{
    void Update() 
    {

    }
}

References