This commit is contained in:
Crizomb 2025-01-29 00:59:22 +01:00
parent a17810ffeb
commit 4e91f448c9
826 changed files with 66 additions and 8 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 378d95684615781798186de36dd1fd98
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
public class MonoBehaviourSingleton<T> : MonoBehaviour
where T : Component
{
private static T _instance;
public static T Instance {
get {
if (_instance == null) {
var objs = FindObjectsByType<T> (FindObjectsSortMode.None) as T[];
if (objs.Length > 0)
_instance = objs[0];
if (objs.Length > 1) {
Debug.LogError ("There is more than one " + typeof(T).Name + " in the scene.");
}
if (_instance == null) {
GameObject obj = new GameObject (typeof(T).Name);
obj.hideFlags = HideFlags.HideAndDontSave;
_instance = obj.AddComponent<T> ();
}
}
return _instance;
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1dde3af729030b37d991e70070acee9b

View file

@ -0,0 +1,18 @@
using UnityEngine;
public class MonoBehaviourSingletonPersistent<T> : MonoBehaviour
where T : Component
{
public static T Instance { get; private set; }
public virtual void Awake ()
{
if (Instance == null) {
Instance = this as T;
Instance.name = typeof(T).Name;
DontDestroyOnLoad (gameObject);
} else {
Destroy (gameObject);
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a1a48baa3d70ae8fca6a9e23eb62eb1d

View file

@ -0,0 +1,80 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class BasedGameManager : MonoBehaviourSingletonPersistent<BasedGameManager>
{
[SerializeField] private List<string> levelNames;
[SerializeField] private List<string> levelMusics;
[SerializeField] private List<int> levelsMoney;
int current_level = -1;
[SerializeField] GameObject GameUI;
[SerializeField] GameObject LoseUI;
[SerializeField] GameObject WinUI;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
// Delete, use only for Debug
if (Input.GetKeyDown(KeyCode.Space))
{
StartFightForAll();
}
}
public void StartFightForAll()
{
AbstractUnit[] units = FindObjectsByType<AbstractUnit>(FindObjectsSortMode.None);
foreach (var unit in units)
{
unit.StartFight();
}
}
private void SetGlobals(int current_level)
{
GlobalsVariable.AliveUnitsTeamB = new List<AbstractUnit>();
GlobalsVariable.AliveUnitsTeamA = new List<AbstractUnit>();
GlobalsVariable.QueenA = null;
GlobalsVariable.QueenB = null;
GlobalsVariable.money = levelsMoney[current_level];
}
public void ReloadLevel()
{
print("get good, reload current scene");
SetGlobals(current_level);
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
}
public void GoNextLevel()
{
if (current_level < levelNames.Count)
{
current_level++;
SetGlobals(current_level);
SceneManager.LoadScene(levelNames[current_level]);
SoundManager.Instance.PlayMusic(levelMusics[current_level]);
}
throw new Exception("Bro there is no next level like stop pls");
}
public void Losing()
{
LoseUI.SetActive(true);
this.enabled = false;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3aa2eb264738746aab80b5768ad3206f

View file

@ -0,0 +1,6 @@
using System.Collections;
using UnityEngine;
public class CoroutineManager : MonoBehaviourSingleton<CoroutineManager>
{
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e25f27d44ff1bea9fb02b1e5deeceed8

View file

@ -0,0 +1,61 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
[Serializable]
public class SoundEntry
{
public string Key;
public AudioClip Value;
}
public class SoundManager : MonoBehaviourSingletonPersistent<SoundManager>
{
// Audio players components.
public AudioSource EffectsSource;
public AudioSource MusicSource;
public List<SoundEntry> SoundsList;
private Dictionary<string, AudioClip> soundsDictionary;
new void Awake()
{
base.Awake();
// Convert the List to a Dictionary at runtime for easier access
soundsDictionary = new Dictionary<string, AudioClip>();
foreach (var entry in SoundsList)
{
if (!soundsDictionary.ContainsKey(entry.Key))
{
soundsDictionary.Add(entry.Key, entry.Value);
}
}
}
private AudioClip GetSound(string key)
{
print(soundsDictionary.Count);
AudioClip clip = soundsDictionary.TryGetValue(key, out var value) ? value : null;
if (clip == null)
{
Debug.LogError($"Sound {key} not found");
}
return clip;
}
public void Play(string keyName)
{
EffectsSource.clip = GetSound(keyName);
EffectsSource.Play();
}
public void PlayMusic(string keyName)
{
MusicSource.clip = GetSound(keyName);
MusicSource.Play();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 674cc8c0eaaaff27c890e7968596e1ec