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?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI 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?
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;
}
}
}
You only need to add the [ExecuteInEditMode]
attribute to your class to run events in edit mode:
[ExecuteInEditMode]
public class myclass: MonoBehaviour
{
void Update()
{
}
}