Skip to content

Instantly share code, notes, and snippets.

@litefeel
Forked from bzgeb/TriggerContainerEditor.cs
Created May 17, 2018 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litefeel/a9de175b84f8c032303838903648e84f to your computer and use it in GitHub Desktop.
Save litefeel/a9de175b84f8c032303838903648e84f to your computer and use it in GitHub Desktop.
Example Drag & Drop area in a custom inspector for the Unity editor
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor (typeof(TriggerContainer))]
public class TriggerContainerEditor : Editor
{
private SerializedObject obj;
public void OnEnable ()
{
obj = new SerializedObject (target);
}
public override void OnInspectorGUI ()
{
DrawDefaultInspector ();
EditorGUILayout.Space ();
DropAreaGUI ();
}
public void DropAreaGUI ()
{
Event evt = Event.current;
Rect drop_area = GUILayoutUtility.GetRect (0.0f, 50.0f, GUILayout.ExpandWidth (true));
GUI.Box (drop_area, "Add Trigger");
switch (evt.type) {
case EventType.DragUpdated:
case EventType.DragPerform:
if (!drop_area.Contains (evt.mousePosition))
return;
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (evt.type == EventType.DragPerform) {
DragAndDrop.AcceptDrag ();
foreach (Object dragged_object in DragAndDrop.objectReferences) {
// Do On Drag Stuff here
}
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment