zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Hotfix/Logic/Behaviour/Game/Helper/EnterGameHelper.cs

63 lines
2.0 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using ET;
using UnityEngine;
namespace ET
{
public class EnterGameHelper
{
public static async ETTask<string> EnterGameAsync(Scene zoneScene,bool isReconnect = false)
2021-04-08 20:09:59 +08:00
{
Game.EventSystem.Publish_Sync(new ET.EventType.TranslateSceneStart
{
isAutoEnd = false,
});
try
2021-04-08 20:09:59 +08:00
{
//!发送请求
G2C_EnterGame ret = (G2C_EnterGame)await zoneScene.GetComponent<SessionComponent>().Session.Call(new C2G_EnterGame() { });
if (!ret.Message.IsNullOrEmpty())
2021-04-08 20:09:59 +08:00
{
Game.EventSystem.Publish(new ET.EventType.ShowTipUI
2021-04-08 20:09:59 +08:00
{
tip = "进入游戏失败,请重新登录。\n" + ret.Message,
okAction = (txt) =>
{
Game.EventSystem.Publish_Sync(new ET.EventType.Quit());
}
}).Coroutine();
return ret.Message;
}
//!赋值用户Id
Unit unit = zoneScene.GetComponent<UnitComponent>().Get(ret.Id);
zoneScene.GetComponent<GlobalVariable>().isOnLine = ret.IsOnline;
await Game.EventSystem.Publish(new ET.EventType.EnterGameFinish_CreateMainUI
{
zoneScene = zoneScene,
isReConnect=isReconnect
});
2021-04-08 20:09:59 +08:00
await TimerComponent.Instance.WaitAsync(500);
2021-04-08 20:09:59 +08:00
await Game.EventSystem.Publish(new ET.EventType.EnterGameFinish_SetCharacter
{
zoneScene = zoneScene,
isOnline = ret.IsOnline
});
}
catch (Exception e)
2021-04-08 20:09:59 +08:00
{
Log.Error(e);
return "系统错误";
}
return null;
2021-04-08 20:09:59 +08:00
}
}
}