AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
EnforceEditorSettings.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using System.Globalization;
6 using UnityEngine;
7 using UnityEditor;
8 
9 namespace HoloToolkit.Unity
10 {
14  [InitializeOnLoad]
15  public class EnforceEditorSettings
16  {
17  private const string AssemblyReloadTimestampKey = "_HoloToolkit_Editor_LastAssemblyReload";
18 
19  static EnforceEditorSettings()
20  {
21  #region Editor Settings
22 
23  if (!IsNewEditorSession())
24  {
25  return;
26  }
27 
28  if (EditorSettings.serializationMode != SerializationMode.ForceText)
29  {
30  if (EditorUtility.DisplayDialog(
31  "Force Text Asset Serialization?",
32  "HoloToolkit is easier to maintain if the asset serialization mode for this project is set to \"Force Text\". Would you like to make this change?",
33  "Force Text Serialization",
34  "Later"))
35  {
36  EditorSettings.serializationMode = SerializationMode.ForceText;
37  Debug.Log("Setting Force Text Serialization");
38  }
39  }
40 
41  if (!EditorSettings.externalVersionControl.Equals("Visible Meta Files"))
42  {
43  if (EditorUtility.DisplayDialog(
44  "Make Meta Files Visible?",
45  "HoloToolkit would like to make meta files visible so they can be more easily handled with common version control systems. Would you like to make this change?",
46  "Enable Visible Meta Files",
47  "Later"))
48  {
49  EditorSettings.externalVersionControl = "Visible Meta Files";
50  Debug.Log("Updated external version control mode: " + EditorSettings.externalVersionControl);
51  }
52  }
53 
54  #endregion
55  }
56 
71  private static bool IsNewEditorSession()
72  {
73  // Determine the launch date for this editor session using the current time, and the time since startup.
74  DateTime thisLaunchDate = DateTime.UtcNow.AddSeconds(-EditorApplication.timeSinceStartup);
75 
76  // Determine the last known launch date of the editor by loading it from the PlayerPrefs cache.
77  // If no key exists set the time to this session.
78  string dateString = EditorPrefsUtility.GetEditorPref(AssemblyReloadTimestampKey, thisLaunchDate.ToString(CultureInfo.InvariantCulture));
79 
80  DateTime lastLaunchDate;
81  DateTime.TryParse(dateString, out lastLaunchDate);
82 
83  // If the current session was launched later than the last known session start date, then this must be
84  // a new session, and we can display the first-time prompt.
85  if ((thisLaunchDate - lastLaunchDate).Seconds > 0)
86  {
87  EditorPrefsUtility.SetEditorPref(AssemblyReloadTimestampKey, dateString);
88  return true;
89  }
90 
91  return false;
92  }
93  }
94 }
Sets Force Text Serialization and visible meta files in all projects that use the HoloToolkit...
static void SetEditorPref(string key, string value)
static string GetEditorPref(string key, string defaultValue)