using System;
using UnityEngine;
using Wizard;
using Wizard.Battle.Phase;

public class UnityEventAgent : MonoBehaviour
{
	private BattleManagerBase m_battleMgr;

	private Action ResetTouchable;

	public bool HasFocus { get; private set; }

	public UnityEventAgent()
	{
		HasFocus = true;
	}

	public void SetBattleMgr(BattleManagerBase battleMgr)
	{
		m_battleMgr = battleMgr;
	}

	private void Update()
	{
		m_battleMgr.Update(Time.deltaTime);
	}

	private void OnDisable()
	{
		LocalLog.AccumulateLastTraceLog("【UnityEventAgent】Object is Disabled");
	}

	private void OnEnable()
	{
		LocalLog.AccumulateLastTraceLog("【UnityEventAgent】Object is Enabled");
	}

	private void OnApplicationPause(bool pause)
	{
		if (!IsSkipPause())
		{
			if (m_battleMgr != null)
			{
				LocalLog.AccumulateLastTraceLog("【UnityEventAgent】OnApplicationPause is called!! isPause：" + pause + "【Phase】：" + m_battleMgr.GetCurrentPhase());
			}
			HasFocus = !pause;
			if (pause)
			{
				m_battleMgr.Pause();
			}
			else
			{
				m_battleMgr.Resume();
			}
		}
	}

	private void OnApplicationFocus(bool focus)
	{
		if (!IsSkipPause())
		{
			if (m_battleMgr != null)
			{
				LocalLog.AccumulateLastTraceLog("【UnityEventAgent】OnApplicationFocus is called!! isFocus：" + focus + "【Phase】：" + m_battleMgr.GetCurrentPhase());
			}
			HasFocus = focus;
			if (focus)
			{
				m_battleMgr.Pause();
				m_battleMgr.Resume();
			}
			else
			{
				m_battleMgr.Pause();
			}
		}
	}

	private bool IsSkipPause()
	{
		if (m_battleMgr != null && (m_battleMgr.GetCurrentPhase() is LoadingPhase || m_battleMgr.GetCurrentPhase() is OpeningPhase))
		{
			return true;
		}
		return false;
	}
}
