Example #1
0
    /// <summary>
    /// Cleans up the entries in this statistics. This accounts for plans that have been deleted.
    /// </summary>
    public static void CleanUp()
    {
        var allPlans = UTils.AllVisibleAssetsOfType <UTAutomationPlan> ();

        var knownGuids = new HashSet <string> ();

        knownGuids.UnionWith(allPlans.ConvertAll(plan => plan.Guid));
        var       knownEntries = new List <StatEntry> ();
        var       i            = 0;
        StatEntry statEntry    = null;

        do
        {
            statEntry      = new StatEntry();
            statEntry.guid = EditorPrefs.GetString(PlanPrefix + i, "");
            if (!string.IsNullOrEmpty(statEntry.guid))
            {
                statEntry.project      = EditorPrefs.GetString(PlanPrefix + i + ".project", "");
                statEntry.lastModified = FromString(EditorPrefs.GetString(PlanPrefix + i + ".lastModified"));
                statEntry.time         = EditorPrefs.GetFloat(PlanPrefix + i + ".time", 0f);

                if (knownGuids.Contains(statEntry.guid))
                {
                    knownEntries.Add(statEntry);
                }
                else
                {
                    // not known, check if it's from this project
                    if (statEntry.project != Application.dataPath)
                    {
                        // different project, candidate for keeping it
                        var age = DateTime.Now - statEntry.lastModified;
                        if (age.TotalDays < 90)
                        {
                            // age is recent, keep it.
                            knownEntries.Add(statEntry);
                        }
                    }
                    // in all other cases, kill it.
                }


                EditorPrefs.DeleteKey(PlanPrefix + i);
                EditorPrefs.DeleteKey(PlanPrefix + i + ".time");
                EditorPrefs.DeleteKey(PlanPrefix + i + ".project");
                EditorPrefs.DeleteKey(PlanPrefix + i + ".lastModified");
            }
            i++;
        } while (!string.IsNullOrEmpty(statEntry.guid));

        i = 0;
        foreach (var entry in knownEntries)
        {
            EditorPrefs.SetString(PlanPrefix + i, entry.guid);
            EditorPrefs.SetFloat(PlanPrefix + i + ".time", entry.time);
            EditorPrefs.SetString(PlanPrefix + i + ".project", entry.project);
            EditorPrefs.SetString(PlanPrefix + i + ".lastModified", ToString(entry.lastModified));
            i++;
        }
    }
Example #2
0
 public static List <UTAutomationPlan> AllUTAutomationPlans()
 {
     return(UTils.AllVisibleAssetsOfType <UTAutomationPlan> ());
 }