AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ExtensionLoader.cs
Go to the documentation of this file.
1 using UnityEditor;
2 using UnityEngine;
3 using System.IO;
4 using System;
5 
6 namespace GitHub.Unity
7 {
8  [InitializeOnLoad]
9  public class ExtensionLoader : ScriptableSingleton<ExtensionLoader>
10  {
11  [SerializeField] private bool initialized = true;
12 
13  public bool Initialized
14  {
15  get
16  {
17  return initialized;
18  }
19  set
20  {
21  initialized = value;
22  Save(true);
23  }
24  }
25 
26  private static bool inSourceMode = false;
27  private const string sourceModePath = "Assets/Editor/build/";
28  private const string realPath = "Assets/Plugins/GitHub/Editor/";
29 
30  private static string[] assemblies20 = { "System.Threading.dll", "AsyncBridge.Net35.dll", "ReadOnlyCollectionsInterfaces.dll", "GitHub.Api.dll", "GitHub.Unity.dll" };
31  private static string[] assemblies45 = { "GitHub.Api.45.dll", "GitHub.Unity.45.dll" };
32 
33  private const string GITHUB_UNITY_DISABLE = "GITHUB_UNITY_DISABLE";
34  private static bool IsDisabled { get { return Environment.GetEnvironmentVariable(GITHUB_UNITY_DISABLE) == "1"; } }
35 
36  static ExtensionLoader()
37  {
38  if (IsDisabled)
39  {
40  return;
41  }
42  EditorApplication.update += Initialize;
43  }
44 
45  private static void Initialize()
46  {
47  EditorApplication.update -= Initialize;
48 
49  // we're always doing this right now because if the plugin gets updated all the meta files will be disabled and we need to re-enable them
50  // we should probably detect if our assets change and re-run this instead of doing it every time
51  //if (!ExtensionLoader.instance.Initialized)
52  {
53  var scriptPath = Path.Combine(Application.dataPath, "Editor" + Path.DirectorySeparatorChar + "GitHub.Unity" + Path.DirectorySeparatorChar + "EntryPoint.cs");
54  inSourceMode = File.Exists(scriptPath);
55  ToggleAssemblies();
56  //ExtensionLoader.instance.Initialized = true;
57  AssetDatabase.SaveAssets();
58  }
59 
60  }
61 
62  private static void ToggleAssemblies()
63  {
64  var path = inSourceMode ? sourceModePath : realPath;
65 #if NET_4_6
66  ToggleAssemblies(path, assemblies20, false);
67  ToggleAssemblies(path, assemblies45, true);
68 #else
69  ToggleAssemblies(path, assemblies45, false);
70  ToggleAssemblies(path, assemblies20, true);
71 #endif
72  }
73 
74  private static void ToggleAssemblies(string path, string[] assemblies, bool enable)
75  {
76  foreach (var file in assemblies)
77  {
78  var filepath = path + file;
79  PluginImporter importer = AssetImporter.GetAtPath(filepath) as PluginImporter;
80  if (importer == null)
81  {
82  Debug.LogFormat("GitHub for Unity: Could not find importer for {0}. Some functionality may fail.", filepath);
83  continue;
84  }
85  if (importer.GetCompatibleWithEditor() != enable)
86  {
87  importer.SetCompatibleWithEditor(enable);
88  importer.SaveAndReimport();
89  }
90  }
91  }
92  }
93 }