220 lines
6.4 KiB
C#
220 lines
6.4 KiB
C#
|
using System;
|
|||
|
using Thousandto.Code.Logic;
|
|||
|
using Thousandto.Core.Asset;
|
|||
|
using Thousandto.Core.Base;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.Gonbest.MagicCube;
|
|||
|
|
|||
|
namespace Thousandto.Code.Center
|
|||
|
{
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 游戏中心脚本
|
|||
|
/// </summary>
|
|||
|
public class GameCenterScript : MonoBehaviour
|
|||
|
{
|
|||
|
private static bool _isCreated = false;
|
|||
|
private static float _pauseTime = 0;
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
public bool ReloadAllLua = false;
|
|||
|
#endif
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Debug.Log("GameCenterScript Awake");
|
|||
|
Application.quitting -= DoApplicationQuit;
|
|||
|
Application.quitting += DoApplicationQuit;
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
Debug.Log("GameCenterScript Start");
|
|||
|
ScreenSystem.SetDesignContentScale();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//laucher端调用,设置游戏的启动参数
|
|||
|
public void GameStart(string lang, bool isStream, int buildType)
|
|||
|
{
|
|||
|
Debug.Log("GameStart lang:" + (lang == null ? "null" : lang));
|
|||
|
|
|||
|
if (!string.IsNullOrEmpty(lang))
|
|||
|
{
|
|||
|
LanguageSystem.SetPackageLang(lang);
|
|||
|
}
|
|||
|
|
|||
|
if (PathUtils.IsStreaming())
|
|||
|
{
|
|||
|
AnimationClipManager.UseAsynLoadAnimClip = true;
|
|||
|
AnimationClipManager.SyncLoadAnimHandler = null;
|
|||
|
}
|
|||
|
#if UNITY_EDITOR && !FUNCELL_LAUNCHER
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
AnimationClipManager.SyncLoadAnimHandler = x => {
|
|||
|
|
|||
|
var ani = UnityEditor.AssetDatabase.LoadAssetAtPath<AnimationClip>(x);
|
|||
|
//Debug.LogError("AnimationClipManager.SyncLoadAnimHandler::" + x + "::" + (ani == null ? "NULL" : ani.ToString()));
|
|||
|
return ani;
|
|||
|
};
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
if (!_isCreated)
|
|||
|
{
|
|||
|
name = "[MainEntry]";
|
|||
|
DontDestroyOnLoad(gameObject);
|
|||
|
_isCreated = true;
|
|||
|
GameCenter.CreateSystem();
|
|||
|
GameCenter.Initialize();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Destroy(gameObject);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
if (gameObject.GetComponent<GameExtentScript>() == null)
|
|||
|
{
|
|||
|
gameObject.AddComponent<GameExtentScript>();
|
|||
|
} */
|
|||
|
}
|
|||
|
|
|||
|
//Launcher端调用,直接进入登录状态
|
|||
|
public void ChangeToLogin()
|
|||
|
{
|
|||
|
if (_isCreated)
|
|||
|
{
|
|||
|
if (GameCenter.GameStateSystem != null)
|
|||
|
GameCenter.GameStateSystem.ChangeState((int)GameStateId.Login);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private int test = 0;
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
//Thousandto.Plugins.Common.Networker.TestMessage = TestMessage;
|
|||
|
|
|||
|
if (_isCreated)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
GameCenter.Update(Time.deltaTime);
|
|||
|
|
|||
|
//if (Input.GetKeyDown(KeyCode.Alpha0))
|
|||
|
//{
|
|||
|
// GameCenter.PushFixEvent(Global.LogicEventDefine.EID_EVENT_HIDE_CURRENT_FORM);
|
|||
|
//}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Debug.LogException(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void FixedUpdate()
|
|||
|
{
|
|||
|
if (_isCreated && !GameCenter.ClientGMSystem.PauseGameCenterUpdate)
|
|||
|
{
|
|||
|
GameCenter.FixedUpdate(Time.deltaTime);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void LateUpdate()
|
|||
|
{
|
|||
|
if (_isCreated && !GameCenter.ClientGMSystem.PauseGameCenterLateUpdate)
|
|||
|
{
|
|||
|
GameCenter.LateUpdate(Time.deltaTime);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnApplicationPause(bool paused)
|
|||
|
{
|
|||
|
if (_isCreated)
|
|||
|
{
|
|||
|
if (!paused)
|
|||
|
{
|
|||
|
ScreenSystem.SetDesignContentScale();
|
|||
|
if (GameCenter.GameStateSystem != null)
|
|||
|
{
|
|||
|
var curState = GameCenter.GameStateSystem.GetCurState();
|
|||
|
if (curState != null)
|
|||
|
{
|
|||
|
if (curState is LoginState)
|
|||
|
{
|
|||
|
//Debug.Log("恢复播放背景音1");
|
|||
|
//后台没播放音乐,才播放游戏背景音乐
|
|||
|
//if (FuncellSDK.Instance.IsMusicPlaying() == false)
|
|||
|
AudioPlayer.PlayMusic(LoginState.GetLoginMusicName());
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//Debug.Log("恢复播放背景音2");
|
|||
|
//后台没播放音乐,才播放游戏背景音乐
|
|||
|
//if (FuncellSDK.Instance.IsMusicPlaying() == false)
|
|||
|
GameCenter.GameSceneSystem.PlayBGMusic();
|
|||
|
|
|||
|
var deltaTimeWhilePauseResume = Time.realtimeSinceStartup - _pauseTime;
|
|||
|
if (deltaTimeWhilePauseResume >= 2 * 60)
|
|||
|
{
|
|||
|
GameCenter.Networker.Disconnect();
|
|||
|
GameCenter.ReconnectSystem.Reconnect();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//Debug.Log("暂停停止背景音!");
|
|||
|
GameCenter.GameSceneSystem.StopBGMusic(true);
|
|||
|
_pauseTime = Time.realtimeSinceStartup;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnApplicationFocus(bool focus)
|
|||
|
{
|
|||
|
if (_isCreated)
|
|||
|
{
|
|||
|
GameCenter.IsFocused = focus;
|
|||
|
GameCenter.PushFixEvent(Global.LogicEventDefine.EID_EVENT_APPFOCUS);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void DoApplicationQuit()
|
|||
|
{
|
|||
|
if (_isCreated)
|
|||
|
{
|
|||
|
GameCenter.Uninitialize();
|
|||
|
GameCenter.ApplicationQuit();
|
|||
|
}
|
|||
|
}
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
//在编辑器状态下,当被选择后的一些图形
|
|||
|
void OnDrawGizmos()
|
|||
|
{
|
|||
|
if (Application.isPlaying)
|
|||
|
{
|
|||
|
Core.Asset.DynamicBoneSystem.SharedInstance.OnGizmos();
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
}
|
|||
|
}
|