예제 #1
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;
        }
예제 #2
0
        public void LoadWorld(string name)
        {
            if (mapGameCoroutine != null)
            {
                StopCoroutine(mapGameCoroutine);
            }
            mapGameCoroutine = null;

            isDeserializing = true;

            string filePath = MenuConsts.Instance.GetSaveFilePath(name);

            try
            {
                MyData.JSONReader reader = new MyData.JSONReader(filePath);

                reader.Structure(Progress, "progress");
                reader.Structure(Map, "map");
                reader.Structure(Settings, "worldSettings");
            }
            catch (MyData.Reader.ReadException e)
            {
                Debug.LogError("Unable to load " + filePath + ": " + e.Message);
            }

            isDeserializing = false;
            if (onDoneDeserializing != null)
            {
                onDoneDeserializing();
            }
            onDoneDeserializing = null;

            mapGameCoroutine = StartCoroutine(Map.RunGameCoroutine());

            if (OnStart != null)
            {
                OnStart();
            }
        }