I have a SentanceList.asset file. You can see its layout in the SentanceListAsset.png ive attached.
This asset file contains a list of serialized sentance objects. I would like to use this “list” of sentances in a dialog system, a sort of drag and drop kind of thing, where I have an array of sentances to use in a seperate dialogmanager script attached to a canvas object.
If drag and drop isnt possible, then what is the best way to reference a specific sentance in this list of sentances? Im open to including more fields in my sentance object is its needed for referencing which sentance is which.
My issue is getting access to the sentances how I want to.
Any helpful pointers that you guys can provide?
You can write a PropertyDrawer for your SentenceAsset wherein you listen for EventTypes like MouseDown and DragMouse to setup UnityEditor.DragAndDrop for a drag operation. When that event happens you can pass the reference of the SentenceAsset into the DragAndDrop class. After you properly setup the drag, Unity’s own classes should automatically be able to detect and accept the drag in fields where it is allowable to be placed.
something a lot like this:
currentEvent = Event.current;
bool isDragged = DragAndDrop.objectReferences != null && property.objectReferenceValue == DragAndDrop.objectReferences[0];
switch (currentEvent.type)
{
case EventType.MouseDown:
if (!position.Contains(currentEvent.mousePosition)) break;
DragAndDrop.PrepareStartDrag();
currentEvent.Use();
break;
case EventType.MouseDrag:
if (DragAndDrop.visualMode == DragAndDropVisualMode.None)
{
//handle dragging from
DragAndDrop.objectReferences = new UnityEngine.Object { property.objectReferenceValue };
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
DragAndDrop.StartDrag("SentenceDrag");
currentEvent.Use();
}
break;
}
Color defaultColor = GUI.color;
GUI.color = isDragged ? Color.black : defaultColor;
EditorGUI.PropertyField(position, property);
GUI.color = defaultColor;