How to get your actor's portrait in code
How to get your actor's portrait in code
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
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:
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:
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.
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 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
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
The namespace is PixelCrushers.DialogueSystem. But I see that I had a typo. Where it said:
instead use UITools.CreateSprite:
I typed it correctly in the text explanation and then mistyped immediately after in the code example.
I just fixed it in my previous post.
API Reference: PixelCrushers.DialogueSystem.UITools.CreateSprite.
Code: Select all
actor.CreateSprite(primaryPortraitTexture); // (incorrect)
Code: Select all
UITools.CreateSprite(primaryPortraitTexture); // (correct)
I just fixed it in my previous post.
API Reference: PixelCrushers.DialogueSystem.UITools.CreateSprite.