init: version 1

This commit is contained in:
Job
2025-07-17 17:16:02 +02:00
commit a76c0f6445
519 changed files with 202925 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Events;
using UnityEngine;
/// <summary>
/// GameManager is a singleton that manages the game state of
/// a single scene.
/// </summary>
public class GameManager : MonoBehaviour
{
public static GameManager Instance => _instance;
private static GameManager _instance;
public MapSwitchEvent onMapSwitch;
public RespawnEvent onRespawn;
public int currentMapIdx;
public List<GameObject> maps;
public List<CubeController> cubes;
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(gameObject);
return;
}
_instance = this;
}
public void SwitchMap(int mapIdx)
{
Vector3 offset = maps[mapIdx].transform.position - maps[currentMapIdx].transform.position;
currentMapIdx = mapIdx;
onMapSwitch?.Invoke(currentMapIdx, offset);
}
public void ResetCubes()
{
foreach (var cube in cubes.Where(x=> x.currentMap == currentMapIdx && x.originMap != x.currentMap))
{
cube.Respawn();
}
}
private void Update()
{
if (!Input.GetKeyDown(KeyCode.J)) return;
SwitchMap((currentMapIdx + 1) % maps.Count);
}
}
[Serializable]
public class MapSwitchEvent : UnityEvent<int, Vector3>
{
}
[Serializable]
public class RespawnEvent : UnityEvent
{
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e76b69a7b31c4556ab9063967e140e54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -100
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using UnityEngine;
/// <summary>
/// MenuManager manages the transitions from the menu screen to the game levels.
/// </summary>
public class MenuManager : MonoBehaviour
{
public void ToLevel(int level)
{
TransitionManager.Instance.ToLevel(level);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df5754d43d0942b489107176ee01993e
timeCreated: 1752740870

View File

@@ -0,0 +1,54 @@
using System.Collections;
using UnityEngine;
/// <summary>
/// TransitionManager is a singleton that manages the transitions
/// between levels in the game.
/// </summary>
public class TransitionManager : MonoBehaviour
{
public static TransitionManager Instance => _instance;
private static TransitionManager _instance;
public int currentLevel;
private Animator _animator;
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(gameObject);
return;
}
_instance = this;
DontDestroyOnLoad(gameObject);
_animator = GetComponentInChildren<Animator>();
}
public void NextLevel()
{
ToLevel(currentLevel + 1);
}
public void ToLevel(int level)
{
currentLevel = level;
var scene = $"Level {level}";
if (Application.CanStreamedLevelBeLoaded(scene))
StartCoroutine(LoadLevel(scene));
else
{
currentLevel = 0;
StartCoroutine(LoadLevel("Menu"));
}
}
private IEnumerator LoadLevel(string levelName)
{
_animator.SetTrigger("Start");
yield return new WaitForSeconds(.5f);
UnityEngine.SceneManagement.SceneManager.LoadScene(levelName);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 89e423dc0c9ad138ebf86acee5de9581