BaseMgr.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using UnityEngine;
  3. public class BaseMgr<T> : MonoBehaviour where T : MonoBehaviour
  4. {
  5. public static T Instance
  6. {
  7. get
  8. {
  9. if (BaseMgr<T>.instance == null)
  10. {
  11. BaseMgr<T>.instance = (T)((object)UnityEngine.Object.FindObjectOfType(typeof(T)));
  12. if (BaseMgr<T>.instance == null)
  13. {
  14. Debug.LogWarning("An instance of " + typeof(T) + " is needed in the scene, but there is none.");
  15. }
  16. }
  17. return BaseMgr<T>.instance;
  18. }
  19. }
  20. protected GameObject GetPanel(string panelName, string rootPath)
  21. {
  22. GameObject gameObject = GameObject.Find(rootPath);
  23. NDebug.Assert(gameObject != null, string.Format("{0}が見つかりませんでした。", "UI Root"));
  24. this.m_goPanel = gameObject.transform.Find(panelName).gameObject;
  25. NDebug.Assert(this.m_goPanel != null, string.Format("{0}が見つかりませんでした。", panelName));
  26. return this.m_goPanel;
  27. }
  28. protected GameObject GetPanel(string panelName)
  29. {
  30. return this.GetPanel(panelName, this.m_uiRootPath);
  31. }
  32. protected Type GetCtrl<Type>() where Type : Component
  33. {
  34. Type component = this.m_goPanel.GetComponent<Type>();
  35. NDebug.Assert(component != null, string.Format("{0}が見つかりませんでした。", typeof(Type) + "コンポーネント"));
  36. return component;
  37. }
  38. public bool IsValidateButton<T>(string clickButtonName)
  39. {
  40. if (!Enum.IsDefined(typeof(T), clickButtonName))
  41. {
  42. Debug.LogError(string.Format("不適切なボタンがクリックされました。クリックされたボタン名={0}", clickButtonName));
  43. return false;
  44. }
  45. return true;
  46. }
  47. public bool IsValidatePopupValue<T>(string value)
  48. {
  49. if (!Enum.IsDefined(typeof(T), value))
  50. {
  51. Debug.LogError(string.Format("ポップアップリストから不適切な値が選択されました。選択されたボタン名={0}", value));
  52. return false;
  53. }
  54. return true;
  55. }
  56. protected GameObject m_goPanel;
  57. private string m_uiRootPath = "/UI Root";
  58. protected static T instance;
  59. }