Hi there,
I recently bought DS to use in a very dialog heavy game and it's made our work a ton easier!
We're using a VN style dialog system with the Player and NPCs using various sprites to express their emotions.
From the manual I learned that I can use [pic=#] to change which sprite is being used for a character, but I was wondering if there is an alternate way to to do it that could use the suffix of the sprite instead.
For example, all our sprites are named by their emotional state as follows:
charactername_angry
charactername_sad
etc.
Would it be possible to set up so that we can use their suffix (e.g. [pic=angry]) rather than than having to remember the numbers for each sprite? ([pic=15])
Thanks for your help!
Setting sprite image by name instead of number [img=#]
Re: Setting sprite image by name instead of number [img=#]
Hi,
There are several ways to accomplish this. I'll describe a few so you can pick one that works best for your workflow.
Three ways to change portraits are:
---
If you want to continue with [pic=#] tags, you can take advantage of the fact that [var=variable] tags are processed before [pic=#] tags. There are many ways to do this. Let's say all of your actors use:
In place of Dialogue Text like "I'm angry! [pic=4]", you'd use "I'm angry! [var=angry]".
---
Another alternative is to add a script with an OnConversationLine special method to the Dialogue Manager GameObject and process your own custom tags in the text. Example:
(Note: I typed that script into the reply; it might have typos.)
There are several ways to accomplish this. I'll describe a few so you can pick one that works best for your workflow.
Three ways to change portraits are:
- [pic=#] markup tag
- SetPortrait() sequencer command
- Animated portraits
- Technically I suppose Spine integration counts as a fourth way
- Sequence: {{default}}; SetPortrait(Adam, angry)
---
If you want to continue with [pic=#] tags, you can take advantage of the fact that [var=variable] tags are processed before [pic=#] tags. There are many ways to do this. Let's say all of your actors use:
- pic 1 = default
- pic 2 = happy
- pic 3 = sad
- pic 4= angry
In place of Dialogue Text like "I'm angry! [pic=4]", you'd use "I'm angry! [var=angry]".
---
Another alternative is to add a script with an OnConversationLine special method to the Dialogue Manager GameObject and process your own custom tags in the text. Example:
Code: Select all
using System.Text.RegularExpressions;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ProcessImgTags : MonoBehaviour
{
void OnConversationLine(Subtitle subtitle)
{
// Process custom [img=imageName] tags:
var match = Regex.Match(subtitle.formattedText.text, @"\[img=(^\])+\]");
if (match.Success)
{
// Get the image name from [img=imageName]:
var imageName = match.Value.Substring(5, match.Value.Length - 6).Trim();
// Remove the tag from the text:
subtitle.formattedText.text = subtitle.formattedText.text.Remove(match.Index, match.Length);
var actor = DialogueManager.masterDatabase.GetActor(subtitle.speakerInfo.id);
if (actor != null)
{
// Find the corresponding pic:
if (actor.spritePortrait != null && actor.spritePortrait.name == imageName)
{
subtitle.formattedText.pic = 1;
}
else
{
for (int i = 0; i < actor.alternatePortraits.Count; i++)
{
if (actor.alternatePortraits[i] != null && actor.alternatePortraits[i].name == imageName)
{
subtitle.formattedText.pic = i + 2;
break;
}
}
}
}
}
}
}
Re: Setting sprite image by name instead of number [img=#]
Thanks for the detailed reply Tony!
I'll be testing out your suggested methods and I think defining variables will likely be the easiest solution for our team.
I'll be testing out your suggested methods and I think defining variables will likely be the easiest solution for our team.