Beispiel #1
0
        public override void SaveRequest(Storage storage)
        {
            RuntimePersistence runtime = new RuntimePersistence();

            runtime.countHistory = _countHistory;
            runtime.instances    = new RuntimeInstance[_spawnedInstances.Count];

            int iterator = 0;

            foreach (RuntimeInstance instance in _spawnedInstances.Values)
            {
                runtime.instances[iterator] = instance;
                iterator++;
            }

            string jsonData = JsonUtility.ToJson(runtime, true);

            storage.UpdateData(StorageConstants.STORAGE_SCENE_PREFIX + StorageConstants.STORAGE_SEPARATOR_GUID + _guid.GetGuid, jsonData, _guid.GetInformation);
        }
Beispiel #2
0
        public override void LoadRequest(Storage storage)
        {
            string key  = string.Format(StorageConstants.STORAGE_SCENE_PREFIX + StorageConstants.STORAGE_SEPARATOR_GUID + _guid.GetGuid);
            string data = storage.GetData(key);

            if (data != null)
            {
                try
                {
                    RuntimePersistence persistence = JsonUtility.FromJson <RuntimePersistence>(data);
                    if (persistence == null || persistence.instances.Length <= 0)
                    {
                        return;
                    }

                    _countHistory = persistence.countHistory;

                    for (var i = 0; i < persistence.instances.Length; i++)
                    {
                        RuntimeInstance instance = persistence.instances[i];

                        if (_loadedRuntimeInstances.Contains(instance.guid))
                        {
                            continue;
                        }

                        RuntimeSource source = instance.source;
                        string        path   = instance.path;
                        string        guid   = instance.guid;

                        StorableRuntimeInstance spawnedInstance = SpawnRuntimeInstance(source, path, guid);
                        _spawnedInstances.Add(spawnedInstance, instance);
                        _countHistory++;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("StorageScene == LoadRequest -- Json is not valid as RuntimePersistence : " + data);
                    throw;
                }
            }
        }