备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace com.fpnn
|
||||
{
|
||||
public static partial class ClientEngine
|
||||
{
|
||||
static partial void PlatformInit()
|
||||
{
|
||||
ConnectionMonitor.Instance.Init();
|
||||
//Application.quitting += () => {
|
||||
// ClientEngine.Close();
|
||||
//};
|
||||
}
|
||||
|
||||
static partial void PlatformUninit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionMonitor : Singleton<ConnectionMonitor>
|
||||
{
|
||||
private bool _isPause;
|
||||
private bool _isFocus;
|
||||
private bool _isBackground;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
this._isPause = false;
|
||||
this._isFocus = true;
|
||||
this._isBackground = false;
|
||||
}
|
||||
|
||||
public void Init() { }
|
||||
|
||||
private void CheckInBackground()
|
||||
{
|
||||
if (_isPause && !_isFocus)
|
||||
{
|
||||
if (_isBackground == false)
|
||||
{
|
||||
_isBackground = true;
|
||||
|
||||
#if UNITY_IOS
|
||||
if (ClientEngine.closeConnectionsWhenBackground)
|
||||
{
|
||||
ClientEngine.ChangeForbiddenRegisterConnection(_isBackground);
|
||||
ClientEngine.StopAllConnections();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isBackground)
|
||||
{
|
||||
_isBackground = false;
|
||||
|
||||
#if UNITY_IOS
|
||||
if (ClientEngine.closeConnectionsWhenBackground)
|
||||
{
|
||||
ClientEngine.ChangeForbiddenRegisterConnection(_isBackground);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnApplicationPause(bool pauseStatus)
|
||||
{
|
||||
_isPause = pauseStatus;
|
||||
|
||||
CheckInBackground();
|
||||
}
|
||||
|
||||
void OnApplicationFocus(bool hasFocus)
|
||||
{
|
||||
_isFocus = hasFocus;
|
||||
|
||||
CheckInBackground();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a41e8ca65b9e3415f9a4b0b2407a0aca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace com.fpnn {
|
||||
|
||||
public class Singleton<T> : MonoBehaviour where T : Singleton<T> {
|
||||
|
||||
public static T Instance {
|
||||
get {
|
||||
if (instance == null) {
|
||||
#if UNITY_EDITOR
|
||||
T[] managers = Object.FindObjectsOfType(typeof(T)) as T[];
|
||||
|
||||
if (managers.Length != 0) {
|
||||
if (managers.Length == 1) {
|
||||
instance = managers[0];
|
||||
instance.gameObject.name = typeof(T).Name;
|
||||
return instance;
|
||||
} else {
|
||||
Debug.LogError("Class " + typeof(T).Name + " exists multiple times in violation of singleton pattern. Destroying all copies");
|
||||
|
||||
foreach (T manager in managers) {
|
||||
Destroy(manager.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
var go = new GameObject(typeof(T).Name, typeof(T));
|
||||
instance = go.GetComponent<T>();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
set {
|
||||
instance = value as T;
|
||||
}
|
||||
}
|
||||
|
||||
private static T instance;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69a9d33ada7b746d383d500683ccea60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user