[HOWTO] How To: Add New Drag-n-Drop to Sequence field
Posted: Tue Oct 31, 2023 5:16 pm
This article contains an example of customizing the Dialogue Editor. It uses a C# hook described in [url=https://pixelcrushers.com/dialogue_syst ... mizeEditor]Customizing The Editor[/code].
If you drag a sprite into a dialogue entry's Sequence field, it will add a SetPortrait() sequencer command. It only checks for Sprites, so you have to drag the sprite into the Sequence field, not its parent Texture. Also, just a reminder that SetPortrait() requires the sprite to be in a Resources folder, addressable, or asset bundle.
If you drag a sprite into a dialogue entry's Sequence field, it will add a SetPortrait() sequencer command. It only checks for Sprites, so you have to drag the sprite into the Sequence field, not its parent Texture. Also, just a reminder that SetPortrait() requires the sprite to be in a Resources folder, addressable, or asset bundle.
Code: Select all
using UnityEngine;
using UnityEditor;
using PixelCrushers.DialogueSystem;
using PixelCrushers.DialogueSystem.DialogueEditor;
[InitializeOnLoad]
public static class AddSetPortraitDragAndDrop
{
static AddSetPortraitDragAndDrop()
{
SequenceEditorTools.tryDragAndDrop += TryDragAndDrop;
}
private static bool TryDragAndDrop(UnityEngine.Object obj, ref string sequence)
{
// Is a dialogue entry selected, and have we dropped a Sprite onto it?
if (obj is Sprite sprite && DialogueEditorWindow.inspectorSelection is DialogueEntry entry)
{
// Get the actor's name:
Actor actor = DialogueEditorWindow.GetCurrentlyEditedDatabase().GetActor(entry.ActorID);
string actorName = (actor != null) ? actor.Name : "???";
// Add a semicolon and newline if necessary:
if (!string.IsNullOrEmpty(sequence))
{
if (!sequence.EndsWith(";")) sequence += ";";
sequence += "\n";
}
// Then add the command:
sequence += $"SetPortrait({actorName}, {sprite.name})";
return true;
}
else
{
return false;
}
}
}