using System;
using UnityEngine;

public class BaseMgr<T> : MonoBehaviour where T : MonoBehaviour
{
	public static T Instance
	{
		get
		{
			if (BaseMgr<T>.instance == null)
			{
				BaseMgr<T>.instance = (T)((object)UnityEngine.Object.FindObjectOfType(typeof(T)));
				if (BaseMgr<T>.instance == null)
				{
					Debug.LogWarning("An instance of " + typeof(T) + " is needed in the scene, but there is none.");
				}
			}
			return BaseMgr<T>.instance;
		}
	}

	protected GameObject GetPanel(string panelName, string rootPath)
	{
		GameObject gameObject = GameObject.Find(rootPath);
		NDebug.Assert(gameObject != null, string.Format("{0}が見つかりませんでした。", "UI Root"));
		this.m_goPanel = gameObject.transform.Find(panelName).gameObject;
		NDebug.Assert(this.m_goPanel != null, string.Format("{0}が見つかりませんでした。", panelName));
		return this.m_goPanel;
	}

	protected GameObject GetPanel(string panelName)
	{
		return this.GetPanel(panelName, this.m_uiRootPath);
	}

	protected Type GetCtrl<Type>() where Type : Component
	{
		Type component = this.m_goPanel.GetComponent<Type>();
		NDebug.Assert(component != null, string.Format("{0}が見つかりませんでした。", typeof(Type) + "コンポーネント"));
		return component;
	}

	public bool IsValidateButton<T>(string clickButtonName)
	{
		if (!Enum.IsDefined(typeof(T), clickButtonName))
		{
			Debug.LogError(string.Format("不適切なボタンがクリックされました。クリックされたボタン名={0}", clickButtonName));
			return false;
		}
		return true;
	}

	public bool IsValidatePopupValue<T>(string value)
	{
		if (!Enum.IsDefined(typeof(T), value))
		{
			Debug.LogError(string.Format("ポップアップリストから不適切な値が選択されました。選択されたボタン名={0}", value));
			return false;
		}
		return true;
	}

	protected GameObject m_goPanel;

	private string m_uiRootPath = "/UI Root";

	protected static T instance;
}
