|
|
|
|
|
|
using UnityEditor; |
|
|
|
using UnityEditorInternal; |
|
|
|
using System.Linq; |
|
|
|
using System; |
|
|
|
|
|
|
|
namespace GameplayIngredients.Editor |
|
|
|
{ |
|
|
|
|
|
|
void DrawHeader(Rect r) |
|
|
|
{ |
|
|
|
GUI.Label(r, new GUIContent($" {serializedProperty.displayName}", Styles.callableIcon), EditorStyles.boldLabel); |
|
|
|
HandleDrop(r, this); |
|
|
|
} |
|
|
|
|
|
|
|
void HandleDrop(Rect rect, CallableReorderableList list) |
|
|
|
{ |
|
|
|
var currentEvent = Event.current; |
|
|
|
var usedEvent = false; |
|
|
|
|
|
|
|
switch (currentEvent.type) |
|
|
|
{ |
|
|
|
case EventType.DragExited: |
|
|
|
if (GUI.enabled) |
|
|
|
HandleUtility.Repaint(); |
|
|
|
break; |
|
|
|
|
|
|
|
case EventType.DragUpdated: |
|
|
|
case EventType.DragPerform: |
|
|
|
if (rect.Contains(currentEvent.mousePosition) && GUI.enabled) |
|
|
|
{ |
|
|
|
bool acceptAtLeastOne = false; |
|
|
|
Object[] droppedObjects = DragAndDrop.objectReferences; |
|
|
|
foreach (Object obj in droppedObjects) |
|
|
|
{ |
|
|
|
if (obj != null && obj is Callable) |
|
|
|
{ |
|
|
|
DragAndDrop.visualMode = DragAndDropVisualMode.Copy; |
|
|
|
if (currentEvent.type == EventType.DragPerform) |
|
|
|
{ |
|
|
|
list.serializedProperty.arraySize++; |
|
|
|
int arrayEnd = list.serializedProperty.arraySize - 1; |
|
|
|
list.serializedProperty.GetArrayElementAtIndex(arrayEnd).objectReferenceValue = obj as Callable; |
|
|
|
acceptAtLeastOne = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (acceptAtLeastOne) |
|
|
|
{ |
|
|
|
GUI.changed = true; |
|
|
|
DragAndDrop.AcceptDrag(); |
|
|
|
usedEvent = true; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (usedEvent) |
|
|
|
currentEvent.Use(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void DrawElement(Rect r, int index, bool isActive, bool isFocused) |
|
|
|
|
|
|
|
|
|
|
public static class CallableExtensions |
|
|
|
{ |
|
|
|
public static void AddCallable(this GameObject gameObject, Component component, string propertyName, Type t) |
|
|
|
public static void AddCallable(this GameObject gameObject, Component component, string propertyName, System.Type t) |
|
|
|
{ |
|
|
|
var field = component.GetType().GetFields().Where(f => f.Name == propertyName).FirstOrDefault(); |
|
|
|
var val = field.GetValue(component) as Callable[]; |
|
|
|