CTT/Unity/Assets/Hotfix/Logic/Behaviour/Game/Helper/EnterGameHelper.cs

63 lines
2.0 KiB
C#

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)
{
Game.EventSystem.Publish_Sync(new ET.EventType.TranslateSceneStart
{
isAutoEnd = false,
});
try
{
//!发送请求
G2C_EnterGame ret = (G2C_EnterGame)await zoneScene.GetComponent<SessionComponent>().Session.Call(new C2G_EnterGame() { });
if (!ret.Message.IsNullOrEmpty())
{
Game.EventSystem.Publish(new ET.EventType.ShowTipUI
{
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
});
await TimerComponent.Instance.WaitAsync(500);
await Game.EventSystem.Publish(new ET.EventType.EnterGameFinish_SetCharacter
{
zoneScene = zoneScene,
isOnline = ret.IsOnline
});
}
catch (Exception e)
{
Log.Error(e);
return "系统错误";
}
return null;
}
}
}