public override IEnumerator OnAfterGameLoad()
        {
            if (!inited)
            {
                Init();
            }

            var analyticsMemory = Game.Instance.GameState.GetMemory("analytics");

            if (analyticsMemory == null)
            {
                analyticsMemory = new Memory();
                Game.Instance.GameState.SetMemory("analytics", analyticsMemory);
            }
            else
            {
                CompletablesController.RestoreCompletables(analyticsMemory);
            }

            if (AutoStart)
            {
                // Get the tracker config from the game settings
                var trackerConfigs = Game.Instance.GameState.Data.getObjects <TrackerConfig>();
                trackerConfig = trackerConfigs.Count == 0 ? new TrackerConfig() : trackerConfigs[0];

                yield return(StartCoroutine(StartTracker(trackerConfig)));
                // TODO wait till start tracker is ready
            }
        }
コード例 #2
0
 private bool VerifyControllers(CompletablesController restoredCompletables)
 {
     return(restoredCompletables.Count == completables.Count &&
            restoredCompletables
            .Select((c, i) => new { c, i })
            .All(r => r.c.ProgressControllers.Count == completables[r.i].getProgress().getMilestones().Count));
 }
コード例 #3
0
        public override void OnAfterGameLoad()
        {
            if (!inited)
            {
                Init();
            }

            var analyticsMemory = Game.Instance.GameState.GetMemory("analytics");

            if (analyticsMemory == null)
            {
                analyticsMemory = new Memory();
                Game.Instance.GameState.SetMemory("analytics", analyticsMemory);
            }
            else
            {
                CompletablesController.RestoreCompletables(analyticsMemory);
            }

            if (AutoStart)
            {
                // Get the tracker config from the game settings
                var trackerConfigs = Game.Instance.GameState.Data.getObjects <TrackerConfig>();
                trackerConfig = trackerConfigs.Count == 0 ? new TrackerConfig() : trackerConfigs[0];

                StartTracker(trackerConfig);
            }
        }
        public void Init()
        {
            if (inited)
            {
                return;
            }

            inited = true;

            CompletablesController = new CompletablesController();
        }
コード例 #5
0
        public void RestoreCompletables(Memory analyticsMemory)
        {
            try
            {
                var serializedCompletables = analyticsMemory.Get <string>("completables");
                if (!string.IsNullOrEmpty(serializedCompletables))
                {
                    CompletablesController restoredCompletables;
                    if (serializedCompletables[0] == '{')
                    {
                        restoredCompletables = (CompletablesController)JsonUtility.FromJson(serializedCompletables, typeof(CompletablesController));
                    }
                    else
                    {
                        restoredCompletables = new CompletablesController();
                        restoredCompletables.AddRange(DeserializeFromString <List <CompletableController> >(serializedCompletables));
                    }

                    // Disable the hooks
                    restoredCompletables.Dispose();

                    if (!VerifyControllers(restoredCompletables))
                    {
                        throw new System.Exception("The saved completable controllers didn't match the current completables. The save is ignored.");
                    }

                    this.Clear();
                    this.AddRange(restoredCompletables);

                    for (int i = 0; i < this.Count; i++)
                    {
                        this[i].SetCompletable(this.completables[i]);
                        this[i].Start.SetMilestone(this.completables[i].getStart());
                        this[i].End.SetMilestone(this.completables[i].getEnd());
                        for (int j = 0; j < this.completables[i].getProgress().getMilestones().Count; j++)
                        {
                            this[i].ProgressControllers[j].SetMilestone(this.completables[i].getProgress().getMilestones()[j]);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error parsing the completables: " + ex.Message + " " + ex.StackTrace);
            }
        }