Hi,
I need to access the actor's portrait from code, but I'm not sure how it's stored in the database. Getting the Portraits field as a sprite array doesn't work. I perused the documentation, but couldn't find anything. How are the portraits stored and how can I access them?
Access portrait image in C# code
Re: Access portrait image in C# code
Hi!
The DialogueDatabase class has a list of actors. Each Actor has a portrait and an array of alternatePortraits which are Texture2Ds.
Let's say you want to get the first alternate portrait for an actor named "Bob". (You can tell a dialogue entry to show this portrait by using the [pic=2] tag.) You can use this code:
Note that these are Texture2Ds, which is the native format used by legacy Unity GUI, 2D Toolkit, NGUI, etc. If you're using Unity UI, you might want to get a Sprite instead by using this code:
PixelCrushers.DialogueSystem.UITools.CreateSprite() caches the value, so it will only actually create a new Sprite the first time you call it for a given Texture2D. After that, it will return the cached value.
The DialogueDatabase class has a list of actors. Each Actor has a portrait and an array of alternatePortraits which are Texture2Ds.
Let's say you want to get the first alternate portrait for an actor named "Bob". (You can tell a dialogue entry to show this portrait by using the [pic=2] tag.) You can use this code:
Code: Select all
var bob = DialogueManager.MasterDatabase.GetActor("Bob");
var pic2 = bob.alternatePortraits[0];
Code: Select all
var sprite = UITools.CreateSprite(pic2);