• 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 post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by Cazual · Mar 31, 2014 at 06:07 AM · mobilesavedataserializable

IOS Serialization How To

I have the following code and t$$anonymous$$s works on all platforms except iOS, does anyone know how I can get the list of classes stored in iOS in a similar fas$$anonymous$$on as below?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Runtime.Serialization;
 
 public class SettingsControl : MonoBehaviour {
     
     public static SettingsControl control;
     
     [System.Serializable]
     public class Setting{
         public string Language;
         public string defaultlanguage;
         public string Omschrijving;
         public string Actievoor;
         public string Zoeken;
         public string NoDesription;
         public string panel2;
         public string panel3;
         public string panel4;
         public string panel5;
         public string disclaimer;
         public string twoagree;
 
     }
 
     [System.Serializable]
     public class ListContainer
     {
         public List<Setting> settings; 
     }
     
     public List<Setting> settings=new List<Setting>();
     
     void Awake () {
         // there can be only ONE ! across scenes
         if (control == null)
         {
             DontDestroyOnLoad(gameObject);
             control = t$$anonymous$$s; 
         }
         else if(control != t$$anonymous$$s)
         {
             Destroy(gameObject);
         }
     }
 
     public bool FirstTime()
     {
         if (File.Exists (Application.persistentDataPath + "/SettingsData.dat")) 
         {
             return false;
         } 
         else 
         {
             return true;
         }
     }
     
     public void Save()
     {
         // Initialize
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create(Application.persistentDataPath + "/SettingsData.dat");
         
         ListContainer lc=new ListContainer();
         lc.settings=settings;
 
         //UnitySerializer.SerializeToFile (lc.settings,Application.persistentDataPath + "/SettingsData.dat");
         // Write Data
         bf.Serialize(file,lc.settings);
 
         file.Close ();
     }
     
     public void Load()
     {
         if (File.Exists(Application.persistentDataPath + "/SettingsData.dat"))
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open (Application.persistentDataPath + "/SettingsData.dat",  FileMode.Open);
             settings = (List<Setting>)bf.Deserialize(file);
 
             file.Close();
 
             //settings = (List<Setting>)UnitySerializer.DeserializeFromFile (Application.persistentDataPath + "/SettingsData.dat");
             
             //Debug.Log("Data Loaded");
         }
         else
         {
             //Debug.Log("File not found Data not loaded");
         }
     }
 
     public bool SetAllDefaultLanguage(string sSelectedLanguage)
     {
         //Debug.Log("SetAllDefaultLanguage");
         foreach (Setting s in settings)
         {
             s.defaultlanguage = sSelectedLanguage;
         }
         //(from s in settings where s.defaultlanguage == "*" select s).First().defaultlanguage = sSelectedLanguage;
 
         return true;
     }
     
     
     public bool SettingExists(string Language)
     {
         return settings.Exists(myObj => myObj.Language == Language );
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by CorwinOfAmberX · Aug 06, 2014 at 02:08 PM

Changing my answer from before it seems that your approach with the path is correct.

T$$anonymous$$s leaves two suspects that I can see:

  1. The serializer usage of the binary - I have encountered problems with that in the past.

  2. The reflection of the list of structures.

I am sorry I cannot help more - I attach below a simple code that works for me with a single structure:

     public void SaveXML()
     {
         string            localfileLocation = GetFilePathAndName();
 
         // Initialize
         Debug.Log("-------------------------------- About to Save Data File (" + localfileLocation + ") --------------------------------");
         
         XmlSerializer     serializer = new XmlSerializer(typeof(ApplicationData));
 
 //        Debug.Log("-------------------------------- About to Create Data File --------------------------------");
         //        FileStream file = File.Create( localfileLocation );
         FileStream file = new FileStream( localfileLocation, FileMode.Create );
         
         // Write Data
 //        Debug.Log("-------------------------------- About to Serialize Data File --------------------------------");
         serializer.Serialize( file, ApplicationSavedData );
 
         file.Close ();
 }





Comment
Add comment · Show 2 · 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
avatar image magonicolas · Jan 06, 2015 at 04:36 PM 0
Share
avatar image CorwinOfAmberX · Jan 06, 2015 at 05:19 PM 0
Share

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Does PersistentDataPath get overwritten on mobile? 1 Answer

Prevent users from opening external data files 2 Answers

Mobile game data server sync architecture using changesets. 1 Answer

Save data in Single-Player 1 Answer

Saving and Loading and assinging to gameobject 0 Answers


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