How to get your actor's portrait in code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
jman
Posts: 5
Joined: Wed Oct 31, 2018 3:45 pm

How to get your actor's portrait in code

Post by jman »

Just wondering how do I obtain the actor's portrait within the code and also understand how to utilize the files[] type.
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get your actor's portrait in code

Post by Tony Li »

Hi,

If you want to get any actor's portrait, use DialogueManager.masterDatabase.GetActor(x), where x is the actor's Name or ID. This returns an Actor object. Then call its GetPortraitTexture(#) function, where # is the portrait index, starting from 1. If you need it as a Sprite, call UITools.CreateSprite(). Example:

Code: Select all

Actor actor = DialogueManager.masterDatabase.GetActor("Player");
Texture2D primaryPortraitTexture = actor.GetPortraitTexture(1);
Sprite primaryPortraitSprite = UITools.CreateSprite(primaryPortraitTexture);
If a character is represented by a GameObject in the scene, it's possible that the GameObject may have a Dialogue Actor component. If so, you'll want to check that Dialogue Actor's portrait field first, which is used to override the actor's portrait in the dialogue database.

If a conversation is active and you want to get the current portraits of the current speaker and listener, it's simpler. Check DialogueManager.currentConversationState.subtitle.speakerInfo or listenerInfo. These are CharacterInfo objects, and they have a portrait field that points to the current portrait. Example:

Code: Select all

Texture2D currentSpeakerPortrait = DialogueManager.currentConversationState.subtitle.speakerInfo.portrait;

The files[] type is just a string of the format [filename, filename, ...]. It's not used for anything special in the Dialogue System. It only exists because the Dialogue System uses the same data structure as Chat Mapper, which defines this type.
User avatar
jman
Posts: 5
Joined: Wed Oct 31, 2018 3:45 pm

Re: How to get your actor's portrait in code

Post by jman »

Thanks, but it also seems that CreateSprite method is not showing up is there a namespace i must use?
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get your actor's portrait in code

Post by Tony Li »

The namespace is PixelCrushers.DialogueSystem. But I see that I had a typo. Where it said:

Code: Select all

actor.CreateSprite(primaryPortraitTexture); // (incorrect)
instead use UITools.CreateSprite:

Code: Select all

UITools.CreateSprite(primaryPortraitTexture); // (correct)
I typed it correctly in the text explanation and then mistyped immediately after in the code example. :oops:

I just fixed it in my previous post.

API Reference: PixelCrushers.DialogueSystem.UITools.CreateSprite.
Post Reply