Moved files to proper folders

This commit is contained in:
Martin Johnson 2021-07-31 22:30:58 -04:00
parent ddb92f7236
commit b0d6a2a72d
5 changed files with 42 additions and 77 deletions

View File

@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
{
[SerializeField] private List<TKey> _keys = new List<TKey>();
[SerializeField] private List<TValue> _values = new List<TValue>();
public void OnBeforeSerialize()
{
_keys.Clear();
_values.Clear();
foreach (KeyValuePair<TKey,TValue> 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]);
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Util
{
[Serializable]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
{
[SerializeField] private List<TKey> _keys = new List<TKey>();
[SerializeField] private List<TValue> _values = new List<TValue>();
public void OnBeforeSerialize()
{
_keys.Clear();
_values.Clear();
foreach (KeyValuePair<TKey,TValue> 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]);
}
}
}
}

View File

@ -1,38 +0,0 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// This class sets the text and image of the popup message
/// </summary>
public class PopupMessage : MonoBehaviour
{
public TextMeshProUGUI popupMessage;
private Image image;
/// <summary>
/// Gets the X mark image in the child object
/// </summary>
private void Awake()
{
image = GetComponentsInChildren<Image>()[1];
}
/// <summary>
/// Sets the new test and shows or hides the X mark image.
/// Hides the whole gameObject after 2 seconds
/// </summary>
/// <param name="newText"></param>
/// <param name="enabled"></param>
/// <returns></returns>
public IEnumerator Reset(string newText, bool enabled = false)
{
popupMessage.text = newText;
image.gameObject.SetActive(enabled);
yield return new WaitForSeconds(2f);
gameObject.SetActive(false);
}
}