コード例 #1
0
 public override void DoButton(Rect rect)
 {
     Single = this;
     if (!MainHelper.DebugMode)
     {
         this.def.buttonVisible = SessionClient.Get.IsLogined;
     }
     base.DoButton(rect);
 }
コード例 #2
0
        /// <summary>
        /// Инициализация после получения всех данных и уже запущенной игре
        /// </summary>
        public static void InitGame()
        {
            try
            {
                Loger.Log("Client InitGame()");
                //Data.ChatsTime = DateTime.UtcNow + ServerTimeDelta; //без этого указания будут получены все сообщения с каналов

                MainButtonWorker_OC.ShowOnStart();
                UpdateWorldController.ClearWorld();
                UpdateWorldController.InitGame();
                Data.UpdateTime = DateTime.MinValue;
                UpdateWorld(true);

                Data.LastServerConnect = DateTime.MinValue;

                Timers.Add(500, UpdateChats);
                Timers.Add(5000, () => UpdateWorld(false));
                Timers.Add(60000 * 15, BackgroundSaveGame);

                //устанавливаем событие на выход из игры
                GameExit.BeforeExit = () =>
                {
                    Loger.Log("Client BeforeExit ");
                    GameExit.BeforeExit = null;
                    TimersStop();
                    if (Current.Game == null)
                    {
                        return;
                    }

                    Loger.Log("Client SaveGameBeforeExit " + SaveFullName);
                    GameDataSaveLoader.SaveGame(SaveName);
                    var content = File.ReadAllBytes(SaveFullName);
                    if (content.Length > 1024)
                    {
                        Data.SaveFileData = content;
                        UpdateWorld(false);

                        Loger.Log("Client SaveGameBeforeExit OK");
                    }
                    SessionClient.Get.Disconnect();
                };
            }
            catch (Exception e)
            {
                ExceptionUtil.ExceptionLog(e, "Client InitGame Error");
                GameExit.BeforeExit = null;
                TimersStop();
                if (Current.Game == null)
                {
                    return;
                }
                SessionClient.Get.Disconnect();
            }
        }
コード例 #3
0
ファイル: StartPoint.cs プロジェクト: thomotron/OnlineCity
 public override void DoButton(Rect rect)
 {
     Single = this;
     if (!MainHelper.DebugMode)
     {
         this.def.buttonVisible = SessionClient.Get.IsLogined;
     }
     base.DoButton(rect);
     try
     {
         if (SessionClientController.Data.ChatNotReadPost > 0)
         {
             var queueRect = new Rect(
                 rect.xMax - 20f - 6f,
                 0f,
                 20f,
                 20f).CenteredOnYIn(rect);
             GameUtils.DrawLabel(queueRect, Color.white, Color.grey, SessionClientController.Data.ChatNotReadPost);
         }
     }
     catch
     {
     }
 }
コード例 #4
0
        /// <summary>
        /// Инициализация после получения всех данных и уже запущенной игре
        /// </summary>
        public static void InitGame()
        {
            try
            {
                Loger.Log("Client InitGame()");
                //Data.ChatsTime = (DateTime.UtcNow + ServerTimeDelta).AddDays(-1); //без этого указания будут получены все сообщения с каналов

                MainButtonWorker_OC.ShowOnStart();
                UpdateWorldController.ClearWorld();
                UpdateWorldController.InitGame();
                Data.UpdateTime = DateTime.MinValue;
                UpdateWorld(true);

                Data.LastServerConnect = DateTime.MinValue;

                Timers.Add(100, UpdateFastTimer);
                Timers.Add(500, UpdateChats);
                Timers.Add(5000, () => UpdateWorld(false));
                Timers.Add(10000, PingServer);
                Timers.Add(60000 * Data.DelaySaveGame, BackgroundSaveGame);
                TimerReconnect.Add(1000, CheckReconnectTimer);

                //устанавливаем событие на выход из игры
                GameExit.BeforeExit = () =>
                {
                    try
                    {
                        Loger.Log("Client BeforeExit ");
                        GameExit.BeforeExit = null;
                        TimersStop();
                        if (Current.Game == null)
                        {
                            return;
                        }

                        if (!Data.BackgroundSaveGameOff)
                        {
                            Loger.Log($"Client {SessionClientController.My.Login} SaveGameBeforeExit " + SaveFullName);
                            GameDataSaveLoader.SaveGame(SaveName);
                            var content = File.ReadAllBytes(SaveFullName);
                            if (content.Length > 1024)
                            {
                                Data.SaveFileData = content;
                                Data.SingleSave   = false;
                                UpdateWorld(false);

                                Loger.Log($"Client {SessionClientController.My.Login} SaveGameBeforeExit OK");
                            }
                        }
                        SessionClient.Get.Disconnect();
                    }
                    catch (Exception e)
                    {
                        Loger.Log("Client BeforeExit Exception: " + e.ToString());
                        throw;
                    }
                };
            }
            catch (Exception e)
            {
                ExceptionUtil.ExceptionLog(e, "Client InitGame Error");
                GameExit.BeforeExit = null;
                TimersStop();
                if (Current.Game == null)
                {
                    return;
                }
                SessionClient.Get.Disconnect();
            }
        }