things
This commit is contained in:
parent
a17810ffeb
commit
4e91f448c9
826 changed files with 66 additions and 8 deletions
8
Assets/Scripts/Singletons/Abstract.meta
Normal file
8
Assets/Scripts/Singletons/Abstract.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 378d95684615781798186de36dd1fd98
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
26
Assets/Scripts/Singletons/Abstract/MonoBehaviourSingleton.cs
Normal file
26
Assets/Scripts/Singletons/Abstract/MonoBehaviourSingleton.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dde3af729030b37d991e70070acee9b
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a1a48baa3d70ae8fca6a9e23eb62eb1d
|
80
Assets/Scripts/Singletons/BasedGameManager.cs
Normal file
80
Assets/Scripts/Singletons/BasedGameManager.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/Singletons/BasedGameManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/BasedGameManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3aa2eb264738746aab80b5768ad3206f
|
6
Assets/Scripts/Singletons/CoroutineManager.cs
Normal file
6
Assets/Scripts/Singletons/CoroutineManager.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class CoroutineManager : MonoBehaviourSingleton<CoroutineManager>
|
||||
{
|
||||
}
|
2
Assets/Scripts/Singletons/CoroutineManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/CoroutineManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e25f27d44ff1bea9fb02b1e5deeceed8
|
61
Assets/Scripts/Singletons/SoundManager.cs
Normal file
61
Assets/Scripts/Singletons/SoundManager.cs
Normal 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();
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/Singletons/SoundManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/SoundManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 674cc8c0eaaaff27c890e7968596e1ec
|
Loading…
Add table
Add a link
Reference in a new issue