2021-03-25 16:53:39 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
2021-03-29 09:10:59 +08:00
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
2021-03-25 16:53:39 +08:00
|
|
|
|
|
|
|
|
|
|
public class UIManager : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
private GameObject mMainPanel;
|
|
|
|
|
|
public GameObject MainPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.mMainPanel;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
this.mMainPanel = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-29 09:10:59 +08:00
|
|
|
|
private HomeController mHomePanel;
|
|
|
|
|
|
public HomeController HomePanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.GetPanelInstance("HomePanel", ref this.mHomePanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-25 16:53:39 +08:00
|
|
|
|
private UserInfoController mUserInfoPanel;
|
|
|
|
|
|
public UserInfoController UserInfoPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.GetPanelInstance<UserInfoController>("UserInfoPanel", ref this.mUserInfoPanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-29 09:10:59 +08:00
|
|
|
|
private DeviceController mDeviceController;
|
|
|
|
|
|
public DeviceController DevicePanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.GetPanelInstance("DevicePanel", ref this.mDeviceController);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-30 14:23:41 +08:00
|
|
|
|
|
2021-03-30 14:14:24 +08:00
|
|
|
|
private MapListController mMapListController;
|
|
|
|
|
|
public MapListController MapListPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.GetPanelInstance("MapListPanel", ref this.mMapListController);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-30 14:23:41 +08:00
|
|
|
|
|
|
|
|
|
|
private EditUserController mEditUserController;
|
|
|
|
|
|
public EditUserController EditUserPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.GetPanelInstance("EditUserPanel", ref this.mEditUserController);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject mModalsPanel;
|
|
|
|
|
|
public GameObject ModalsPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.mModalsPanel;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
this.mModalsPanel = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-25 16:53:39 +08:00
|
|
|
|
public static UIManager Instance;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance = this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private T GetPanelInstance<T>(string prefabName, ref T internalComponent)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (internalComponent == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/" + prefabName);
|
|
|
|
|
|
if (@object != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(@object, base.transform.parent, false);
|
|
|
|
|
|
if (gameObject != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
internalComponent = gameObject.GetComponent<T>();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return internalComponent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-30 14:23:41 +08:00
|
|
|
|
public static void Show(MonoBehaviour panelToShow, GameObject parent = null, bool modal = false)
|
2021-03-25 16:53:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (UIManager.Instance == null || panelToShow == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-03-30 14:23:41 +08:00
|
|
|
|
|
|
|
|
|
|
if (modal)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent = UIManager.Instance.ModalsPanel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-25 16:53:39 +08:00
|
|
|
|
foreach (Transform child in parent.transform)
|
|
|
|
|
|
{
|
|
|
|
|
|
//GameObject.Destroy(child);
|
|
|
|
|
|
//GameObject.Destroy(child.gameObject);
|
|
|
|
|
|
child.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
//var panel = UIManager.Instance.MainPanel; //UIManager.Instance.MainCanvasTransform.transform.Find("Panel");
|
|
|
|
|
|
|
|
|
|
|
|
//panel.gameObject.AddComponent<GameObject>(panelToShow.gameObject);
|
|
|
|
|
|
panelToShow.transform.SetParent(parent.transform);
|
|
|
|
|
|
|
2021-03-29 09:10:59 +08:00
|
|
|
|
panelToShow.gameObject.SetActive(true);
|
|
|
|
|
|
//panelToShow.transform.position = new Vector3(0, 0, 0);
|
|
|
|
|
|
panelToShow.transform.localPosition = new Vector3(0, 0, 0);
|
|
|
|
|
|
//panelToShow.transform.localRotation = new Quaternion(0, 0, 0, 0);
|
|
|
|
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
|
|
|
|
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
|
|
|
|
|
|
panelToShow.transform.localScale = parent.transform.localScale;
|
|
|
|
|
|
|
2021-03-25 16:53:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public static void ShowHomePanel()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// UIManager.Show(UIManager.Instance.PanelHome, UIManager.Instance.MainPanel);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
public static void ShowUserInfoPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Show(UIManager.Instance.UserInfoPanel, UIManager.Instance.MainPanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-29 09:10:59 +08:00
|
|
|
|
public static void ShowHomePanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Show(UIManager.Instance.HomePanel, UIManager.Instance.MainPanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void ShowDevicePanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Show(UIManager.Instance.DevicePanel, UIManager.Instance.MainPanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-30 14:23:41 +08:00
|
|
|
|
public static void ShowEditUserPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Show(UIManager.Instance.EditUserPanel, UIManager.Instance.MainPanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-25 16:53:39 +08:00
|
|
|
|
public static void ShowLoadingDialogBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
public static void ShowMapListPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Show(UIManager.Instance.MapListPanel, UIManager.Instance.MainPanel);
|
|
|
|
|
|
}
|
2021-03-29 09:10:59 +08:00
|
|
|
|
public static void AddEvent(GameObject gameObject, EventTriggerType eventTriggerType, UnityAction<BaseEventData> call)
|
|
|
|
|
|
{
|
|
|
|
|
|
EventTrigger et = gameObject.GetComponent<EventTrigger>();
|
|
|
|
|
|
if (et == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
et = gameObject.AddComponent<EventTrigger>();
|
|
|
|
|
|
}
|
|
|
|
|
|
EventTrigger.Entry pointerEvent = new EventTrigger.Entry();
|
|
|
|
|
|
pointerEvent.eventID = eventTriggerType;
|
|
|
|
|
|
pointerEvent.callback.AddListener(call);
|
|
|
|
|
|
et.triggers.Add(pointerEvent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-25 16:53:39 +08:00
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|