Jump to content
  • Advertisement
Sign in to follow this  
DarkZoulz

[.net] Serialize a XNA Vector3 type

This topic is 3798 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I serialize a XNA Vector3 type into xml attributes? Only way I can think of is to write a new Vector3 class and implement the attribute tags on it. something like this:

<scene>
    <scenemesh name="test" x="5" y="5" z="5" />
</scene>


C#

[Serializable]
public class SceneMesh
{
    [XmlAttribute("name", typeof(string))]
    public string name;

    [XmlAttribute(typeof(Vector3))]
    public Vector3 position;
}


Share this post


Link to post
Share on other sites
Advertisement
The only thing I can think of as a quick solution is exactly what you said - Make another Vector3 class that is actually serializable. Or as a quick fix you could just add 3 double properties to that scene mesh class called X, Y and Z and then each one would return your_vector3.X / Y or Z. Then just add the attribbutes to those properties and not the Vector3 itself. Like this:


[Serializable]
public class SceneMesh
{
private Vector3 _pos;

[XmlAttribute("name", typeof(string))]
public string name{ set; get; }
public Vector3 position
{
set{_pos = value;}
get{return _pos; }
}

[XmlAttribute("x", typeof(double))]
public double posX
{
get{ return _pos.X; }
}

// ... etc etc

}



Hope it helps,

James

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!