using UnityEngine;
using System.Collections;

namespace mgaia.Utils.Pause
{
    /// <summary>
    /// Classe básica para um sistema de pause
    /// </summary>
    /// <owner>Victor</owner>
    public abstract class BasePauseManager
    {
        private Semaphore mSemaphore;

        public BasePauseManager()
        {
            if (mSemaphore == null)
            {
                mSemaphore = new Semaphore(SemaphoreStateChanged);
            }
        }

        private void SemaphoreStateChanged(Semaphore semaphore)
        {
            if (semaphore == mSemaphore)
            {
                HandlePauseStateChanged(semaphore.IsLocked);
            }
        }

        /// <summary>
        /// Pausa o jogo
        /// </summary>
        public void Pause()
        {
            mSemaphore.AddLock();
        }

        /// <summary>
        /// Despausa o jogo
        /// </summary>
        public void Resume()
        {
            mSemaphore.RemoveLock();
        }

        protected abstract void HandlePauseStateChanged(bool isPaused);
    }
}