예제 #1
0
        /// <summary>
        /// Бесконечно дописывает логи в файл.
        /// </summary>
        /// <param name="state"></param>
        private async void ThreadWork(object state)
        {
            try
            {
                while (true)
                {
                    await Task.Delay(maxPrintingPeriodMs);

                    string[] logsCopy = new string[logs.Count];
                    lock (LockObj)
                    {
                        if (logs.Count > 0)
                        {
                            logs.CopyTo(logsCopy);
                            logs.Clear();
                        }
                    }
                    Print(logsCopy);
                }
            }
            catch (Exception e)
            {
                UnityThread.Execute(() =>
                {
                    Debug.LogError("Было брошено исключение в логгере " + e.Message);
                });
            }

            // ReSharper disable once FunctionNeverReturns
        }
예제 #2
0
        public void Fatal(string message)
        {
            const string levelName = " " + nameof(Fatal) + " ";
            string       log       = DateTime.Now.ToLongTimeString() + levelName + typeName + message;

            logManager.AddLog(log);
            UnityThread.Execute(() => UnityEngine.Debug.LogError(log));
        }
예제 #3
0
 public void ShowImageAnimation()
 {
     UnityThread.Execute(async() =>
     {
         imageForPlayerDeath.SetActive(true);
         Image image  = imageForPlayerDeath.GetComponent <Image>();
         int maxAlpha = 45;
         for (int currentAlpha = maxAlpha; currentAlpha > 0; currentAlpha--)
         {
             var currentColor = image.color;
             image.color      = new Color(currentColor.r, currentColor.g, currentColor.b, currentAlpha);
             await Task.Delay(15);
         }
     });
 }
예제 #4
0
        public void Error(string message)
        {
            const string levelName = " " + nameof(Error) + " ";
            string       log       = DateTime.Now.ToLongTimeString() + levelName + typeName + message;

            logManager.AddLog(log);
            if (Thread.CurrentThread.ManagedThreadId == mainThreadId)
            {
                UnityEngine.Debug.LogError(log);
            }
            else
            {
                UnityThread.Execute(() =>
                {
                    UnityEngine.Debug.LogError(log);
                });
            }
        }
예제 #5
0
        public async Task <UsernameValidationResultEnum> TrySetUsernameAsync(string newUsername)
        {
            log.Debug(Thread.CurrentThread.Name);
            UsernameChangingService service = new UsernameChangingService();
            var result = await service.ChangesUsernameAsync(newUsername);

            log.Debug(Thread.CurrentThread.Name);
            if (result == UsernameValidationResultEnum.Ok)
            {
                UnityThread.Execute(() =>
                {
                    log.Debug(Thread.CurrentThread.Name);
                    PlayerPrefs.SetString(UsernameKey, newUsername);
                    PlayerIdStorage.SetUsername(newUsername);
                    var lobbyEcsController = FindObjectOfType <LobbyEcsController>();
                    lobbyEcsController.ReplaceUsername(newUsername);
                });
            }

            return(result);
        }