GameObject.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using CommonLang;
  2. using CommonLang.Concurrent;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace CommonAI.Zone
  8. {
  9. abstract public class GameEntity : Disposable
  10. {
  11. private HashMap<string, object> mAttributes = new HashMap<string, object>();
  12. public GameEntity()
  13. {
  14. }
  15. public bool IsAttribute(string key)
  16. {
  17. return mAttributes.ContainsKey(key);
  18. }
  19. public void SetAttribute(string key, object value)
  20. {
  21. mAttributes.Put(key, value);
  22. }
  23. public object RemoveAttribute(string key)
  24. {
  25. return mAttributes.RemoveByKey(key);
  26. }
  27. public object GetAttribute(string key)
  28. {
  29. return mAttributes.Get(key);
  30. }
  31. public T GetAttributeAs<T>(string key)
  32. {
  33. object obj = mAttributes.Get(key);
  34. if (obj != null)
  35. {
  36. return (T)obj;
  37. }
  38. return default(T);
  39. }
  40. protected override void Disposing()
  41. {
  42. mAttributes.Clear();
  43. }
  44. }
  45. }