#if !COMBAT_SERVER

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
#endif
using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventLogic;
using Object = System.Object;

/// <summary>
/// 播放特效
/// </summary>
[System.Serializable]
public class TimeLinePlayFxSerializtion : TimeLineAssetSerialization
{
    public string fxName;
    public uint randomSeed;
    public FXLocationType locationType;
    public string targetSpecialDotName;
    public string hitPointGroupName;
    public  bool isGround;
    /// <summary>
    /// 是否跟随目标
    /// </summary>
    public bool isFollowTarget;

    /// <summary>
    /// 是否不旋转 （默认是跟随目标旋转）
    /// </summary>
    public bool isNotRotate;

    /// <summary>
    /// 是否跟随攻击速度进行播放te
    /// </summary>
    public bool isAttSpeed;

    public int CustomTargetPosIndex;
    public bool isActivityCustomTargetPos;
    /// <summary>
    /// 是否循环
    /// </summary>
    public bool isLoop;
    /// <summary>
    /// 循环独立
    /// </summary>
    public bool loopAlone;
    public float intervalTime;
    public TimeLinePlayFxSerializtion()
    {
    }
#if !COMBAT_SERVER

    public TimeLinePlayFxSerializtion(PlayableDirector playableDirector, GroupTrack groupTrack,
        TimelineClip timelineClip) : base(groupTrack, timelineClip)
    {
        TimeLineParticleSystemAsset controlPlayableAsset = timelineClip.asset as TimeLineParticleSystemAsset;
        if (controlPlayableAsset == null)
        {
            return;
        }

        GameObject go = null;
       
        if (controlPlayableAsset.prefabGameObject != null)
        {
            go = controlPlayableAsset.prefabGameObject;
        }
        else if(playableDirector.playableGraph.GetResolver()!=null)
        {
            go=  controlPlayableAsset.sourceGameObject.Resolve(playableDirector.playableGraph.GetResolver());
        }

        Object obj = controlPlayableAsset.sourceGameObject.defaultValue;
        // Debug.Log(playableDirector.playableGraph.GetResolver());
        if (go != null)
        {
            fxName =go.name;
            randomSeed = controlPlayableAsset.particleRandomSeed;
            locationType = controlPlayableAsset.LocationType;
            targetSpecialDotName = controlPlayableAsset.targetSpecialDotName;
            hitPointGroupName = controlPlayableAsset.hitPointGroupName;
            isFollowTarget = controlPlayableAsset.isFollowTarget;
            isGround = controlPlayableAsset.isGround;
            isNotRotate = controlPlayableAsset.isNotRotate;
            isAttSpeed = controlPlayableAsset.isAttSpeed;
            targetEntityType = controlPlayableAsset.targetType;
            CustomTargetPosIndex = controlPlayableAsset.CustomTargetPosIndex;
            isActivityCustomTargetPos = controlPlayableAsset.isActivityCustomTargetPos;
            loopAlone = controlPlayableAsset.loopAlone;
            isLoop=controlPlayableAsset.isLoop;
            intervalTime=controlPlayableAsset.intervalTime;
        }
    }
#endif
    public override TimeLineEventLogicBasic CreateLogic()
    {
        return new TimeLineEventParticleLogicBasic();
    }
}