/
arti4
/
Diplom
Обзор
Документация
Войти
/
arti4
/
Diplom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Scripts/Other/Map/LoadingScreen.cs
153 строки
4 KB
arti4
Загрузка всех скриптов
17 май 2026, 09:08
Верифицирован
17 май 2026, 09:08
cc2e1cd
Код
Авторство
О чём код?
using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class LoadingScreen : MonoBehaviour { [Header("UI ��������")] public GameObject blackPanel; public TMP_Text loadingText; [Header("���������")] public float dotChangeInterval = 0.5f; public string baseText = "��������"; private Canvas canvas; private Coroutine loadingCoroutine; private bool isLoading = false; private Coroutine autoHideCoroutine; void Awake() { canvas = GetComponent<Canvas>(); if (canvas != null) { canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.sortingOrder = 9999; } } public void Show(float duration = 2f, System.Action onComplete = null) { if (isLoading) return; isLoading = true; if (blackPanel != null) blackPanel.SetActive(true); if (loadingText != null) { loadingText.gameObject.SetActive(true); loadingText.text = baseText; } BlockInput(true); if (loadingCoroutine != null) StopCoroutine(loadingCoroutine); loadingCoroutine = StartCoroutine(LoadingAnimation()); if (autoHideCoroutine != null) StopCoroutine(autoHideCoroutine); autoHideCoroutine = StartCoroutine(AutoHide(duration, onComplete)); } public void Hide() { if (!isLoading) return; isLoading = false; if (loadingCoroutine != null) { StopCoroutine(loadingCoroutine); loadingCoroutine = null; } if (autoHideCoroutine != null) { StopCoroutine(autoHideCoroutine); autoHideCoroutine = null; } if (blackPanel != null) blackPanel.SetActive(false); if (loadingText != null) loadingText.gameObject.SetActive(false); BlockInput(false); } public void OnLoadingComplete() { } private IEnumerator LoadingAnimation() { int dotCount = 0; while (isLoading) { dotCount = (dotCount + 1) % 4; if (loadingText != null) { string dots = new string('.', dotCount); loadingText.text = baseText + dots; } yield return new WaitForSeconds(dotChangeInterval); } } private IEnumerator AutoHide(float duration, System.Action onComplete) { yield return new WaitForSeconds(duration); Hide(); if (onComplete != null) onComplete(); } private void BlockInput(bool block) { if (block) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } else { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } } void OnDestroy() { BlockInput(false); } public void ForceHide() { if (isLoading) { isLoading = false; if (loadingCoroutine != null) { StopCoroutine(loadingCoroutine); loadingCoroutine = null; } if (autoHideCoroutine != null) { StopCoroutine(autoHideCoroutine); autoHideCoroutine = null; } if (blackPanel != null) blackPanel.SetActive(false); if (loadingText != null) loadingText.gameObject.SetActive(false); BlockInput(false); } } }