Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 23, 2015 at 01:58 PM by RealMTG for the following reason:

I decided to try and change encryption method to something a bit easier. More info about the problem here http://forum.unity3d.com/threads/ways-to-encrypt-serialize-my-game-data.349662/

avatar image
0
Question by RealMTG · Aug 10, 2015 at 06:51 PM · stringbinaryformatterdeserialize

BinaryFormatter to string

Hi

I currently have a BinaryFormatter that serializes player levels and all that stuff. But I also need to be able to upload these levels to a webserver and the webserver can only take strings for data storage. So I can make the deserialized info into a string?

The level file is called by using FileStream. It finds the file at a location and serializes/deserializes it. It then gets all the variables I've set in a class and then assign the needed variables with the right data from the deserialized class.

I am not sure of what code I will show since it is pretty basic but if you want to know how I did the serialization, then go here. It starts around 30-31 minutes in.

Thanks in advance!

EDIT: I realized it was bit short on information so I added a bit more.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RealMTG · Aug 10, 2015 at 01:39 PM 0
Share

Do anyone know how I can do this?

avatar image Glurth · Aug 10, 2015 at 04:14 PM 0
Share

I guess I'm not quite clear on what you are asking. You have the option to either "stringify" you serialized data (the file), or your deserialized data (instances of classes).I'm not sure which will work best for you, you'll need to clarify that.

However, I should mention that most unity classes have an overridable function called ToString(), which converts the instance data into a string. I usually use this for debug info, but it should work for your purposes to.

avatar image RealMTG · Aug 10, 2015 at 04:16 PM 0
Share

@Glurth What I basically need to do is to deserialize the data from a file and then turn it all into one string so I can upload it to a webserver. I did also try and do something with the .ToString() function but failed. I will try again since I don't remember exactly what I did in order to fail.

avatar image Glurth · Aug 10, 2015 at 04:48 PM 0
Share

Ok, so we are converting instances into "serialized strings". $$anonymous$$eep in $$anonymous$$d you will be doing, in essence, EXACTLY what you need to do in your serialize function, except that rather than keeping everything as binary data, it is converted to strings.
You mentioned you tried this and it failed, but I think you CAN get it working this way once you work out the bugs.

One other thing to consider is how this data will be received by the webserver. If it is unaware of the structure of your data, simply sending data alone may not be sufficient! You might choose to include FIELD NA$$anonymous$$ES also in your "serialized string". This will allow the webserver to handle (deserialize) the data without the need for perfect awareness of your class structure.

avatar image Nikunj-Kareliya · Aug 10, 2015 at 05:41 PM 0
Share

Anyone here know, how to store to data to web server, after serialization ?? I did using making prefabs, and store it in the resources folder. Other option is using playerprefs. But i want to store level specific data such as obstacles, enemies positions, its type, etc. There are currently 50 levels in the game. I am finding ideal way of doing it. Links would be appriciable.

Thanx.

Show more comments

1 Reply

  • Sort: 
avatar image
-1

Answer by LaneFox · Aug 11, 2015 at 04:50 PM

Here's how I'm doing it. You can probably apply this to your situation.

 private static string SerializeDataToString(OptionsData staticOptions)
 {
     MemoryStream ms = new MemoryStream();
     XmlSerializer xs = new XmlSerializer(typeof(OptionsData));
     XmlTextWriter tw = new XmlTextWriter(ms, Encoding.UTF8);
     xs.Serialize(tw, staticOptions);
     ms = (MemoryStream)tw.BaseStream;

     string xmlizedString = UtfToString(ms.ToArray());
     return xmlizedString; 
 }

 private static string UtfToString(byte[] bytes)
 {
     UTF8Encoding encoding = new UTF8Encoding();
     string constructedString = encoding.GetString(bytes);
     return (constructedString);
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add strings in a list AND be able to save it and load it? Using playerpref OR serialization 2 Answers

BinaryFormatter Deserialization Problem 0 Answers

Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch 0 Answers

How do you deserialize string into Vector3 using XMLSerializer? 0 Answers

Assign a variable using BinaryFormatter 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges