Graphic menu elements set to "Dialog Portrait" will, by default, display the portrait graphic of the currently-speaking character.
This Action allows you to override that with a specific character, so that it always shows that character's portrait - regardless of whether they're talking or not.
ActionPortraitOverride.cs:
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionPortraitOverride : Action
{
public string menuName;
public string graphicElementName;
public bool isPlayer;
public AC.Char character;
private AC.Char runtimeChar;
public ActionPortraitOverride ()
{
this.isDisplayed = true;
category = ActionCategory.Menu;
title = "Set portrait override";
}
public override void AssignValues (List<ActionParameter> parameters)
{
runtimeChar = (isPlayer) ? KickStarter.player : character;
}
public override float Run ()
{
MenuElement element = PlayerMenus.GetElementWithName (menuName, graphicElementName);
if (element != null && element is MenuGraphic)
{
MenuGraphic menuGraphic = (MenuGraphic) element;
menuGraphic.PortraitCharacterOverride = runtimeChar;
}
return 0f;
}
#if UNITY_EDITOR
public override void ShowGUI ()
{
menuName = EditorGUILayout.TextField ("Menu name:", menuName);
graphicElementName = EditorGUILayout.TextField ("Graphic element name:", graphicElementName);
isPlayer = EditorGUILayout.Toggle ("Map to Player?", isPlayer);
if (!isPlayer)
{
character = (AC.Char) EditorGUILayout.ObjectField ("Character to map to:", character, typeof (AC.Char), true);
}
AfterRunningOption ();
}
#endif
}
}