Jump to content

  • Log In with Google      Sign In   
  • Create Account


Save System Help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 KoldGames   Members   -  Reputation: 222

Like
0Likes
Like

Posted 03 November 2013 - 09:58 AM

Hello! I am trying to create a save system and I am having problems.

[System.AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
	public class NXSaveElement : Attribute
	{
		public string ElementName { get; set; }
		
		public NXSaveElement(string elementName)
		{
			ElementName = elementName;
		}
	}
	
	public abstract class INXSave
	{
		public abstract string Name { get; }
		
		public void Save(string dir)
		{
			string finalFile = Path.Combine(dir, Name);
			
			using (BinaryWriter writer = new BinaryWriter(File.Open(finalFile,FileMode.OpenOrCreate)))
			{
				foreach (PropertyInfo info in this.GetType().GetProperties())
				{
					foreach (object obj in info.GetCustomAttributes(true))
					{
						Attribute attribute = (Attribute)obj;
						
						if (attribute is NXSaveElement)
						{
							NXSaveElement element = (NXSaveElement)attribute;
							writer.Write(element.ElementName);
							//WRITE VALUE HERE
						}
					}
				}
			}
		}
	}
	
	public class NXPlayerSave : INXSave
	{
		public override string Name {
			get {
				return "player";
			}
		}
		
		[NXSaveElement("position")]
		public Vector3 Position { get; set; }
		
		[NXSaveElement("rotation")]
		public Vector3 Rotation { get; set; }
		
		[NXSaveElement("health")]
		public float Health { get; set ; }
		
		public NXPlayerSave(NXPlayer player)
		{
			Position = player.Position;
			Rotation = new Vector3(player.Camera.Yaw, player.Camera.Pitch, 0);
			Health = player.Health;
		}
	}

I would like to get the value of objects I have my NXSaveElement attribute attached to so I can write the value to a binary file but I don't know how to get the value. Is it possible? Thanks! :)



Sponsor:

#2 KoldGames   Members   -  Reputation: 222

Like
0Likes
Like

Posted 03 November 2013 - 10:17 AM

Never mind, I fixed it! :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS