InitSceneStartEvent_InitGame.cs 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
using System;
using System.Reflection;
using Base;
using UnityEngine;
using Object = Base.Object;

namespace Controller
{
	/// <summary>
	/// 初始化游戏
	/// </summary>
	[Event(EventIdType.InitSceneStart)]
	public class InitSceneStartEvent_InitGame: IEvent
	{
		public async void Run()
		{
			GameObject code = (GameObject)Resources.Load("Code/Code");
			byte[] assBytes = code.Get<TextAsset>("Controller.dll").bytes;
			byte[] mdbBytes = code.Get<TextAsset>("Controller.dll.mdb").bytes;
			Assembly assembly = Assembly.Load(assBytes, mdbBytes);
			Object.ObjectManager.Register("Controller", assembly);
T
tanghai 已提交
22
			Object.ObjectManager.Register("Base", typeof(Game).Assembly);
23 24

			Game.Scene.AddComponent<MessageComponent>();
T
tanghai 已提交
25
			Game.Scene.AddComponent<ChildrenComponent>();
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

			try
			{
				S2C_FetchServerTime s2CFetchServerTime = await Game.Scene.GetComponent<MessageComponent>().CallAsync<S2C_FetchServerTime>(new C2S_FetchServerTime());
				Log.Info($"server time is: {s2CFetchServerTime.ServerTime}");
			}
			catch (RpcException e)
			{
				Log.Error(e.ToString());
			}
			catch (Exception e)
			{
				Log.Error(e.ToString());
			}
		}
	}
}