海淀天下城电子沙盘单机版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.1 KiB

4 years ago
using AX.MessageSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AX.DevelopEngine;
using System;
/// <summary>
/// 程序退出管理单例类,需要初始挂载在物体上
/// </summary>
public class QuitApplicationManager : MonoSingleton<QuitApplicationManager> {
#region Variables
private Dictionary<MonoBehaviour, Action> QuitEventDict = new Dictionary<MonoBehaviour, Action>();
private bool isQuit = false;
private Action ToQuitTipAction;
private GUIStyle tipStyle;
private bool isShowGUI = false;
private string guiTip = "";
#endregion
#region Mono
// Use this for initialization
void Start()
{
Instance.Init();
tipStyle = new GUIStyle();
tipStyle.fontSize = 40;
tipStyle.normal.textColor = Color.red;
string filepath = Application.dataPath + @"/xml/AXConfig.xml";
XmlProcess process = new XmlProcess(filepath);
bool smart = false;
bool validity = false;
bool unique = false;
process.GetMode("assets", ref smart, ref unique, ref validity);
if(smart)
{
// SmartController.Instance.Init();
}
else if(validity)
{
ValidityDetection.Instance.Init();
}
else if(unique)
{
UniqueIdentifier.Instance.Init();
}
//默认如果点击x关闭程序时,不想拦截退出事件,可以执行下面方法允许程序直接退出
AddToQuitTipAction(SureQuit);
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
if (isShowGUI)
{
GUI.Label(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 75, 300, 150), guiTip, tipStyle);
}
}
public void OnApplicationQuit()
{
if (!isQuit)
{
Application.CancelQuit();
ActiveToQuitTipAction();
//Debug.LogError("Application cancel quit **************************");
}
}
private void OnDestroy()
{
QuitEventDict.Clear();
QuitEventDict = null;
ToQuitTipAction = null;
}
#endregion
#region Customs
public void Init()
{
}
public void SetGuiTip(string tip, bool flag = true)
{
guiTip = tip;
isShowGUI = flag;
}
public void SureQuit()
{
isQuit = true;
ActiveQuitEvent();
Application.Quit();
// Debug.Log("Application quit");
}
public void AddQuitEvent(MonoBehaviour mono, Action action)
{
if (!QuitEventDict.ContainsKey(mono))
{
QuitEventDict.Add(mono, action);
}
}
public void AddToQuitTipAction(Action action)
{
ToQuitTipAction += action;
}
public void ActiveToQuitTipAction()
{
if (ToQuitTipAction != null)
ToQuitTipAction();
}
private void ActiveQuitEvent()
{
foreach (var pair in QuitEventDict)
{
pair.Value();
}
}
#endregion
}