From b0d6a2a72d64787e34f81bae554039c1a4b92633 Mon Sep 17 00:00:00 2001 From: Martin Johnson Date: Sat, 31 Jul 2021 22:30:58 -0400 Subject: [PATCH] Moved files to proper folders --- Singleton.cs => Core/Singleton.cs | 0 Timer.cs => Core/Timer.cs | 0 SerializableDictionary.cs | 39 ---------------------------- Util/SerializableDictionary.cs | 42 +++++++++++++++++++++++++++++++ Utility/PopupMessage.cs | 38 ---------------------------- 5 files changed, 42 insertions(+), 77 deletions(-) rename Singleton.cs => Core/Singleton.cs (100%) rename Timer.cs => Core/Timer.cs (100%) delete mode 100644 SerializableDictionary.cs create mode 100644 Util/SerializableDictionary.cs delete mode 100644 Utility/PopupMessage.cs diff --git a/Singleton.cs b/Core/Singleton.cs similarity index 100% rename from Singleton.cs rename to Core/Singleton.cs diff --git a/Timer.cs b/Core/Timer.cs similarity index 100% rename from Timer.cs rename to Core/Timer.cs diff --git a/SerializableDictionary.cs b/SerializableDictionary.cs deleted file mode 100644 index 5dab809..0000000 --- a/SerializableDictionary.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -[Serializable] -public class SerializableDictionary : Dictionary, ISerializationCallbackReceiver -{ - [SerializeField] private List _keys = new List(); - [SerializeField] private List _values = new List(); - - public void OnBeforeSerialize() - { - _keys.Clear(); - _values.Clear(); - - foreach (KeyValuePair pair in this) - { - _keys.Add(pair.Key); - _values.Add(pair.Value); - } - } - - public void OnAfterDeserialize() - { - Clear(); - - if (_keys.Count != _values.Count) - { - throw new Exception( - $"There are {_keys.Count} keys and {_values.Count} values after deserialization." + - " Make sure that both key and value types are serializable."); - } - - for (int i = 0; i < _keys.Count; ++i) - { - Add(_keys[i], _values[i]); - } - } -} \ No newline at end of file diff --git a/Util/SerializableDictionary.cs b/Util/SerializableDictionary.cs new file mode 100644 index 0000000..d20494a --- /dev/null +++ b/Util/SerializableDictionary.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace Util +{ + [Serializable] + public class SerializableDictionary : Dictionary, ISerializationCallbackReceiver + { + [SerializeField] private List _keys = new List(); + [SerializeField] private List _values = new List(); + + public void OnBeforeSerialize() + { + _keys.Clear(); + _values.Clear(); + + foreach (KeyValuePair pair in this) + { + _keys.Add(pair.Key); + _values.Add(pair.Value); + } + } + + public void OnAfterDeserialize() + { + Clear(); + + if (_keys.Count != _values.Count) + { + throw new Exception( + $"There are {_keys.Count} keys and {_values.Count} values after deserialization." + + " Make sure that both key and value types are serializable."); + } + + for (int i = 0; i < _keys.Count; ++i) + { + Add(_keys[i], _values[i]); + } + } + } +} \ No newline at end of file diff --git a/Utility/PopupMessage.cs b/Utility/PopupMessage.cs deleted file mode 100644 index a67ede5..0000000 --- a/Utility/PopupMessage.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections; -using UnityEngine; -using UnityEngine.UI; -using TMPro; - -/// -/// This class sets the text and image of the popup message -/// -public class PopupMessage : MonoBehaviour -{ - public TextMeshProUGUI popupMessage; - private Image image; - - /// - /// Gets the X mark image in the child object - /// - private void Awake() - { - image = GetComponentsInChildren()[1]; - } - - - /// - /// Sets the new test and shows or hides the X mark image. - /// Hides the whole gameObject after 2 seconds - /// - /// - /// - /// - public IEnumerator Reset(string newText, bool enabled = false) - { - - popupMessage.text = newText; - image.gameObject.SetActive(enabled); - yield return new WaitForSeconds(2f); - gameObject.SetActive(false); - } -}