Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / AI / FSM / DictionariesFSM.cs
@Rackday Rackday on 21 Aug 970 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DictionariesFSM<T>
  5. {
  6. private Dictionary<string, T> dictionary;
  7. public DictionariesFSM()
  8. {
  9. this.dictionary = new Dictionary<string, T>();
  10. }
  11. public T GetValue(string key, T defaultValue = default)
  12. {
  13. T value;
  14. if (!dictionary.TryGetValue(key, out value))
  15. {
  16. value = defaultValue;
  17. }
  18. return value;
  19. }
  20. public bool HasKey(string key)
  21. {
  22. return dictionary.ContainsKey(key);
  23. }
  24. public void SetValue(string key, T value)
  25. {
  26. if (!HasKey(key))
  27. {
  28. dictionary.Add(key, value);
  29. }
  30. else
  31. {
  32. dictionary[key] = value;
  33. }
  34. }
  35. public void DeleteKey(string key)
  36. {
  37. if (HasKey(key))
  38. dictionary.Remove(key);
  39. }
  40. public void ClearDictionary()
  41. {
  42. dictionary.Clear();
  43. }
  44. }