private static void scanForInstance() { var allAssets = AssetDatabase.LoadAllAssetsAtPath(projectSettingsAssetPath); LabkitProjectSettings settings = null; bool newSettings = allAssets.Length == 0; if (newSettings) { string tempAssetPath = AssetDatabase.GenerateUniqueAssetPath("Assets/Labkit Settings.asset"); AssetDatabase.CreateAsset(ScriptableObject.CreateInstance(typeof(LabkitProjectSettings)), tempAssetPath); if (File.Exists(projectSettingsAssetPath)) { File.Delete(projectSettingsAssetPath); } File.Move(tempAssetPath, projectSettingsAssetPath); AssetDatabase.Refresh(); allAssets = AssetDatabase.LoadAllAssetsAtPath(projectSettingsAssetPath); } if (allAssets.Length == 0) { throw new System.InvalidOperationException("Couldn't load or create settings asset"); } settings = allAssets[0] as LabkitProjectSettings; if (newSettings) { initializeNewSettings(settings); } LabkitProjectSettings.s_instance = settings; }
private static void initializeNewSettings(LabkitProjectSettings settings) { var vsCodePath = findVisualStudioCode(); if (vsCodePath != null) { settings.UseVisualStudioCode = true; } }
private static void OnLoad() { try { LabkitProjectSettings.scanForInstance(); } catch { } if (LabkitProjectSettings.s_instance != null) { LabkitProjectSettings.s_instance.ApplySettingsToProject(); } EditorApplication.update -= OnLoad; }