using EasyTalk.Controller; using System.Collections.Generic; namespace EasyTalk.Display { /// /// This class implements logic which helps to manage animatable character portrayals/portrait displays during dialogue playback. /// public class CharacterDisplay : DialogueListener { /// /// A List of character sprite panels which will be managed by the display. /// private List characterPanels = new List(); /// /// Whether the display is initialized. /// private bool initialized = false; /// private void Awake() { if (!initialized) { Init(); } } /// private void Init() { FindCharacterPanels(); initialized = true; } /// /// Finds all of the character sprite panels which are children of this display and adds them to the characterPanels List to be managed. /// private void FindCharacterPanels() { characterPanels.Clear(); CharacterSpritePanel[] spritePanels = GetComponentsInChildren(true); foreach(CharacterSpritePanel panel in spritePanels) { characterPanels.Add(panel); } } /// /// When the dialogue exists, the character display will hide all of the visible characters' displays. /// /// The name of the exist point for the dialogue. public override void OnDialogueExited(string exitPointName) { base.OnDialogueExited(exitPointName); HideAll(); } /// /// Hides all managed character panels. /// public void HideAll() { foreach (CharacterSpritePanel panel in characterPanels) { panel.Hide(); } } /// /// Returns whether or not any of the managed character panels is portraying the character who has the specified name. /// /// The name of the character to check. /// Whether the character is being displayed on any of the managed character panels. public bool IsShowingCharacter(string characterName) { foreach (CharacterSpritePanel panel in characterPanels) { if (panel.CurrentCharacterName != null && panel.CurrentCharacterName.Equals(characterName) && !panel.IsHidden) { return true; } } return false; } } }