/// <summary>
        /// Saves a value to the data store.
        /// </summary>
        /// <param name="name"> The name of the object to save.</param>
        /// <param name="value">The value to save.</param>
        protected static void SaveValue <T>(string name, T value)
        {
            var json = new JsonFactory <T>();

            PlayerPrefs.SetString(MakeID(name), json.ToString(value));

            var names = NameList;

            if (!names.Contains(name))
            {
                var n = names.ToList();
                n.Add(name);
                NameList = n.ToArray();
            }

            PlayerPrefs.Save();
        }
Exemple #2
0
        /// <summary>
        /// If the time between reports has elapsed, retrieve a new GPS report, saving the results to
        /// PlayerPrefs and firing the <see cref="onPositionUpdated"/> and <see
        /// cref="PositionUpdated"/> events if one is found.
        /// </summary>
        public void Update()
        {
            if (!startingTask.IsRunning())
            {
                if (startingTask != null)
                {
                    if (startingTask.IsFaulted)
                    {
                        enabled = false;
                    }
                    else
                    {
                        startingTask = null;
                    }
                }

                if (UseFakeCoord != lastUseFakeCoord)
                {
                    UnityInput.compass.enabled = !UseFakeCoord;
                }

                lastUseFakeCoord = UseFakeCoord;

                if (Status == LocationServiceStatus.Running &&
                    !UseFakeCoord &&
                    Time.unscaledTime >= nextUpdateTime)
                {
                    nextUpdateTime += timeBetweenUpdates;
                    var newLocation = Location.lastData;
                    if (newLocation.timestamp > lastLocation.timestamp)
                    {
                        Coord = new LatLngPoint(newLocation.latitude, newLocation.longitude, newLocation.altitude);
                        PlayerPrefs.SetString(COORD_KEY, coordFactory.ToString(Coord));
                        lastLocation = newLocation;
                        OnPositionUpdated();
                    }
                }
            }

            if (DebugReport)
            {
                PrintDebugReport();
            }
        }