﻿using UnityEngine;
using System.Collections;

public class PauseManager : MonoBehaviour
{

    public Sprite pauseGameIcon;
    public Sprite unpauseGameIcon;
    
    private GamePauseState pauseState;
    private float originalTimeScale = 1; // The original scale before we paused the game.

    public enum GamePauseState
    {
        Paused = 0,
        UnPaused = 1
    }

    public GamePauseState PauseState
    {
        get
        {
            return pauseState;
        }
        set
        {
            pauseState = value;
            UpdatePauseState();
        }
    }

    // Use this for initialization
    void Start()
    {
        PauseState = GamePauseState.UnPaused;
    }

    // Switches the button mode
    public void SwitchPauseMode()
    {
        switch (PauseState)
        {
            case GamePauseState.Paused:
                UnPauseGame();
                break;
            case GamePauseState.UnPaused:
                PauseGame();
                break;
        }

    }

    private void PauseGame()
    {
        PauseState = GamePauseState.Paused;
    }

    private void UnPauseGame()
    {
        PauseState = GamePauseState.UnPaused;
    }

    private void UpdatePauseState()
    {
        switch (PauseState)
        {
            case GamePauseState.Paused:
                originalTimeScale = Time.timeScale;
                Time.timeScale = 0;
                GetComponent<UI2DSprite>().sprite2D = unpauseGameIcon;
                break;
            case GamePauseState.UnPaused:
                Time.timeScale = originalTimeScale;
                GetComponent<UI2DSprite>().sprite2D = pauseGameIcon;
                break;
        }
    }
}
