﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ActionSystem;
public class MassEditPositionOnEvent : EditOnEvent
{
    public bool Looping = false;
    public bool LocalPosition = false;
    [System.Serializable]
    public struct PositionInfo
    {
        public Vector3 Position;
        public float Duration;
        public Curve EasingCurve;
        public float DelayAfter;
    }

    public List<PositionInfo> Positions = new List<PositionInfo>();
    ActionSequence Seq = null;
	// Use this for initialization
	public override void Start ()
    {
        base.Start();
	}

    public override void OnEventFunc(EventData data)
    {
        if(Seq == null || !Looping)
        {
            FillSequence();
            EditChecks(Seq);
        }
    }

    void FillSequence()
    {
        Seq = Action.Sequence(this.GetActions(), Looping);
        if(!LocalPosition)
        {
            foreach (var i in Positions)
            {
                Action.Property(Seq, transform.GetProperty(o => o.position), transform.position + i.Position, i.Duration, i.EasingCurve);
                if (i.DelayAfter != 0)
                {
                    Action.Delay(Seq, i.DelayAfter);
                }
            }
        }
        else
        {
            foreach (var i in Positions)
            {
                Action.Property(Seq, transform.GetProperty(o => o.localPosition), transform.localPosition + i.Position, i.Duration, i.EasingCurve);
                if (i.DelayAfter != 0)
                {
                    Action.Delay(Seq, i.DelayAfter);
                }
            }
        }
    }
}
