using UnityEngine;
using System.Collections;

public class LayerSlice : MonoBehaviour 
{
    public int InsertionOrder = 1;
    private LayerSliceEffect mEffect = null;

    void Awake()
    {
        Util.AssertTrue(InsertionOrder >= 1, "InsertionOrder must be equal to or higher than 1");
        Util.AssertTrue(transform.parent.GetComponent<IInputReceivable>() != null, "LayerSlice objects must be sons of IInputReceivables");        
        Util.AssertTrue(GetComponents<LayerSliceEffect>().Length <= 1, "Only 0 or 1 effect per slice is currently suported");
        mEffect = GetComponent<LayerSliceEffect>();
    }

    public void Init(bool removing)
    {
        if (mEffect != null)
        {
            mEffect.Init(removing);
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns>True if the effect ended, false otherwise</returns>
    public bool CustomUpdate(float deltaTime)
    {
        if (mEffect == null)
        {
            return true;
        }
        return mEffect.CustomUpdate(deltaTime);
    }

    public void OnLayerPositionSet()
    {
        if (mEffect != null)
        {
            mEffect.OnLayerPositionSet();
        }
    }
}