451 lines
12 KiB
C#
451 lines
12 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace BF
|
||
{
|
||
/// <summary>
|
||
/// 口头约束 各个manager的Create函数只提供给BFMain使用
|
||
/// </summary>
|
||
public class BFMain : MonoSingleton<BFMain>
|
||
{
|
||
List<ManagerBase> managerList;
|
||
// 客户端c#代码版本号,每次发布新包后加1,lua层存在一套代码兼容多版本c#代码
|
||
public const int CLIENT_VERSION = 4;
|
||
// 是否是单机版
|
||
public static bool IsStandAlone = false;
|
||
public static bool IsShenhe = false;
|
||
public static bool IsWhite = false;
|
||
public static bool IsGotServerTime = false;
|
||
public const string FILE_HEAD = "for_file_head";
|
||
public const string FILE_HEAD_BASE64 = "Zm9yX2ZpbGVfaGVhZ";
|
||
public static long ServerTime = 0;
|
||
public static long DifferenceTime = 0;
|
||
public static string ProjectId
|
||
{
|
||
get
|
||
{
|
||
#if UNITY_EDITOR
|
||
return "b13";
|
||
#else
|
||
if (BFPlatform.Identifier == BFPlatform.ANDROID_GP_PACKAGE_NAME_RU)
|
||
{
|
||
return "b13-ru";
|
||
}
|
||
else
|
||
{
|
||
return "b13";
|
||
}
|
||
#endif
|
||
}
|
||
}
|
||
public static string ProjectEnv
|
||
{
|
||
get
|
||
{
|
||
#if UNITY_EDITOR
|
||
// 编辑器
|
||
return "release";
|
||
#else
|
||
// 如果走深度链接启动且有参数,则走深度链接地址
|
||
if (!string.IsNullOrEmpty(DPEnv))
|
||
{
|
||
return DPEnv;
|
||
}
|
||
else
|
||
{
|
||
return "release";
|
||
}
|
||
#endif
|
||
}
|
||
}
|
||
public static bool ForceEnv
|
||
{
|
||
get
|
||
{
|
||
return DPForceEnv;
|
||
}
|
||
}
|
||
|
||
// 深度链接参数
|
||
public static string DPEntrance = string.Empty; // 内外网
|
||
public static bool DPIsLan = false; // 是否为内网
|
||
public static string DPEnv = string.Empty; // env
|
||
public static bool DPSupportGM = false; // 正式环境下是否开启GM
|
||
public static bool DPSupportLog = false; // 正式环境下是否打印日志
|
||
public static string DPPackageName = string.Empty; // 模拟包名
|
||
public static bool DPForceEnv = false; // 是否强制设置env
|
||
|
||
protected override void Init()
|
||
{
|
||
base.Init();
|
||
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
||
#if !UNITY_EDITOR
|
||
BestHTTP.HTTPManager.Logger.Level = BestHTTP.Logger.Loglevels.None; // 避免真机上BestHTTP的异常导致的崩溃
|
||
#endif
|
||
InitMgrs();
|
||
StartGame();
|
||
}
|
||
|
||
void InitMgrs()
|
||
{
|
||
managerList = new List<ManagerBase>();
|
||
}
|
||
|
||
public void StartGame()
|
||
{
|
||
#if UNITY_EDITOR
|
||
var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
||
if (Application.isPlaying && sceneName.CompareTo("enter_scene") == 0)
|
||
{
|
||
GameLaunchMgr.LaunchGame();
|
||
}
|
||
#else
|
||
GameLaunchMgr.LaunchGame();
|
||
#endif
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
var count = managerList.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
managerList[i].Update();
|
||
}
|
||
}
|
||
|
||
void LateUpdate()
|
||
{
|
||
var count = managerList.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
managerList[i].LateUpdate();
|
||
}
|
||
}
|
||
|
||
void OnDestroy()
|
||
{
|
||
var count = managerList.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
managerList[i].Destroy();
|
||
}
|
||
managerList.Clear();
|
||
}
|
||
|
||
void OnApplicationPause(bool pause)
|
||
{
|
||
if (luaMgr != null)
|
||
{
|
||
luaMgr.OnApplicationPause(pause);
|
||
}
|
||
}
|
||
|
||
void OnApplicationFocus(bool focus)
|
||
{
|
||
if (luaMgr != null)
|
||
{
|
||
luaMgr.OnApplicationFocus(focus);
|
||
}
|
||
}
|
||
|
||
void OnApplicationQuit()
|
||
{
|
||
if (luaMgr != null)
|
||
{
|
||
luaMgr.OnApplicationQuit();
|
||
}
|
||
Destroy();
|
||
}
|
||
|
||
public void Destroy()
|
||
{
|
||
Destroy(gameObject);
|
||
}
|
||
|
||
GameLaunchManager gameLaunchMgr;
|
||
public GameLaunchManager GameLaunchMgr
|
||
{
|
||
get
|
||
{
|
||
if (gameLaunchMgr == null)
|
||
{
|
||
gameLaunchMgr = GameLaunchManager.Create();
|
||
gameLaunchMgr.Init();
|
||
managerList.Add(gameLaunchMgr);
|
||
}
|
||
return gameLaunchMgr;
|
||
}
|
||
}
|
||
|
||
LuaManager luaMgr;
|
||
public LuaManager LuaMgr
|
||
{
|
||
get
|
||
{
|
||
if (luaMgr == null)
|
||
{
|
||
luaMgr = LuaManager.Create();
|
||
luaMgr.SetMono(this);
|
||
luaMgr.Init();
|
||
managerList.Add(luaMgr);
|
||
}
|
||
return luaMgr;
|
||
}
|
||
}
|
||
|
||
LoomManager loomMgr;
|
||
public LoomManager LoomMgr
|
||
{
|
||
get
|
||
{
|
||
if (loomMgr == null)
|
||
{
|
||
loomMgr = LoomManager.Create();
|
||
loomMgr.SetMono(this);
|
||
loomMgr.Init();
|
||
managerList.Add(loomMgr);
|
||
}
|
||
return loomMgr;
|
||
}
|
||
}
|
||
|
||
PoolManager poolMgr;
|
||
public PoolManager PoolMgr
|
||
{
|
||
get
|
||
{
|
||
if (poolMgr == null)
|
||
{
|
||
poolMgr = PoolManager.Create();
|
||
managerList.Add(poolMgr);
|
||
}
|
||
return poolMgr;
|
||
}
|
||
}
|
||
|
||
BFTouchManager touchMgr;
|
||
public BFTouchManager TouchMgr
|
||
{
|
||
get
|
||
{
|
||
if (touchMgr == null)
|
||
{
|
||
touchMgr = BFTouchManager.Create();
|
||
managerList.Add(touchMgr);
|
||
}
|
||
return touchMgr;
|
||
}
|
||
}
|
||
|
||
RenderManager renderMgr;
|
||
public RenderManager RenderMgr
|
||
{
|
||
get
|
||
{
|
||
if (renderMgr == null)
|
||
{
|
||
renderMgr = RenderManager.Create();
|
||
renderMgr.SetMono(this);
|
||
managerList.Add(renderMgr);
|
||
}
|
||
return renderMgr;
|
||
}
|
||
}
|
||
|
||
ResourceManager resMgr;
|
||
public ResourceManager ResMgr
|
||
{
|
||
get
|
||
{
|
||
if (resMgr == null)
|
||
{
|
||
resMgr = ResourceManager.Create();
|
||
resMgr.Init();
|
||
managerList.Add(resMgr);
|
||
}
|
||
return resMgr;
|
||
}
|
||
}
|
||
|
||
NetManager netMgr;
|
||
public NetManager NetMgr
|
||
{
|
||
get
|
||
{
|
||
if (netMgr == null)
|
||
{
|
||
netMgr = NetManager.Create();
|
||
managerList.Add(netMgr);
|
||
}
|
||
return netMgr;
|
||
}
|
||
}
|
||
|
||
BFWebRequestManager webRequestMgr;
|
||
public BFWebRequestManager WebRequestMgr
|
||
{
|
||
get
|
||
{
|
||
if (webRequestMgr == null)
|
||
{
|
||
webRequestMgr = BFWebRequestManager.Create();
|
||
managerList.Add(webRequestMgr);
|
||
}
|
||
return webRequestMgr;
|
||
}
|
||
}
|
||
|
||
OneShotManager oneShotManager;
|
||
public OneShotManager OneShotManager
|
||
{
|
||
get
|
||
{
|
||
if (oneShotManager == null)
|
||
{
|
||
oneShotManager = OneShotManager.Create();
|
||
oneShotManager.Init();
|
||
managerList.Add(oneShotManager);
|
||
}
|
||
return oneShotManager;
|
||
}
|
||
}
|
||
|
||
SoundManager soundManager;
|
||
public SoundManager SoundManager
|
||
{
|
||
get
|
||
{
|
||
if (soundManager == null)
|
||
{
|
||
soundManager = SoundManager.Create();
|
||
soundManager.Init();
|
||
managerList.Add(soundManager);
|
||
}
|
||
return soundManager;
|
||
}
|
||
}
|
||
|
||
TaskManager taskMgr;
|
||
public TaskManager TaskMgr
|
||
{
|
||
get
|
||
{
|
||
if (taskMgr == null)
|
||
{
|
||
taskMgr = TaskManager.Create();
|
||
taskMgr.Init();
|
||
taskMgr.SetMono(this);
|
||
managerList.Add(taskMgr);
|
||
}
|
||
return taskMgr;
|
||
}
|
||
}
|
||
|
||
BIReport biReport;
|
||
public BIReport BIReport
|
||
{
|
||
get
|
||
{
|
||
if (biReport == null)
|
||
{
|
||
biReport = BIReport.Create();
|
||
biReport.Init();
|
||
managerList.Add(biReport);
|
||
}
|
||
return biReport;
|
||
}
|
||
}
|
||
|
||
SDKManager sdkMgr;
|
||
public SDKManager SDKMgr
|
||
{
|
||
get
|
||
{
|
||
if (sdkMgr == null)
|
||
{
|
||
sdkMgr = SDKManager.Create();
|
||
sdkMgr.Init();
|
||
managerList.Add(sdkMgr);
|
||
}
|
||
return sdkMgr;
|
||
}
|
||
}
|
||
|
||
// BattleManager battleMgr;
|
||
// public BattleManager BattleMgr
|
||
// {
|
||
// get
|
||
// {
|
||
// if (battleMgr == null)
|
||
// {
|
||
// battleMgr = BattleManager.Create();
|
||
// battleMgr.SetMono(this);
|
||
// battleMgr.Init();
|
||
// managerList.Add(battleMgr);
|
||
// }
|
||
// return battleMgr;
|
||
// }
|
||
// }
|
||
|
||
BFParseClientManager parseClientMgr;
|
||
public BFParseClientManager ParseClientMgr
|
||
{
|
||
get
|
||
{
|
||
if (parseClientMgr == null)
|
||
{
|
||
parseClientMgr = BFParseClientManager.Create();
|
||
parseClientMgr.SetMono(this);
|
||
parseClientMgr.Init();
|
||
managerList.Add(parseClientMgr);
|
||
}
|
||
return parseClientMgr;
|
||
}
|
||
}
|
||
|
||
URPManager urpMgr;
|
||
public URPManager URPMgr
|
||
{
|
||
get
|
||
{
|
||
if (urpMgr == null)
|
||
{
|
||
urpMgr = URPManager.Create();
|
||
urpMgr.Init();
|
||
managerList.Add(urpMgr);
|
||
}
|
||
return urpMgr;
|
||
}
|
||
}
|
||
|
||
public static void SetServerTime(long serverTime)
|
||
{
|
||
ServerTime = serverTime;
|
||
DifferenceTime = Convert.ToInt64(Time.realtimeSinceStartup);
|
||
}
|
||
|
||
public static string ForFree(string str)
|
||
{
|
||
var bytes = System.Text.Encoding.UTF8.GetBytes(str);
|
||
var bytesCount = bytes.Length;
|
||
var index = 0;
|
||
var key = BF.Utils.GetFreeChar();
|
||
var keyLength = key.Length;
|
||
var headLength = FILE_HEAD.Length;
|
||
var newbytes = new byte[bytes.Length + headLength];
|
||
for (int i = 0; i < headLength; i++)
|
||
{
|
||
var headByte = (byte)FILE_HEAD[i];
|
||
newbytes[i] = headByte;
|
||
}
|
||
for (int i = 0; i < bytesCount; i++)
|
||
{
|
||
newbytes[i + headLength] = (byte)(bytes[i] ^ (key[index % keyLength]));
|
||
index++;
|
||
}
|
||
return System.Convert.ToBase64String(newbytes);
|
||
}
|
||
}
|
||
}
|