Page 1 of 1

How to get your actor's portrait in code

Posted: Wed Oct 31, 2018 3:52 pm
by jman
Just wondering how do I obtain the actor's portrait within the code and also understand how to utilize the files[] type.

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

Posted: Wed Oct 31, 2018 5:07 pm
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.

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

Posted: Mon Nov 12, 2018 12:28 pm
by jman
Thanks, but it also seems that CreateSprite method is not showing up is there a namespace i must use?

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

Posted: Mon Nov 12, 2018 1:45 pm
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.