CTT/Unity/Assets/Hotfix/Init.cs

87 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Linq;
using System.Reflection;
using ET;
namespace ET
{
public static class InitHotfix
{
#if UNITY
public static async void Start()
#else
public static async void Start(string key, string keyIV, byte[] xorKey)
#endif
{
try
{
#if UNITY
string clientVersion = await GlobalHotfixProtoHelper.GetClintVersion();
if (!clientVersion.Equals(GlobalConfigComponent.Instance.GlobalProto.ClientVersion))
{
ETTaskCompletionSource tcs = new ETTaskCompletionSource();
Game.EventSystem.Publish(new ET.EventType.ShowMessageBox
{
title = "提示!",
content = $"客户端有更新,请下载最新版客户端{clientVersion}",
action = async (MessageBoxEventId id) =>
{
Quit();
}
});
await tcs.Task;
return;
}
if (Define.hasView)
{
Game.EventSystem.Add(Hotfix.instance.hotfix);
Game.EventSystem.Add(Hotfix.instance.hotfixView);
}
else
{
Game.EventSystem.Add(Hotfix.instance.hotfix);
}
#else
await Game.EventSystem.Publish(new ET.EventType.AppStart()
{
key = key,
keyIV = keyIV,
xorKey = xorKey
});
#endif
Game.Scene.AddComponent<NetThreadComponent>();
Game.Scene.AddComponent<OpcodeTypeComponent>();
Game.Scene.AddComponent<MessageDispatcherComponent>();
Game.Scene.AddComponent<ZoneSceneManagerComponent>();
Game.Scene.AddComponent<AIDispatcherComponent>();
ConfigComponent config = Game.Scene.GetOrAddComponent<ConfigComponent>();
Game.Scene.AddComponent<NumericWatcherComponent>();
Game.Scene.AddComponent<WordComponent>();
Scene zoneScene = SceneFactory.CreateZoneScene(1, "Game");
OpcodeHotfixHelper.Init();
Game.EventSystem.Publish_Sync(new ET.EventType.AfterCreateZoneScene() {zoneScene = zoneScene});
}
catch (Exception e)
{
Log.Error(e);
}
}
private static void Quit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
UnityEngine.Application.Quit();
#endif
}
}
}