﻿using System;
using UnityEngine;
using System.Collections;
using Febucci.TextAnimatorForUnity;
using Febucci.TextAnimatorCore.Typing;
using UtageExtensions;

namespace Utage
{
	public class SampleTextAnimatorEvent : MonoBehaviour
	{
        NovelTextForTextAnimator NovelText => this.GetComponentCache(ref novelText);
        [SerializeField] NovelTextForTextAnimator novelText;
        TypewriterComponent Typewriter => this.GetComponentCache(ref typewriter);
        [SerializeField] TypewriterComponent typewriter;
        void Awake()
        {
            Typewriter.onMessage.AddListener(OnMessage);
/*
            Typewriter.onTypewriterStart.AddListener(() =>
            {
                Debug.LogWarning($"frame={Time.frameCount} Typewriter Start");
            });
            Typewriter.onTextDisappeared.AddListener(() =>
            {
                Debug.LogWarning($"frame={Time.frameCount} Text Disappeared");
            });
            Typewriter.onCharacterVisible.AddListener(characterData=>
            {
                Debug.LogWarning($"frame={Time.frameCount} Character Visible index={characterData.index}, char='{characterData.info.character}'");
            });
*/        }

        void OnDestroy()
        {
            if (Typewriter) Typewriter.onMessage.RemoveListener(OnMessage);
        }

        void OnMessage(EventMarker eventData)
        {
            string msg = $"frame={Time.frameCount} 　event Name = {eventData.name}, index = {eventData.index} parameters = {string.Join(", ",eventData.parameters)}\n"
                + $"MaxVisibleCharacters = {NovelText.MaxVisibleCharacters},  TextAnimator.CharactersCount = {NovelText.TextAnimator.CharactersCount}";
            Debug.LogWarning(msg);
//            UnityEditor.EditorApplication.isPaused = true;
        }
	}
}
