I'm using a composite sprite system I created, so the sprites are dynamically generated by a script, then assigned to the sprite component of a spriteRenderer, and then that sprite component is saved as a playmaker Sprite variable. Then I'm using this playmaker action to assign that Sprite variable to the dialogue actor's portrait image.
Is there a better way to accomplish this?
Here is my playmaker action code:
Code: Select all
[ActionCategory("Dialogue")]
[HutongGames.PlayMaker.TooltipAttribute("Sets an actor's portrait")]
public class SetDialogueActorPortrait : FsmStateAction
{
[RequiredField]
[HutongGames.PlayMaker.TooltipAttribute("The name of the actor in the dialogue database")]
public FsmString actorName;
[RequiredField]
[ObjectType(typeof(Sprite))]
[HutongGames.PlayMaker.TooltipAttribute("The new portrait sprite to set")]
public FsmObject newPortrait;
public override void Reset()
{
actorName = null;
newPortrait = null;
}
public override void OnEnter()
{
var sprite = newPortrait.Value as Sprite;
if (sprite != null)
{
Actor actor = DialogueManager.MasterDatabase.GetActor(actorName.Value);
if (actor != null)
{
actor.spritePortrait = sprite;
}
}
Finish();
}
}
Code: Select all
public override void OnEnter()
{
var sprite = newPortrait.Value as Sprite;
if (sprite != null)
{
Actor actor = DialogueManager.MasterDatabase.GetActor(actorName.Value);
if (actor != null && actor.spritePortraits != null)
{
// Update the second portrait
actor.spritePortraits[2] = sprite;
}
}
Finish();
}