游戏入口

本项目以Main.cs(Assets/Script/Main.cs)作为主入口初始化游戏逻辑.首先初始化日志系统方便查看整个项目运行过程中的输出日志,并且添加发布宏在正式发布时自动关闭日志.

        [SerializeField]
        private bool isLogOn = false;
        [SerializeField]
        private bool isLogOnScene = false;
        [SerializeField]
        private bool isFpsOn = false;

        public void Start()
        {
#if Release
            this.isLogOn = this.isLogOnScene = this.isFpsOn = false;
#endif

其次初始化游戏的Tick管理逻辑,线程回调事件,游戏退出回调事件等.GameWorld里面包含线程处理的队列,保证线程的回调事件按顺序在主线程中正常处理.

再之后启动GameBox中的配置读取逻辑,音效初始化,注册游戏模块:战斗场景,服务器交互.

 public void Init()
        {
            GameWorld.Instance.StartCoroutine(ExcelManager.LoadAll_Enum(progress =>
            {
                if (progress == 1.0f)
                {
                    this.isDataOk = true;
                    InitGame();
                }
            }));
            Singleton.GetInstance<GameAudio>().Init();
            new ServiceTask(new[]
            {
                typeof(IAssetManager),
                typeof(IRecycleManager)
            }).Start().Continue(t =>
            {
                this.isServiceOk = true;
                Regist<HttpAgent>(Module.EModele.Login);
                Regist<TcpConnection>(Module.EModele.Network_Tcp);
                Regist<KcpConnection>(Module.EModele.Network_Kcp);
                Regist<UdpConnection>(Module.EModele.Network_Udp);
                Regist<BattleScene>(Module.EModele.Battle);
                InitGame();
                return null;
            });
        }

当所有的服务和数据准备完成之后就可以通过GameBox资源组件加载游戏登录UI:

 private void InitGame()
        {
            if (this.isDataOk && this.isServiceOk)
            {
                using (var asset = ServiceCenter.GetService<IAssetManager>().Load("UI", AssetType.Prefab))
                {
                    Object.Instantiate(asset.Cast<Object>());
                }
            }
        }

results matching ""

    No results matching ""