2
0

WorldObject.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //-----------------------------------------------------------------------------
  2. // WorldObject.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using Microsoft.Xna.Framework;
  9. using Microsoft.Xna.Framework.Content;
  10. namespace RolePlaying.Data
  11. {
  12. /// <summary>
  13. /// Common base class for all objects that are visible in the world.
  14. /// </summary>
  15. public abstract class WorldObject : ContentObject
  16. {
  17. /// <summary>
  18. /// The name of the object.
  19. /// </summary>
  20. private string name;
  21. /// <summary>
  22. /// The name of the object.
  23. /// </summary>
  24. public string Name
  25. {
  26. get { return name; }
  27. set { name = value; }
  28. }
  29. /// <summary>
  30. /// Read a WorldObject object from the content pipeline.
  31. /// </summary>
  32. public class WorldObjectReader : ContentTypeReader<WorldObject>
  33. {
  34. /// <summary>
  35. /// Read a WorldObject object from the content pipeline.
  36. /// </summary>
  37. protected override WorldObject Read(ContentReader input,
  38. WorldObject existingInstance)
  39. {
  40. // we cannot create this object, so there must be an existing instance
  41. if (existingInstance == null)
  42. {
  43. throw new ArgumentNullException("existingInstance");
  44. }
  45. existingInstance.AssetName = input.AssetName;
  46. existingInstance.Name = input.ReadString();
  47. return existingInstance;
  48. }
  49. }
  50. }
  51. }