using System.Collections.Generic;
using Fort23.UTool;

#if !COMBAT_SERVER

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
#endif

using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventLogic;

[System.Serializable]
public class TimeLineCollisionTriggerSerializtion : TimeLineAssetSerialization
{
    public string guid;
    public List<Vector3> allVe = new List<Vector3>();
    public Vector3 off;
    public string startPosGuid;
    public string boneName;

    public TimeLineCollisionTriggerSerializtion()
    {
    }
#if !COMBAT_SERVER
    public TimeLineCollisionTriggerSerializtion(PlayableDirector playableDirector, GroupTrack groupTrack,
        TimelineClip timelineClip) : base(groupTrack, timelineClip)
    {
        TimeLineCollisionTriggerAsset animationPlayableAsset =
            timelineClip.asset as TimeLineCollisionTriggerAsset;
        Object obj = animationPlayableAsset.GameObject.defaultValue;
        Debug.Log(obj);
        if (animationPlayableAsset.GameObject.Resolve(playableDirector.playableGraph.GetResolver()) != null)
        {
            GameObject go = animationPlayableAsset.GameObject.Resolve(playableDirector.playableGraph.GetResolver());
            BoxCollider2D boxCollider2D = go.GetComponent<BoxCollider2D>();
            if (boxCollider2D != null)
            {
                allVe = new List<Vector3>();
                Vector2 Half_size = boxCollider2D.size / 2;
                allVe.Add(new Vector3(-Half_size.x, -Half_size.y));
                allVe.Add(new Vector3(-Half_size.x, Half_size.y));
                allVe.Add(new Vector3(Half_size.x, Half_size.y));
                allVe.Add(new Vector3(Half_size.x, -Half_size.y));
                off = boxCollider2D.offset+(Vector2)boxCollider2D.transform.localPosition;
            }
            else
            {
                EdgeCollider2D edgeCollider2D = go.GetComponent<EdgeCollider2D>();
                if (edgeCollider2D != null)
                {
                    allVe = new List<Vector3>();
                    Vector2[] points = edgeCollider2D.points;
                    for (int i = 0; i < edgeCollider2D.pointCount; i++)
                    {
                        allVe.Add(points[i]);
                    }
                }
                off = edgeCollider2D.transform.localPosition;
            }

        
            guid = animationPlayableAsset.guid;
            startPosGuid = animationPlayableAsset.startPosGuid;
        }
    }
#endif

    public override TimeLineEventLogicBasic CreateLogic()
    {
        return new TimeLineCollisionTriggerLogic();
    }
}