Files
FueraDeEscala/Assets/Game/Menus/LoadingScreen/LoadingScreenController.cs
Robii Aragon 0e961ba4b1 Migrate shaders to URP and add loading screen
Reworks multiple shaders and materials for URP compatibility and adds a Loading screen/scene and a few model imports. Key changes:
- Converted ProBuilder standard vertex-color shader and several particle/surface shaders to URP HLSL passes (UniversalForward, ShadowCaster, Depth, DepthNormals) preserving base texture * tint * vertex color, normal map and PBR parameters.
- Updated particle SurfaceShader_VC to a URP forward pass and simplified lighting to use URP shader library helpers.
- Updated materials (landMark, tile) to point to project textures, adjust keywords/flags (e.g. XRMotionVectorsPass, disable ShadowCaster for one), tweak tiling and base color values.
- Added a Loading screen UI (UXML, USS) and LoadingScreenController.cs plus a new Loading scene and scene metadata.
- Imported new FBX assets (T-Pose, Untitled) and updated Editor build settings / project settings to include the new Loading scene.
These changes migrate rendering code to the Universal Render Pipeline and add a basic loading UI/scene, while updating materials and project settings accordingly.
2026-02-23 21:47:59 -08:00

80 lines
2.5 KiB
C#

using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.SceneManagement;
using System.Collections;
public class LoadingScreenController : MonoBehaviour
{
private UIDocument _doc;
private Label _loadingText;
private VisualElement _spaceship;
private int _dotCount = 0;
private float _time = 0f;
[Header("Configuración de Carga")]
public string sceneToLoad = "SampleScene";
private void Awake()
{
_doc = GetComponent<UIDocument>();
var root = _doc.rootVisualElement;
_loadingText = root.Q<Label>("LoadingText");
_spaceship = root.Q<VisualElement>("Spaceship");
// 1. Animación del texto: Se ejecuta cada 400 milisegundos
root.schedule.Execute(UpdateLoadingText).Every(400);
// 2. Animación loca de la nave: Se ejecuta cada 20 milisegundos para fluidez
root.schedule.Execute(AnimateSpaceship).Every(20);
// 3. Iniciar la carga de la escena en segundo plano
StartCoroutine(LoadSceneAsync());
}
private void UpdateLoadingText()
{
// Alterna entre 0 y 3 puntos
_dotCount = (_dotCount + 1) % 4;
_loadingText.text = "Cargando" + new string('.', _dotCount);
}
private void AnimateSpaceship()
{
if (_spaceship == null) return;
_time += 0.1f;
// Efecto "Rabbid": vibración y rotación errática usando Seno y Coseno
float offsetX = Mathf.Sin(_time * 12f) * 8f;
float offsetY = Mathf.Cos(_time * 15f) * 6f;
float rotation = Mathf.Sin(_time * 20f) * 3f;
_spaceship.style.translate = new Translate(offsetX, offsetY, 0);
_spaceship.style.rotate = new Rotate(new Angle(rotation, AngleUnit.Degree));
}
private IEnumerator LoadSceneAsync()
{
// Pequeña pausa opcional para que la pantalla no parpadee si la escena carga muy rápido
yield return new WaitForSeconds(0.5f);
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneToLoad);
// La escena no cambia automáticamente hasta que nosotros lo indiquemos
asyncLoad.allowSceneActivation = false;
// Espera hasta que Unity haya cargado el 90% (el 10% restante es la activación)
while (asyncLoad.progress < 0.9f)
{
yield return null;
}
// Pequeña pausa para que la animación sea visible aunque la escena cargue muy rápido
yield return new WaitForSeconds(0.8f);
// Ahora sí, activa la escena
asyncLoad.allowSceneActivation = true;
}
}