using TMPro;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

namespace Streamingle.Subtitles
{
    [TrackColor(0.16f, 0.72f, 0.86f)]
    [TrackBindingType(typeof(TMP_Text))]
    [TrackClipType(typeof(SubtitleClip))]
    public sealed class SubtitleTrack : TrackAsset
    {
        public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
        {
            return ScriptPlayable<SubtitleMixerBehaviour>.Create(graph, inputCount);
        }

#if UNITY_EDITOR
        public override void GatherProperties(PlayableDirector director, IPropertyCollector collector)
        {
            var target = director != null ? director.GetGenericBinding(this) as TMP_Text : null;
            if (target != null)
                collector.AddFromName<TMP_Text>(target.gameObject, "m_text");

            base.GatherProperties(director, collector);
        }
#endif
    }
}
