Ejemplo n.º 1
0
        public void SaveWorld()
        {
            string filePath = MenuConsts.Instance.GetSaveFilePath(Settings.Name);

            using (MyData.JSONWriter writer = new MyData.JSONWriter(filePath))
            {
                try
                {
                    writer.Structure(Progress, "progress");
                    writer.Structure(Map, "map");
                    writer.Structure(Settings, "worldSettings");
                }
                catch (MyData.Writer.WriteException e)
                {
                    Debug.LogError("Unable to save " + filePath + ": " + e.Message);
                }
            }
        }
Ejemplo n.º 2
0
        private Consts()
        {
            //Try to read the constants from a file.
            const string fileName = "GroupConsts.consts";
            string       filePath = Path.Combine(Application.dataPath, fileName);

            if (File.Exists(filePath))
            {
                try
                {
                    MyData.JSONReader reader = new MyData.JSONReader(filePath);
                    reader.Structure(this, "consts");
                }
                catch (MyData.Reader.ReadException e)
                {
                    Debug.LogError("Error reading data file \"" + filePath + "\": " +
                                   e.Message + "||" + e.StackTrace);
                }
            }
            //If we're in a standalone build and the file doesn't exist, create it.
            else if (!Application.isEditor)
            {
                MyData.JSONWriter writer = null;
                try
                {
                    writer = new MyData.JSONWriter(filePath);
                    writer.Structure(this, "consts");
                }
                catch (MyData.Writer.WriteException e)
                {
                    Debug.LogError("Error writing data file \"" + filePath + "\": " +
                                   e.Message + "||" + e.StackTrace);
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Dispose();
                    }
                }
            }

            instance = this;
        }