347 lines
9.7 KiB
C#
347 lines
9.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using DG.Tweening;
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
private PFUIPanel mMainPanel;
|
|
public PFUIPanel MainPanel
|
|
{
|
|
get
|
|
{
|
|
return this.mMainPanel;
|
|
}
|
|
set
|
|
{
|
|
this.mMainPanel = value;
|
|
}
|
|
}
|
|
|
|
private HomeController mHomePanel;
|
|
public HomeController HomePanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("HomePanel", ref this.mHomePanel);
|
|
}
|
|
}
|
|
|
|
private UserInfoController mUserInfoPanel;
|
|
public UserInfoController UserInfoPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance<UserInfoController>("UserInfoPanel", ref this.mUserInfoPanel);
|
|
}
|
|
}
|
|
|
|
private DeviceController mDeviceController;
|
|
public DeviceController DevicePanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("DevicePanel", ref this.mDeviceController);
|
|
}
|
|
}
|
|
|
|
private MapListController mMapListController;
|
|
public MapListController MapListPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("MapListPanel", ref this.mMapListController);
|
|
}
|
|
}
|
|
|
|
private MapDetailController mMapDetailController;
|
|
public MapDetailController MapDetailPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("MapDetailPanel", ref this.mMapDetailController);
|
|
}
|
|
}
|
|
|
|
private CyclingController mCyclingController;
|
|
public CyclingController CyclingController
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("CyclingController", ref this.mCyclingController);
|
|
}
|
|
}
|
|
|
|
private EditUserController mEditUserController;
|
|
public EditUserController EditUserPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("EditUserPanel", ref this.mEditUserController);
|
|
}
|
|
}
|
|
|
|
private PFUIPanel mModalsPanel;
|
|
public PFUIPanel ModalsPanel
|
|
{
|
|
get
|
|
{
|
|
return this.mModalsPanel;
|
|
}
|
|
set
|
|
{
|
|
this.mModalsPanel = value;
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
private T GetInstance<T>(string prefabName, ref T internalComponent)
|
|
{
|
|
if (internalComponent == null)
|
|
{
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/" + prefabName);
|
|
if (@object != null)
|
|
{
|
|
GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(@object, base.transform.parent, false);
|
|
if (gameObject != null)
|
|
{
|
|
internalComponent = gameObject.GetComponent<T>();
|
|
}
|
|
}
|
|
}
|
|
|
|
return internalComponent;
|
|
}
|
|
|
|
private static PFUIPanel prePanel = null;
|
|
public static void Show(PFUIPanel panelToShow, PFUIPanel parent = null, bool modal = false)
|
|
{
|
|
if (UIManager.Instance == null || panelToShow == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (modal)
|
|
{
|
|
parent = UIManager.Instance.ModalsPanel;
|
|
}
|
|
else
|
|
{
|
|
if(prePanel != null)
|
|
{
|
|
prePanel.Close();
|
|
}
|
|
prePanel = panelToShow;
|
|
}
|
|
//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);
|
|
parent.AddChild(panelToShow);
|
|
//panelToShow.gameObject.SetActive(true);
|
|
panelToShow.Show();
|
|
//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);
|
|
|
|
//if (modal == false)
|
|
{
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
|
|
}
|
|
panelToShow.transform.localScale = parent.transform.localScale;
|
|
}
|
|
|
|
public static void ShowCustom(PFUIPanel panelToShow, GameObject parent = null, bool modal = false)
|
|
{
|
|
if (UIManager.Instance == null || panelToShow == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (modal)
|
|
{
|
|
parent = UIManager.Instance.ModalsPanel.gameObject;
|
|
}
|
|
else
|
|
{
|
|
if (prePanel != null)
|
|
{
|
|
prePanel.Close();
|
|
}
|
|
prePanel = panelToShow;
|
|
}
|
|
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);
|
|
panelToShow.transform.parent = parent.transform;
|
|
//panelToShow.gameObject.SetActive(true);
|
|
panelToShow.Show();
|
|
//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);
|
|
|
|
//if (modal == false)
|
|
{
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
|
|
}
|
|
panelToShow.transform.localScale = parent.transform.localScale;
|
|
}
|
|
|
|
|
|
//public static void ShowHomePanel()
|
|
//{
|
|
// UIManager.Show(UIManager.Instance.PanelHome, UIManager.Instance.MainPanel);
|
|
//}
|
|
|
|
public static void ShowUserInfoPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.UserInfoPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void ShowHomePanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.HomePanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void ShowDevicePanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.DevicePanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void ShowEditUserPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.EditUserPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void ShowLoadingDialogBox()
|
|
{
|
|
}
|
|
public static void ShowMapListPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.MapListPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
public static void ShowMapDetailPanel(int id)
|
|
{
|
|
var ctrl = UIManager.Instance.MapDetailPanel;
|
|
ctrl.id = id;
|
|
UIManager.Show(UIManager.Instance.MapDetailPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public static void Close(MonoBehaviour obj)
|
|
{
|
|
obj.gameObject.SetActive(false);
|
|
}
|
|
|
|
public static void CloseModal()
|
|
{
|
|
//foreach (var item in UIManager.Instance.ModalsPanel.transform.DetachChildren)
|
|
//{
|
|
// item.
|
|
//}
|
|
|
|
//UIManager.Instance.ModalsPanel.transform.DetachChildren();
|
|
//UIManager.Instance.ModalsPanel.transform.childCount
|
|
for (int i = 0; i < 1; i++)
|
|
{
|
|
var obj = UIManager.Instance.ModalsPanel.transform.GetChild(i);
|
|
obj.gameObject.SetActive(false);
|
|
DestroyImmediate(obj.gameObject);
|
|
}
|
|
}
|
|
|
|
public Alert alert = null;
|
|
public static void ShowAlert(string msg)
|
|
{
|
|
if(UIManager.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (UIManager.Instance.alert == null)
|
|
{
|
|
UIManager.Instance.alert = UIManager.Instance.GetInstance<Alert>("Alert", ref UIManager.Instance.alert);
|
|
UIManager.Instance.alert.SetText(msg);
|
|
UIManager.Show(UIManager.Instance.alert, null, true);
|
|
}
|
|
else {
|
|
UIManager.Instance.alert.Show();
|
|
UIManager.Instance.alert.SetText(msg);
|
|
}
|
|
}
|
|
|
|
|
|
private void OnDestroy()
|
|
{
|
|
UIManager.Instance = null;
|
|
}
|
|
}
|