using UnityEngine;
using System.Collections;
using Framework.Entities;
using Framework.Extensions;
using System.Linq;
using System.Collections.Generic;
using Framework.InteractionSystem;
using Framework.Utility;
using UnityEngine.UI;
using System.Threading;

namespace Project.Effects
{
    public class FadeEffect : CoreBehaviour
    {
        public float time = 0.5f;
        private Image image;
        private UnityTimer lifeTimer;
        public bool proceed = true;
        private UnityTimer waitTimer;

        // Use this for initialization
        protected override void InnerAwake()
        {
            this.image = GetComponent<Image>();
            this.lifeTimer = new UnityTimer(this.time, false);
            this.waitTimer = new UnityTimer(3f, false);
        }

        protected override void InnerStart()
        {
        }

        // Update is called once per frame
        protected override void InnerUpdate()
        {
            this.waitTimer.Advance();
            if (this.waitTimer.IsComplete())
            {
                this.lifeTimer.Advance();
                float phase = this.lifeTimer.GetCurrent() / this.lifeTimer.GetEnd();
                this.image.color = new Color(this.image.color.r, this.image.color.g, this.image.color.b, 1 - phase);
                if (this.lifeTimer.IsComplete())
                {
                    Application.LoadLevel(Application.loadedLevel + 1);
                    Destroy(this.gameObject);
                }
            }
        }
    }
}