[HOWTO] How To: Add New Drag-n-Drop to Sequence field

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 20632
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Add New Drag-n-Drop to Sequence field

Post by Tony Li »

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.

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;
        }
    }
}
Post Reply