224 lines
7.0 KiB
C#
224 lines
7.0 KiB
C#
using UnityEngine;
|
||
#if UNITY_IOS && !UNITY_EDITOR
|
||
using System.Runtime.InteropServices;
|
||
#endif
|
||
|
||
namespace BF
|
||
{
|
||
public class GameLaunchManager : ManagerBase
|
||
{
|
||
#if UNITY_IOS && !UNITY_EDITOR
|
||
[DllImport("__Internal")]
|
||
private static extern void IOS_ATTrack();
|
||
#endif
|
||
|
||
public LaunchRequester LaunchRequester { get; private set; }
|
||
public int LaunchTimes { get; private set; }
|
||
public bool LoadedFirstAb = false;
|
||
|
||
GameLaunchProcessorBase currentProcessor;
|
||
|
||
static GameLaunchManager instance;
|
||
|
||
public static GameLaunchManager Create()
|
||
{
|
||
BFLog.LogAssert(instance == null, "This method only allows BFMain to call once");
|
||
instance = new GameLaunchManager();
|
||
return instance;
|
||
}
|
||
|
||
GameLaunchManager() { }
|
||
|
||
public override void SetMono(MonoBehaviour mono)
|
||
{
|
||
base.SetMono(mono);
|
||
}
|
||
|
||
public override void Init()
|
||
{
|
||
LaunchRequester = new LaunchRequester();
|
||
LaunchTimes = 0;
|
||
}
|
||
|
||
public override void Update()
|
||
{
|
||
if (currentProcessor != null)
|
||
{
|
||
currentProcessor.Update();
|
||
}
|
||
}
|
||
|
||
public override void Destroy()
|
||
{
|
||
}
|
||
|
||
/// <summary>
|
||
/// 游戏启动入口
|
||
/// </summary>
|
||
public void LaunchGame()
|
||
{
|
||
#if UNITY_IOS && !UNITY_EDITOR
|
||
IOS_ATTrack();
|
||
#endif
|
||
LaunchTimes++;
|
||
#if USE_AB
|
||
GameLaunchProcessorBase processor = new LaunchSuccProcessor();
|
||
|
||
BFMain.IsStandAlone = false;
|
||
processor = new FixUpProcessor(processor);
|
||
processor = new DownloadUpdateProcessor(processor);
|
||
processor = new CalculateDiffProcessor(processor);
|
||
processor = new OnGetVersionProcessor(processor);
|
||
processor = new RequestVersionProcessor(processor);
|
||
processor = new PreCheckProcessor(processor);
|
||
processor = new FirstABProcessor(processor);
|
||
processor = new PrepareProcessor(processor);
|
||
processor.Process(LaunchRequester);
|
||
#else
|
||
GameLaunchProcessorBase processor = new LaunchSuccProcessor();
|
||
processor = new RequestLoginCenterConfigProcessor(processor);
|
||
processor.Process(LaunchRequester);
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选服拉更新时版本不一致调用,除首包外的资源和lua全部要卸载掉
|
||
/// </summary>
|
||
public void LaunchForLogin(string versionJson)
|
||
{
|
||
LaunchTimes++;
|
||
GameLaunchProcessorBase processor = new LaunchSuccProcessor();
|
||
processor = new FixUpProcessor(processor);
|
||
processor = new DownloadUpdateProcessor(processor);
|
||
processor = new CalculateDiffProcessor(processor);
|
||
processor = new OnGetVersionProcessor(processor);
|
||
|
||
LaunchRequester.SetVersionInfo(versionJson);
|
||
processor.Process(LaunchRequester);
|
||
|
||
BFLog.LogDebug(BFLog.DEBUG_GAME_LAUNCH, "green", "LaunchForLogin " + versionJson);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 游戏过程中踢下线再登陆时版本不一致调用,要卸载掉所有资源和lua,重新把首包加回来
|
||
/// </summary>
|
||
public void LaunchForRelogin(string versionJson)
|
||
{
|
||
LaunchTimes++;
|
||
GameLaunchProcessorBase processor = new LaunchSuccProcessor();
|
||
processor = new FixUpProcessor(processor);
|
||
processor = new DownloadUpdateProcessor(processor);
|
||
processor = new CalculateDiffProcessor(processor);
|
||
processor = new OnGetVersionProcessor(processor);
|
||
processor = new FirstABProcessor(processor);
|
||
|
||
LaunchRequester.SetVersionInfo(versionJson);
|
||
processor.Process(LaunchRequester);
|
||
|
||
BFLog.LogDebug(BFLog.DEBUG_GAME_LAUNCH, "green", "LaunchForRelogin " + versionJson);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切语言调用,不用请求版本
|
||
/// </summary>
|
||
public void LaunchForLanguage(string language)
|
||
{
|
||
LaunchTimes++;
|
||
LaunchRequester.isHotUpdate = true;
|
||
LaunchRequester.versionAbcc = LaunchRequester.persistentAbcc;
|
||
|
||
GameLaunchProcessorBase processor = new LaunchSuccProcessor();
|
||
processor = new FixUpProcessor(processor);
|
||
processor = new DownloadUpdateProcessor(processor);
|
||
processor = new CalculateDiffProcessor(processor);
|
||
processor = new OnGetVersionProcessor(processor);
|
||
processor = new FirstABProcessor(processor);
|
||
|
||
processor.Process(LaunchRequester);
|
||
BFLog.LogDebug(BFLog.DEBUG_GAME_LAUNCH, "green", "LaunchForLanguage " + language);
|
||
}
|
||
|
||
public bool IsNetworkReachability()
|
||
{
|
||
return Application.internetReachability != NetworkReachability.NotReachable;
|
||
}
|
||
|
||
public bool IsWifi()
|
||
{
|
||
return Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork;
|
||
}
|
||
|
||
public void SetCurrentProcessor(GameLaunchProcessorBase processor)
|
||
{
|
||
BFLog.LogDebug(BFLog.DEBUG_GAME_LAUNCH, "green", "current processor " + processor);
|
||
currentProcessor = processor;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否是白名单版本
|
||
/// </summary>
|
||
public bool IsVersionWhiteList()
|
||
{
|
||
if (BFPlatform.IsPublishChannel())
|
||
{
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
#if SKIP_VERSION
|
||
return true;
|
||
#else
|
||
return false;
|
||
#endif
|
||
}
|
||
}
|
||
|
||
public AssetBundle GetFirstAB()
|
||
{
|
||
return LaunchRequester.firstAb;
|
||
}
|
||
|
||
public string GetCurrentVersion()
|
||
{
|
||
if (LaunchRequester.persistentAbcc != null)
|
||
{
|
||
return LaunchRequester.persistentAbcc.version;
|
||
}
|
||
#if UNITY_EDITOR && !USE_AB
|
||
return "0.1.0";
|
||
#else
|
||
return "";
|
||
#endif
|
||
}
|
||
|
||
public void QuitGame()
|
||
{
|
||
Application.Quit();
|
||
}
|
||
|
||
public static string ForJustice(string str)
|
||
{
|
||
if (!str.StartsWith(BFMain.FILE_HEAD_BASE64))
|
||
{
|
||
return str;
|
||
}
|
||
var bytes = System.Convert.FromBase64String(str);
|
||
var index = 0;
|
||
var headCount = BFMain.FILE_HEAD.Length;
|
||
var bytesCount = bytes.Length;
|
||
var key = BF.Utils.GetFreeChar();
|
||
var keyLength = key.Length;
|
||
var realCount = bytesCount - headCount;
|
||
for (int i = 0; i < realCount; i++)
|
||
{
|
||
bytes[i] = (byte)(bytes[i + headCount] ^ (key[index % key.Length]));
|
||
index++;
|
||
if (index >= keyLength) {
|
||
index = 0;
|
||
}
|
||
}
|
||
return System.Text.Encoding.UTF8.GetString(bytes, 0, realCount);
|
||
}
|
||
}
|
||
}
|