1174 lines
36 KiB
C#
1174 lines
36 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using DG.Tweening;
|
|
using Assets.Scripts.UI.Prefab.Login;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine.UI;
|
|
using Assets.Scripts.UI.Control;
|
|
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using System.Linq;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using Assets.Scenes.Ride.Scripts;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Threading;
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private PFUIPanel mMainPanel;
|
|
|
|
public PFUIPanel MainPanel
|
|
{
|
|
get
|
|
{
|
|
return this.mMainPanel;
|
|
}
|
|
set
|
|
{
|
|
this.mMainPanel = value;
|
|
}
|
|
}
|
|
public Canvas MainCanvas
|
|
{
|
|
get
|
|
{
|
|
if (mMainPanel)
|
|
{
|
|
return mMainPanel.transform.parent.GetComponent<Canvas>();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
public GameObject Root;
|
|
|
|
private HomeController mHomePanel;
|
|
public HomeController HomePanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("HomePanel", ref this.mHomePanel);
|
|
}
|
|
}
|
|
public static void RunOnUnityThread(Action action)
|
|
{
|
|
// is this right?
|
|
if (unityThread == Thread.CurrentThread.ManagedThreadId)
|
|
{
|
|
action();
|
|
}
|
|
else
|
|
{
|
|
lock (runInUpdate)
|
|
{
|
|
runInUpdate.Enqueue(action);
|
|
}
|
|
}
|
|
}
|
|
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 SettingContoller mSettingContoller;
|
|
public SettingContoller SettingModal
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("SettingModal", ref this.mSettingContoller);
|
|
}
|
|
}
|
|
private FeedbackController mfeedbackController;
|
|
public FeedbackController FeedbackModal
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("FeedbackModal", ref this.mfeedbackController);
|
|
}
|
|
}
|
|
private NewsController mNewsContoller;
|
|
public NewsController NewsModal
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("NewsModal", ref this.mNewsContoller);
|
|
}
|
|
}
|
|
private DownloadController mDownloadModal;
|
|
public DownloadController DownloadModal
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("DownloadModal", ref this.mDownloadModal);
|
|
}
|
|
}
|
|
|
|
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 RaceAlertController mRaceAlertPanel;
|
|
public RaceAlertController RaceAlertPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelNewInstance<RaceAlertController>("RaceAlertPanel");
|
|
}
|
|
}
|
|
|
|
private RaceAlertController mRaceAlertBandPanel;
|
|
public RaceAlertController RaceAlertBandPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelNewInstance<RaceAlertController>("RaceAlertBandPanel");
|
|
}
|
|
}
|
|
|
|
private EditUserController mEditUserController;
|
|
public EditUserController EditUserPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("EditUserPanel", ref this.mEditUserController);
|
|
}
|
|
}
|
|
|
|
public static void SetModalPanel(PFUIPanel p)
|
|
{
|
|
UIManager.Instance.ModalsPanel = p;
|
|
}
|
|
#if UNITY_ANDROID || UNITY_IOS
|
|
private ResultListPanelController mResultListController;
|
|
public ResultListPanelController ResultListPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("ResultListPanel", ref this.mResultListController);
|
|
}
|
|
}
|
|
public static void ShowResultListPanel()
|
|
{
|
|
Debug.Log(UIManager.Instance.MainPanel);
|
|
UIManager.Show(UIManager.Instance.ResultListPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
#endif
|
|
/*比赛首页*/
|
|
private RaceHomeScript mRaceHomeScript;
|
|
public RaceHomeScript RaceHomePanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RaceHomePanel", ref this.mRaceHomeScript);
|
|
}
|
|
}
|
|
public static void ShowRaceHomePanel(bool fromRaceList = false)
|
|
{
|
|
if (fromRaceList)
|
|
{
|
|
UIManager.PopStack();
|
|
}
|
|
UIManager.Instance.MainPanel.GetComponent<Image>().sprite =
|
|
Resources.Load<Sprite>("Images/Race/RACE-BG");
|
|
UIManager.Show(UIManager.Instance.RaceHomePanel, UIManager.Instance.MainPanel);
|
|
}
|
|
/*比赛首页*/
|
|
/*比赛列表*/
|
|
private RaceListScript mRaceListScript;
|
|
public RaceListScript RaceListPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RaceListPanel", ref this.mRaceListScript);
|
|
}
|
|
}
|
|
public static void ShowRaceListPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.RaceListPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
/*比赛列表*/
|
|
/*比赛列表*/
|
|
private DownloadWorkoutsController mDownloadWorkoutsController;
|
|
public DownloadWorkoutsController DownloadWorkoutsModal
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("DownloadWorkoutsModal", ref this.mDownloadWorkoutsController);
|
|
}
|
|
}
|
|
public static void ShowDownloadWorkoutsPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.DownloadWorkoutsModal, null, true);
|
|
//UIManager.Show(UIManager.Instance.RaceListPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void CloseConfirm3()
|
|
{
|
|
if (UIManager.Instance.confirm3 != null)
|
|
{
|
|
UIManager.Instance.confirm3.Close();
|
|
}
|
|
}
|
|
|
|
/*比赛列表*/
|
|
/*划船机页面*/
|
|
//自由滑
|
|
private RowerHomeScript mRowerHomeScript;
|
|
public RowerHomeScript RowerHomeScript
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RowerPanel", ref this.mRowerHomeScript);
|
|
}
|
|
}
|
|
public static void ShowRowerPanel()
|
|
{
|
|
App.IsRowerMode = true;
|
|
// App.MainDeviceAdapter.ClearDevice();
|
|
//#if UNITY_ANDROID || UNITY_IOS
|
|
// App.MainDeviceAdapter.StartScan();
|
|
//#endif
|
|
stack.Clear();
|
|
UIManager.Show(UIManager.Instance.RowerHomeScript, UIManager.Instance.MainPanel);
|
|
}
|
|
//结束页
|
|
private RowerWelldone mRowerWelldone;
|
|
public RowerWelldone RowerWelldone
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RowerWelldone", ref this.mRowerWelldone);
|
|
}
|
|
}
|
|
public static void ShowRowerWelldone(RowerRecordModel model)
|
|
{
|
|
Debug.Log("進入welldone");
|
|
UIManager.Show(UIManager.Instance.RowerWelldone, null, true);
|
|
if (UIManager.Instance.RowerWelldone)
|
|
{
|
|
UIManager.Instance.RowerWelldone.Initial(model);
|
|
}
|
|
}
|
|
//结果页
|
|
private RowerResult mRowerResult;
|
|
public RowerResult RowerResult
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RowerResult", ref this.mRowerResult);
|
|
}
|
|
}
|
|
public static void ShowRowerResult(string id)
|
|
{
|
|
UIManager.Show(UIManager.Instance.RowerResult, null, true);
|
|
if (UIManager.Instance.RowerResult)
|
|
{
|
|
UIManager.Instance.RowerResult.Initial(id);
|
|
}
|
|
}
|
|
private RowerSelector mRowerSelector;
|
|
public RowerSelector RowerSelector
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RowerSelector", ref this.mRowerSelector);
|
|
}
|
|
}
|
|
public static void ShowRowerSelector()
|
|
{
|
|
Debug.Log("进入Rower");
|
|
UIManager.Show(UIManager.Instance.RowerSelector, null, true);
|
|
}
|
|
/*划船机页面*/
|
|
#region 新版路线页面
|
|
private NewRouteOverviewController mNewRouteOverviewController;
|
|
public NewRouteOverviewController NewRouteOverviewPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("NewRouteOverviewPanel", ref this.mNewRouteOverviewController);
|
|
}
|
|
}
|
|
public static void ShowNewRouteOverviewPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.NewRouteOverviewPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
private NewRouteDetailController mNewRouteDetailController;
|
|
public NewRouteDetailController NewRouteDetailPanel
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("NewRouteDetailPanel", ref this.mNewRouteDetailController);
|
|
}
|
|
}
|
|
public static void ShowNewRouteDetailPanel(MapRouteAreaItem area)
|
|
{
|
|
UIManager.Instance.NewRouteDetailPanel
|
|
.GetComponent<NewRouteDetailController>().Initial(area);
|
|
UIManager.Show(UIManager.Instance.NewRouteDetailPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
#endregion
|
|
private CountDownAnimation mCountDownAnimation;
|
|
public CountDownAnimation CountDownAnimation
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("CountDown", ref this.mCountDownAnimation);
|
|
}
|
|
}
|
|
public static void ShowCountDownAnimation(UnityAction action, UnityAction action2 = null)
|
|
{
|
|
UIManager.Show(UIManager.Instance.CountDownAnimation, null, true);
|
|
UIManager.Instance.CountDownAnimation.StartTime(action,action2);
|
|
}
|
|
//安卓下载页
|
|
private AndroidUpdate mAndroidUpdate;
|
|
public AndroidUpdate AndroidUpdate
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("AndroidUpdate", ref this.mAndroidUpdate);
|
|
}
|
|
}
|
|
public static void ShowAndroidUpdate(JObject jo)
|
|
{
|
|
UIManager.Show(UIManager.Instance.AndroidUpdate, null, true);
|
|
UIManager.Instance.AndroidUpdate.StartDownload(jo);
|
|
}
|
|
#region 比赛点击弹窗
|
|
private RaceModalScript mRaceModalScript;
|
|
public RaceModalScript RaceDetailModal
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("RaceDetailModal", ref this.mRaceModalScript);
|
|
}
|
|
}
|
|
public static void ShowRaceDetailModal(Transform parent,MapCompetition mapCompetition)
|
|
{
|
|
UIManager.Show(UIManager.Instance.RaceDetailModal, null, true);
|
|
UIManager.Instance.RaceDetailModal.transform.SetAsFirstSibling();
|
|
UIManager.Instance.mRaceModalScript.Initial(parent, mapCompetition);
|
|
//UIManager.Show(UIManager.Instance.RaceListPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
#endregion
|
|
|
|
#region
|
|
private StartRideModal mStartRideModal;
|
|
public StartRideModal StartRideModalObj
|
|
{
|
|
get
|
|
{
|
|
return this.GetPanelInstance("StartRideModal", ref this.mStartRideModal);
|
|
}
|
|
}
|
|
public static void ShowStartRideModal(MapRoute map)
|
|
{
|
|
UIManager.Instance.StartRideModalObj.GetComponent<StartRideModal>().Initial(map);
|
|
UIManager.Show(UIManager.Instance.StartRideModalObj, null, true);
|
|
}
|
|
#endregion
|
|
private PFUIPanel mModalsPanel;
|
|
public PFUIPanel ModalsPanel
|
|
{
|
|
get
|
|
{
|
|
return this.mModalsPanel;
|
|
}
|
|
set
|
|
{
|
|
this.mModalsPanel = value;
|
|
}
|
|
}
|
|
|
|
|
|
public static UIManager Instance;
|
|
|
|
private static Stack<PFUIPanel> stack;
|
|
public static void PushHome()
|
|
{
|
|
stack.Clear();
|
|
stack.Push(UIManager.Instance.HomePanel);
|
|
}
|
|
public static int unityThread;
|
|
static public Queue<Action> runInUpdate = new Queue<Action>();
|
|
private void Awake()
|
|
{
|
|
UIManager.Instance = this;
|
|
unityThread = Thread.CurrentThread.ManagedThreadId;
|
|
stack = new Stack<PFUIPanel>();
|
|
loginRegOptions = new LoginRegOptions();
|
|
var userInfosJson = PlayerPrefs.GetString("UserInfos");
|
|
userInfos = JsonConvert.DeserializeObject<List<QUserInfo>>(userInfosJson);
|
|
if (userInfos == null) userInfos = new List<QUserInfo>();
|
|
|
|
var settingsJson = PlayerPrefs.GetString("Settings");
|
|
settings = JsonConvert.DeserializeObject<Settings>(settingsJson);
|
|
if (settings == null) settings = new Settings();
|
|
|
|
userInfoIndex = PlayerPrefs.GetInt("UserInfoIndex");
|
|
collectDict = new Dictionary<bool, Sprite> {
|
|
{ false,Resources.Load<Sprite>("Images/p-4灰")},
|
|
{ true,Resources.Load<Sprite>("Images/p-4")},
|
|
};
|
|
//var a = Resources.Load<TextAsset>("UI/simpleCountry");
|
|
//var clist = JsonConvert.DeserializeObject<List<CountryInfo>>(a.text);
|
|
|
|
if (_now == null)
|
|
{
|
|
Debug.Log(123);
|
|
InitNow();
|
|
}
|
|
EventQueueSystem.AddListener<CompetitonStartMessageEvent>(CompetitonStartHandler);
|
|
|
|
}
|
|
//首页消息通知
|
|
|
|
//比赛即将开始消息提醒
|
|
private void CompetitonStartHandler(CompetitonStartMessageEvent e)
|
|
{
|
|
if (App.CurrentScene.Equals("Ride"))
|
|
{
|
|
var mRaceAlertPanel = ShowRaceAlertPanel();
|
|
if (mRaceAlertPanel != null)
|
|
{
|
|
mRaceAlertPanel.Set(e.StartTime.ToLocalTime(), Now.GetDateTime(), e.title, e.SceneName, e.competitionId, e.routeId);
|
|
}
|
|
}
|
|
else if (App.CurrentScene.Equals("Main"))
|
|
{
|
|
var raceAlertBandPanel = ShowRaceAlertBanelPanel();
|
|
if (raceAlertBandPanel != null)
|
|
{
|
|
raceAlertBandPanel.Set(e.StartTime.ToLocalTime(), Now.GetDateTime(), e.title, e.SceneName, e.competitionId, e.routeId);
|
|
}
|
|
}
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
while (runInUpdate.Count > 0)
|
|
{
|
|
Action action = null;
|
|
lock (runInUpdate)
|
|
{
|
|
if (runInUpdate.Count > 0)
|
|
action = runInUpdate.Dequeue();
|
|
}
|
|
action?.Invoke();
|
|
}
|
|
}
|
|
//重新查询已经参赛列表
|
|
public static void UpdateJoinCompetition()
|
|
{
|
|
try
|
|
{
|
|
if (App.CurrentUser != null)
|
|
{
|
|
var api = ConfigHelper.mapCompetitionApi;
|
|
var s = api.GetMyCompetitionList();
|
|
App.JoinedCompetitionList = s.data;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
//通知用户当前最近的一场比赛开始
|
|
public static void SendCompetitionStartMessage(string sceneName)
|
|
{
|
|
if (App.JoinedCompetitionList != null)
|
|
{
|
|
foreach (var item in App.JoinedCompetitionList)
|
|
{
|
|
var onStart = (item.StartTime.ToLocalTime() - Now.GetDateTime()).TotalMinutes <= 5 && (item.StartTime.ToLocalTime() - Now.GetDateTime()).TotalMinutes >= 0;
|
|
var notify = App.CompetitionIdList.Contains(item.Id);
|
|
|
|
if (onStart && !notify)
|
|
{
|
|
EventQueueSystem.QueueEventOnce(new CompetitonStartMessageEvent(item.Title, item.Id, item.RouteId, item.StartTime.ToLocalTime(), sceneName),"CompetitionAlert"+item.Id.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private T GetPanelNewInstance<T>(string prefabName)
|
|
{
|
|
T internalComponent = default(T);
|
|
{
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/" + prefabName);
|
|
#else
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/Mobile/" + prefabName);
|
|
#endif
|
|
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 GetPanelInstance<T>(string prefabName, ref T internalComponent)
|
|
{
|
|
if (internalComponent == null)
|
|
{
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/" + prefabName);
|
|
#else
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/Mobile/" + prefabName);
|
|
#endif
|
|
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)
|
|
{
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Common/" + prefabName);
|
|
#else
|
|
UnityEngine.Object @object = Resources.Load("UI/Prefab/Common/Mobile/" + prefabName);
|
|
#endif
|
|
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;
|
|
private static PFUIPanel currentPanel = null;
|
|
public static void Show(PFUIPanel panelToShow, PFUIPanel parent = null, bool modal = false)
|
|
{
|
|
if (UIManager.Instance == null || panelToShow == null)
|
|
{
|
|
return;
|
|
}
|
|
if (parent == UIManager.Instance.MainPanel)
|
|
{
|
|
App.currentPageIsHome = panelToShow.Equals(UIManager.Instance.HomePanel);
|
|
}
|
|
|
|
if (modal)
|
|
{
|
|
parent = UIManager.Instance.ModalsPanel;
|
|
}
|
|
else
|
|
{
|
|
var root = UIManager.Instance.Root;
|
|
for (int i = 0; i < root.transform.childCount; i++)
|
|
{
|
|
var panel1 = root.transform.GetChild(i).GetComponent<PFUIPanel>();
|
|
if (panel1 != null)
|
|
{
|
|
panel1.Close();
|
|
}
|
|
}
|
|
|
|
if (currentPanel != null)
|
|
{
|
|
currentPanel.Close();
|
|
}
|
|
//prePanel = panelToShow;
|
|
prePanel = currentPanel;
|
|
currentPanel = panelToShow;
|
|
if (panelToShow.newNav != null)
|
|
{
|
|
panelToShow.newNav.SetExpand(false);
|
|
}
|
|
stack.Push(panelToShow);
|
|
}
|
|
if (parent != null && parent.IsActive() == false)
|
|
{
|
|
parent.gameObject.SetActive(true);
|
|
}
|
|
|
|
//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 !(UNITY_ANDROID || UNITY_IOS)
|
|
//if (modal == false)
|
|
{
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
|
|
}
|
|
#else
|
|
if (modal)
|
|
{
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
|
|
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
|
|
}
|
|
#endif
|
|
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.Instance.UserInfoPanel.Reset();
|
|
UIManager.Show(UIManager.Instance.UserInfoPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void ShowHomePanel()
|
|
{
|
|
App.IsRowerMode = false;
|
|
stack.Clear();
|
|
UIManager.Instance.MainPanel.GetComponent<Image>().sprite =
|
|
Resources.Load<Sprite>("Images/main-bg");
|
|
UIManager.Show(UIManager.Instance.HomePanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static void ShowDevicePanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.DevicePanel, null, true);
|
|
}
|
|
public static void ShowSettingModal()
|
|
{
|
|
UIManager.Show(UIManager.Instance.SettingModal, null, true);
|
|
}
|
|
public static void ShowNewsModal()
|
|
{
|
|
UIManager.Show(UIManager.Instance.NewsModal, null, true);
|
|
}
|
|
public static void ShowDownloadModal()
|
|
{
|
|
UIManager.Show(UIManager.Instance.DownloadModal, null, true);
|
|
}
|
|
public static void ShowFeedBackModal()
|
|
{
|
|
UIManager.Show(UIManager.Instance.FeedbackModal, null, true);
|
|
}
|
|
public static void ShowEditUserPanel()
|
|
{
|
|
UIManager.Show(UIManager.Instance.EditUserPanel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
public static RaceAlertController ShowRaceAlertPanel()
|
|
{
|
|
var raceAlertPanel = UIManager.Instance.RaceAlertPanel;
|
|
UIManager.Show(raceAlertPanel, null, true);
|
|
return raceAlertPanel;
|
|
}
|
|
|
|
public static RaceAlertController ShowRaceAlertBanelPanel()
|
|
{
|
|
var raceAlertBandPanel = UIManager.Instance.RaceAlertBandPanel;
|
|
UIManager.Show(raceAlertBandPanel, null, true);
|
|
return raceAlertBandPanel;
|
|
}
|
|
|
|
//LoadingPf loading;
|
|
public static void ShowLoadingDialogBox()
|
|
{
|
|
if (UIManager.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
//if(UIManager.Instance.loading == null)
|
|
//{
|
|
// UIManager.Instance.loading = UIManager.Instance.GetInstance<LoadingPf>("Loading", ref UIManager.Instance.loading);
|
|
// UIManager.Instance.loading.GetComponent<RectTransform>().position = new Vector3(Screen.width / 2, Screen.height / 2, 0);
|
|
// //var rect = UIManager.Instance.loading.GetComponent<RectTransform>().rect;
|
|
// //rect.width = 154;
|
|
// //rect.height = 111;
|
|
// UIManager.Instance.loading.GetComponent<RectTransform>().sizeDelta = new Vector2(154, 111);
|
|
// //var rrr = UIManager.Instance.loading.GetComponent<RectTransform>();
|
|
|
|
// UIManager.Instance.loading.Initial();
|
|
|
|
// UIManager.Show(UIManager.Instance.loading, null, true);
|
|
//}
|
|
//else
|
|
//{
|
|
// UIManager.Instance.loading.Show();
|
|
//}
|
|
Utils.showLoading(UIManager.Instance.ModalsPanel.gameObject);
|
|
}
|
|
|
|
public static void HideLoadingDialogBox()
|
|
{
|
|
if (UIManager.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
Utils.hideLoading(UIManager.Instance.ModalsPanel.gameObject);
|
|
}
|
|
|
|
|
|
public static void ShowMapListPanel(UnityAction<MapListController> after = null)
|
|
{
|
|
Debug.Log("清空");
|
|
//App.propTextureCache["recordCache"].Clear();
|
|
//UIManager.Instance.MapListPanel.ResetPanel();
|
|
UIManager.Show(UIManager.Instance.MapListPanel, UIManager.Instance.MainPanel);
|
|
if (after != null)
|
|
{
|
|
after(UIManager.Instance.MapListPanel);
|
|
}
|
|
}
|
|
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 PopStack(int count = 1)
|
|
{
|
|
for (int i = 0; i < count && stack.Count>0; i++)
|
|
{
|
|
stack.Pop();
|
|
}
|
|
}
|
|
public static void ShowPrePanel()
|
|
{
|
|
stack.Pop();
|
|
var panel = stack.Pop();
|
|
if (panel == null)
|
|
{
|
|
if (App.pageName == "map")
|
|
{
|
|
ShowBigMapPanel();
|
|
}
|
|
else if (App.pageName == "earth")
|
|
{
|
|
ShowEarthPanel();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UIManager.Show(panel, UIManager.Instance.MainPanel);
|
|
}
|
|
|
|
//if (prePanel.name.Contains("EditUserPanel"))
|
|
//{
|
|
// UIManager.Show(UIManager.Instance.HomePanel, UIManager.Instance.MainPanel);
|
|
//}
|
|
//else
|
|
//{
|
|
// UIManager.Show(prePanel, UIManager.Instance.MainPanel);
|
|
//}
|
|
}
|
|
public static void ShowBigMapPanel(double lat = 0, double lon = 0)
|
|
{
|
|
UIManager.Instance.MainPanel.gameObject.SetActive(false);
|
|
#if UNITY_ANDROID || UNITY_IOS
|
|
var obj = Resources.Load("UI/Prefab/Panel/Mobile/BigMapPanel");
|
|
#else
|
|
var obj = Resources.Load("UI/Prefab/Panel/BigMapPanel");
|
|
#endif
|
|
//var root = UIManager.Instance.MainPanel.transform.parent.parent;
|
|
var bigMap = (GameObject)Instantiate(obj, UIManager.Instance.Root.transform);
|
|
bigMap.GetComponent<BigMapController>().Show(lat, lon);
|
|
stack.Push(null);
|
|
App.pageName = "map";
|
|
//prePanel = bigMap.GetComponent<PFUIPanel>();
|
|
}
|
|
|
|
static GameObject earthPanel = null;
|
|
public static void ShowEarthPanel(double lat = 0, double lon = 0)
|
|
{
|
|
if (UIManager.Instance.MainPanel != null)
|
|
{
|
|
UIManager.Instance.MainPanel.gameObject.SetActive(false);
|
|
}
|
|
if (earthPanel == null)
|
|
{
|
|
#if (UNITY_ANDROID || UNITY_IOS)
|
|
var obj = Resources.Load("UI/Prefab/Panel/Mobile/EarthPanel");
|
|
#else
|
|
var obj = Resources.Load("UI/Prefab/Panel/EarthPanel");
|
|
#endif
|
|
//var root = UIManager.Instance.MainPanel.transform.parent.parent;
|
|
earthPanel = (GameObject)Instantiate(obj, UIManager.Instance.Root.transform);
|
|
}
|
|
stack.Push(null);
|
|
App.pageName = "earth";
|
|
earthPanel.GetComponent<EarthController>().Show(lat, lon);
|
|
}
|
|
|
|
static Texture2D cursor;
|
|
static AudioClip buttonClip;
|
|
public static void RemoveEvent(GameObject gameObject)
|
|
{
|
|
EventTrigger et = gameObject.GetComponent<EventTrigger>();
|
|
if (et == null) return;
|
|
et.triggers.RemoveAll(x => true);
|
|
}
|
|
public static void AddEvent(GameObject gameObject, EventTriggerType eventTriggerType, UnityAction<BaseEventData> call)
|
|
{
|
|
EventTrigger et = gameObject.GetComponent<EventTrigger>();
|
|
EventTrigger.Entry pointerEvent = null;
|
|
if (et == null)
|
|
{
|
|
et = gameObject.AddComponent<EventTrigger>();
|
|
}
|
|
foreach (EventTrigger.Entry entry2 in et.triggers)
|
|
{
|
|
if(entry2.eventID == eventTriggerType)
|
|
{
|
|
pointerEvent = entry2;
|
|
break;
|
|
}
|
|
}
|
|
if (pointerEvent == null)
|
|
{
|
|
pointerEvent = new EventTrigger.Entry();
|
|
pointerEvent.eventID = eventTriggerType;
|
|
et.triggers.Add(pointerEvent);
|
|
}
|
|
//pointerEvent.callback.RemoveAllListeners();
|
|
|
|
pointerEvent.callback.AddListener((e)=> {
|
|
if (gameObject == null || gameObject.activeInHierarchy == false) return;
|
|
var btn = gameObject.GetComponent<Button>();
|
|
if(btn != null && btn.enabled == false)
|
|
{
|
|
return;
|
|
}
|
|
//if (eventTriggerType == EventTriggerType.PointerClick)
|
|
//{
|
|
// var audioSource = gameObject.GetComponent<AudioSource>();
|
|
// if (audioSource != null)
|
|
// audioSource.PlayOneShot(buttonClip);
|
|
//}
|
|
call(e);
|
|
});
|
|
|
|
|
|
if (eventTriggerType == EventTriggerType.PointerClick)
|
|
{
|
|
//设置光标
|
|
if (cursor == null)
|
|
{
|
|
cursor = Resources.Load<Texture2D>("Images/PointerButtonHover");
|
|
}
|
|
////设置点击音效
|
|
//if (buttonClip == null)
|
|
//{
|
|
// buttonClip = Resources.Load<AudioClip>("audio/高科技UI点击触控警告提示反馈APP菜单UI-很酷的应用程序_爱给网_aigei_com");
|
|
//}
|
|
//var audioSource = gameObject.GetComponent<AudioSource>();
|
|
//if (audioSource == null)
|
|
//{
|
|
// audioSource = gameObject.AddComponent<AudioSource>();
|
|
//}
|
|
//audioSource.volume = 0.5f;
|
|
|
|
UIManager.AddEvent(gameObject, EventTriggerType.PointerEnter, (e) =>
|
|
{
|
|
//if (!gameObject.activeInHierarchy) return;
|
|
Cursor.SetCursor(cursor, Vector2.zero, CursorMode.Auto);
|
|
});
|
|
UIManager.AddEvent(gameObject, EventTriggerType.PointerUp, (e) =>
|
|
{
|
|
//if (!gameObject.activeInHierarchy) return;
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
});
|
|
UIManager.AddEvent(gameObject, EventTriggerType.PointerExit, (e) =>
|
|
{
|
|
//if (!gameObject.activeInHierarchy) return;
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
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 < UIManager.Instance.ModalsPanel.transform.childCount; i++)
|
|
{
|
|
var obj = UIManager.Instance.ModalsPanel.transform.GetChild(UIManager.Instance.ModalsPanel.transform.childCount - 1);
|
|
obj.gameObject.SetActive(false);
|
|
//DestroyImmediate(obj.gameObject);
|
|
}
|
|
}
|
|
|
|
AlertV1 alert = null;
|
|
public static void ShowAlert(string title,string msg)
|
|
{
|
|
if (UIManager.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (UIManager.Instance.alert == null)
|
|
{
|
|
UIManager.Instance.alert = UIManager.Instance.GetInstance<AlertV1>("Alert", ref UIManager.Instance.alert);
|
|
UIManager.Instance.alert.Set(title,msg);
|
|
UIManager.Show(UIManager.Instance.alert, null, true);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.alert.Show();
|
|
UIManager.Instance.alert.Set(title, msg);
|
|
}
|
|
}
|
|
|
|
Confirm confirm = null;
|
|
public static void ShowConfirm(string title, string content, UnityAction action,int type = 2,UnityAction cancel = null)
|
|
{
|
|
|
|
if (UIManager.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
title = App.GetLocalString(title);
|
|
content = App.GetLocalString(content);
|
|
|
|
if (UIManager.Instance.confirm == null)
|
|
{
|
|
UIManager.Instance.confirm = UIManager.Instance.GetInstance<Confirm>("Confirm", ref UIManager.Instance.confirm);
|
|
UIManager.Show(UIManager.Instance.confirm, null, true);
|
|
UIManager.Instance.confirm.Set(title, content, action, cancel);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.confirm.Show();
|
|
UIManager.Instance.confirm.Set(title, content, action, cancel);
|
|
}
|
|
UIManager.Instance.confirm.SetType(type);
|
|
}
|
|
public static void CloseConfirm()
|
|
{
|
|
if (UIManager.Instance.confirm != null)
|
|
{
|
|
UIManager.Instance.confirm.Close();
|
|
}
|
|
}
|
|
public static void ShowConfirm3(string title, string content, UnityAction action1, UnityAction action2,UnityAction action3)
|
|
{
|
|
if (UIManager.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
if (UIManager.Instance.confirm3 == null)
|
|
{
|
|
UIManager.Instance.confirm3 = UIManager.Instance.GetInstance<Confirm3>("Confirm3", ref UIManager.Instance.confirm3);
|
|
UIManager.Show(UIManager.Instance.confirm3, null, true);
|
|
UIManager.Instance.confirm3.Set(title, content, action1, action2, action3);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.confirm3.Show();
|
|
UIManager.Instance.confirm3.Set(title, content, action1, action2, action3);
|
|
}
|
|
}
|
|
public LoginRegOptions loginRegOptions { get; private set; }
|
|
private List<QUserInfo> _userInfos;
|
|
public List<QUserInfo> userInfos
|
|
{
|
|
get
|
|
{
|
|
return _userInfos;
|
|
}
|
|
set
|
|
{
|
|
_userInfos = value;
|
|
PlayerPrefs.SetString("UserInfos", JsonConvert.SerializeObject(value));
|
|
}
|
|
}
|
|
public Dictionary<bool, Sprite> collectDict { get; private set; }
|
|
private int _userInfoIndex;
|
|
public int userInfoIndex
|
|
{
|
|
get
|
|
{
|
|
return _userInfoIndex;
|
|
}
|
|
set
|
|
{
|
|
_userInfoIndex = value;
|
|
PlayerPrefs.SetInt("UserInfoIndex", value);
|
|
}
|
|
}
|
|
private Settings _settings;
|
|
public Settings settings
|
|
{
|
|
get
|
|
{
|
|
return _settings;
|
|
}
|
|
set
|
|
{
|
|
_settings = value;
|
|
PlayerPrefs.SetString("Settings", JsonConvert.SerializeObject(value));
|
|
}
|
|
}
|
|
|
|
private static CustomDateTime _now;
|
|
public static CustomDateTime Now
|
|
{
|
|
get
|
|
{
|
|
return _now;
|
|
}
|
|
}
|
|
|
|
Confirm3 confirm3 = null;
|
|
|
|
public static async void InitNow()
|
|
{
|
|
var now = await ConfigHelper.userApi.GetNow();
|
|
_now = new CustomDateTime(now);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
UIManager.Instance = null;
|
|
EventQueueSystem.ClearQueue();
|
|
Resources.UnloadUnusedAssets();
|
|
GC.Collect();
|
|
}
|
|
public static void SwitchAccount()
|
|
{
|
|
ShowConfirm("Logout", "Do you want to log out and change accounts?", () =>
|
|
{
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
SceneManager.LoadScene("Login");
|
|
#else
|
|
SceneManager.LoadScene("Login-Mobile");
|
|
#endif
|
|
CloseConfirm();
|
|
}, 2);
|
|
}
|
|
}
|