-
-
Save bzgeb/3800350 to your computer and use it in GitHub Desktop.
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; | |
} | |
} | |
} |
Could you call GetComponent on the dragged game object?
Thanks a big Bunch!!!!
This is nice, but how do you get a reference to the component being dragged instead of the entire object? For example, I want to drag a specific MonoBehavior component attached to the object so that I can add it to a list of behaviors to enable or disable, but the dragged_object only references the GameObject that the behavior is attached to.
How about Getting the GameObject and then call Getcomponent on it.
Gameobject obj = dragged_object as GameObject;
T type = obj.GetComponent< T >();
Give it a try
No, GetComponent can't be called on Object. Anyway, I figured out my original issue which led me to try this solution so I don't need it anymore.
goodWork
Wonderful!
<3
I love you most. More than all those people from past years.
Seriously thanks for this - trying to jump into the Editor coding has been rough for me, and this gave me a great platform to jump into it.
Dian son, this is good, thanks!
What a gigachad
This is nice, but how do you get a reference to the component being dragged instead of the entire object? For example, I want to drag a specific MonoBehavior component attached to the object so that I can add it to a list of behaviors to enable or disable, but the dragged_object only references the GameObject that the behavior is attached to.