浏览代码

Handle drop as Game Objects

/feature-handle-drop-rlist
Thomas ICHÉ 4 年前
当前提交
e408fa92
共有 2 个文件被更改,包括 24 次插入2 次删除
  1. 1
      Editor/BrowsePopup/CallableProvider.cs
  2. 25
      Editor/PropertyDrawers/CallableReorderableList.cs

1
Editor/BrowsePopup/CallableProvider.cs


static void AddCallable()
{
Undo.RecordObject(addNextComponentInfo.gameObject, "Add Callable");
addNextComponentInfo.gameObject.AddCallable(
addNextComponentInfo.component,
addNextComponentInfo.propertyName,

25
Editor/PropertyDrawers/CallableReorderableList.cs


Object[] droppedObjects = DragAndDrop.objectReferences;
foreach (Object obj in droppedObjects)
{
if (obj != null && obj is Callable)
if(obj != null && obj is GameObject)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (currentEvent.type == EventType.DragPerform)
{
GenericMenu m = new GenericMenu();
var callables = (obj as GameObject).GetComponents<Callable>();
foreach(var c in callables)
{
m.AddItem(new GUIContent($"{c.Name} ({c.GetType().Name})"), false, () => {
list.serializedProperty.serializedObject.Update();
list.serializedProperty.arraySize++;
int arrayEnd = list.serializedProperty.arraySize - 1;
list.serializedProperty.GetArrayElementAtIndex(arrayEnd).objectReferenceValue = c;
list.serializedProperty.serializedObject.ApplyModifiedProperties();
});
}
m.ShowAsContext();
acceptAtLeastOne = true;
}
}
else if (obj != null && obj is Callable)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (currentEvent.type == EventType.DragPerform)

if (t != null && typeof(Callable).IsAssignableFrom(t))
{
var newCmp = gameObject.AddComponent(t);
var newCmp = Undo.AddComponent(gameObject, t);
field.SetValue(component, val.Append(newCmp as Callable));
}
else

正在加载...
取消
保存