public static void Load() { using (ProfilingUtility.SampleBlock("Load Icons")) { Language.Load(); } }
public static EditorTexture Load(IResourceProvider resources, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); Ensure.That(nameof(resolutions)).HasItems(resolutions); var set = new EditorTexture(); var name = Path.GetFileNameWithoutExtension(path).PartBefore('@'); var extension = Path.GetExtension(path); var directory = Path.GetDirectoryName(path); // Try with explicit resolutions first foreach (var resolution in resolutions) { var width = resolution.width; // var height = resolution.height; var personalPath = Path.Combine(directory, $"{name}@{width}x{extension}"); var professionalPath = Path.Combine(directory, $"{name}@{width}x_Pro{extension}"); if (resources.FileExists(personalPath)) { set.personal.Add(width, resources.LoadTexture(personalPath, options)); } if (resources.FileExists(professionalPath)) { set.professional.Add(width, resources.LoadTexture(professionalPath, options)); } } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } return(set); } }
public static void UpdateSettings() { using (ProfilingUtility.SampleBlock("Codebase settings update")) { _settingsAssemblies = new List <Assembly>(); _settingsAssembliesTypes = new List <Type>(); _settingsTypes = new List <Type>(); foreach (var assembly in _assemblies) { var couldHaveIncludeInSettingsAttribute = ludiqAssemblies.Contains(assembly); // It's important not to provide types outside the settings assemblies, // because only those assemblies will be added to the linker to preserve stripping. if (IncludeInSettings(assembly)) { _settingsAssemblies.Add(assembly); foreach (var type in assembly.GetTypesSafely()) { // Apparently void can be returned somehow: // http://support.ludiq.io/topics/483 if (type == typeof(void)) { continue; } _settingsAssembliesTypes.Add(type); // For optimization, we bypass [IncludeInSettings] for assemblies // that could logically never have it. if (IncludeInSettings(type, couldHaveIncludeInSettingsAttribute)) { _settingsTypes.Add(type); } } } } settingsAssemblies = _settingsAssemblies.AsReadOnly(); settingsAssembliesTypes = _settingsAssembliesTypes.AsReadOnly(); settingsTypes = _settingsTypes.AsReadOnly(); settingsChanged?.Invoke(); } }
public static EditorTexture Load(IResourceProvider resources, string path, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); var set = new EditorTexture(); var name = Path.GetFileNameWithoutExtension(path).PartBefore('@'); var extension = Path.GetExtension(path); var directory = Path.GetDirectoryName(path); var personalPath = Path.Combine(directory, $"{name}{extension}"); var professionalPath = Path.Combine(directory, $"{name}@Pro{extension}"); var texture = resources.LoadTexture(personalPath, options); if (texture != null) { set.personal.Add(texture.width, texture); } texture = resources.LoadTexture(professionalPath, options); if (texture != null) { set.professional.Add(texture.width, texture); } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } return(set); } }
private static void DeserializeJson(fsSerializer serializer, string json, ref object instance, bool forceReflected) { using (ProfilingUtility.SampleBlock("DeserializeJson")) { var fsData = fsJsonParser.Parse(json); fsResult result; if (forceReflected) { result = serializer.TryDeserialize(fsData, instance.GetType(), typeof(fsReflectedConverter), ref instance); } else { result = serializer.TryDeserialize(fsData, ref instance); } HandleResult("Deserialization", result, instance as UnityObject); } }
private static string SerializeJson(fsSerializer serializer, object instance, bool forceReflected) { using (ProfilingUtility.SampleBlock("SerializeJson")) { fsData data; fsResult result; if (forceReflected) { result = serializer.TrySerialize(instance.GetType(), typeof(fsReflectedConverter), instance, out data); } else { result = serializer.TrySerialize(instance, out data); } HandleResult("Serialization", result, instance as UnityObject); return(fsJsonPrinter.CompressedJson(data)); } }
static Codebase() { using (ProfilingUtility.SampleBlock("Codebase initialization")) { _assemblies = new List <Assembly>(); _runtimeAssemblies = new List <Assembly>(); _editorAssemblies = new List <Assembly>(); _ludiqAssemblies = new List <Assembly>(); _ludiqRuntimeAssemblies = new List <Assembly>(); _ludiqEditorAssemblies = new List <Assembly>(); _types = new List <Type>(); _runtimeTypes = new List <Type>(); _editorTypes = new List <Type>(); _ludiqTypes = new List <Type>(); _ludiqRuntimeTypes = new List <Type>(); _ludiqEditorTypes = new List <Type>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { #if NET_4_6 if (assembly.IsDynamic) { continue; } #endif _assemblies.Add(assembly); var isRuntimeAssembly = IsRuntimeAssembly(assembly); var isEditorAssembly = IsEditorDependentAssembly(assembly); var isLudiqAssembly = IsLudiqRuntimeDependentAssembly(assembly) || IsLudiqEditorDependentAssembly(assembly); var isLudiqEditorAssembly = IsLudiqEditorDependentAssembly(assembly); var isLudiqRuntimeAssembly = IsLudiqRuntimeDependentAssembly(assembly) && !IsLudiqEditorDependentAssembly(assembly); if (isRuntimeAssembly) { _runtimeAssemblies.Add(assembly); } if (isEditorAssembly) { _editorAssemblies.Add(assembly); } if (isLudiqAssembly) { _ludiqAssemblies.Add(assembly); } if (isLudiqEditorAssembly) { _ludiqEditorAssemblies.Add(assembly); } if (isLudiqRuntimeAssembly) { _ludiqRuntimeAssemblies.Add(assembly); } foreach (var type in assembly.GetTypesSafely()) { _types.Add(type); RuntimeCodebase.PrewarmTypeDeserialization(type); if (isRuntimeAssembly) { _runtimeTypes.Add(type); } if (isEditorAssembly) { _editorTypes.Add(type); } if (isLudiqAssembly) { _ludiqTypes.Add(type); } if (isLudiqEditorAssembly) { _ludiqEditorTypes.Add(type); } if (isLudiqRuntimeAssembly) { _ludiqRuntimeTypes.Add(type); } } } catch (Exception ex) { Debug.LogWarning($"Failed to analyze assembly '{assembly}':\n{ex}"); } } assemblies = _assemblies.AsReadOnly(); runtimeAssemblies = _runtimeAssemblies.AsReadOnly(); editorAssemblies = _editorAssemblies.AsReadOnly(); ludiqAssemblies = _ludiqAssemblies.AsReadOnly(); ludiqRuntimeAssemblies = _ludiqRuntimeAssemblies.AsReadOnly(); ludiqEditorAssemblies = _ludiqEditorAssemblies.AsReadOnly(); types = _types.AsReadOnly(); runtimeTypes = _runtimeTypes.AsReadOnly(); editorTypes = _editorTypes.AsReadOnly(); ludiqTypes = _ludiqTypes.AsReadOnly(); ludiqRuntimeTypes = _ludiqRuntimeTypes.AsReadOnly(); ludiqEditorTypes = _ludiqEditorTypes.AsReadOnly(); } }
internal static void Initialize() { EditorApplication.delayCall -= initializeCallbackFunction; using (ProfilingUtility.SampleBlock("Plugin Container Initialization")) { initializing = true; pluginTypesById = Codebase.ludiqEditorTypes .Where(t => typeof(Plugin).IsAssignableFrom(t) && t.IsConcrete()) .ToDictionary(GetPluginID); pluginDependencies = new Dictionary <string, HashSet <string> >(); foreach (var pluginTypeById in pluginTypesById) { pluginDependencies.Add(pluginTypeById.Key, pluginTypeById.Value.GetAttributes <PluginDependencyAttribute>().Select(pda => pda.id).ToHashSet()); } var moduleTypes = Codebase.ludiqEditorTypes .Where(t => typeof(IPluginModule).IsAssignableFrom(t) && t.HasAttribute <PluginModuleAttribute>(false)) .OrderByDependencies(t => t.GetAttributes <PluginModuleDependencyAttribute>().Select(pmda => pmda.moduleType)) .ToArray(); pluginsById = new Dictionary <string, Plugin>(); var allModules = new List <IPluginModule>(); foreach (var pluginId in pluginTypesById.Keys.OrderByDependencies(pluginId => pluginDependencies[pluginId])) { var pluginType = pluginTypesById[pluginId]; Plugin plugin; try { using (ProfilingUtility.SampleBlock($"{pluginType.Name} (Instantiation)")) { plugin = (Plugin)pluginType.Instantiate(); } } catch (Exception ex) { throw new TargetInvocationException($"Could not instantiate plugin '{pluginId}' ('{pluginType.CSharpName()}').", ex); } var modules = new List <IPluginModule>(); foreach (var moduleType in moduleTypes) { try { var required = moduleType.GetAttribute <PluginModuleAttribute>(false).required; var moduleProperty = pluginType.GetProperties().FirstOrDefault(p => p.PropertyType.IsAssignableFrom(moduleType)); if (moduleProperty == null) { continue; } IPluginModule module = null; var moduleOverrideType = Codebase.ludiqEditorTypes .FirstOrDefault(t => moduleType.IsAssignableFrom(t) && t.IsConcrete() && t.HasAttribute <PluginAttribute>() && t.GetAttribute <PluginAttribute>().id == pluginId); if (moduleOverrideType != null) { try { using (ProfilingUtility.SampleBlock($"{moduleOverrideType.Name} (Instantiation)")) { module = (IPluginModule)InstantiateLinkedType(moduleOverrideType, plugin); } } catch (Exception ex) { throw new TargetInvocationException($"Failed to instantiate user-defined plugin module '{moduleOverrideType.CSharpName()}' for '{pluginId}'.", ex); } } else if (moduleType.IsConcrete()) { try { using (ProfilingUtility.SampleBlock($"{moduleType.Name} (Instantiation)")) { module = (IPluginModule)InstantiateLinkedType(moduleType, plugin); } } catch (Exception ex) { throw new TargetInvocationException($"Failed to instantiate built-in plugin module '{moduleType.CSharpName()}' for '{pluginId}'.", ex); } } else if (required) { throw new InvalidImplementationException($"Missing implementation of plugin module '{moduleType.CSharpName()}' for '{pluginId}'."); } if (module != null) { moduleProperty.SetValue(plugin, module, null); modules.Add(module); allModules.Add(module); } } catch (Exception ex) { Debug.LogException(ex); } } pluginsById.Add(plugin.id, plugin); foreach (var module in modules) { try { using (ProfilingUtility.SampleBlock($"{module.GetType().Name} (Initialization)")) { module.Initialize(); } } catch (Exception ex) { Debug.LogException(new Exception($"Failed to initialize plugin module '{plugin.id}.{module.GetType().CSharpName()}'.", ex)); } } if (plugin.manifest.versionMismatch) { anyVersionMismatch = true; } } initializing = false; initialized = true; foreach (var module in allModules) { try { using (ProfilingUtility.SampleBlock($"{module.GetType().Name} (Late Initialization)")) { module.LateInitialize(); } } catch (Exception ex) { Debug.LogException(new Exception($"Failed to late initialize plugin module '{module.plugin.id}.{module.GetType().CSharpName()}'.", ex)); } } var afterPluginTypes = Codebase.ludiqEditorTypes .Where(t => t.HasAttribute <InitializeAfterPluginsAttribute>()); using (ProfilingUtility.SampleBlock($"BeforeInitializeAfterPlugins")) { EditorApplicationUtility.BeforeInitializeAfterPlugins(); } foreach (var afterPluginType in afterPluginTypes) { using (ProfilingUtility.SampleBlock($"{afterPluginType.Name} (Static Initializer)")) { RuntimeHelpers.RunClassConstructor(afterPluginType.TypeHandle); } } using (ProfilingUtility.SampleBlock($"AfterInitializeAfterPlugins")) { EditorApplicationUtility.AfterInitializeAfterPlugins(); } using (ProfilingUtility.SampleBlock($"Delayed Calls")) { lock (delayQueue) { while (delayQueue.Count > 0) { delayQueue.Dequeue().Invoke(); } } } InternalEditorUtility.RepaintAllViews(); ProfilingUtility.Clear(); using (ProfilingUtility.SampleBlock($"Product Container Initialization")) { ProductContainer.Initialize(); } using (ProfilingUtility.SampleBlock($"Launch Setup Wizards")) { // Automatically show setup wizards if (!EditorApplication.isPlayingOrWillChangePlaymode) { var productsRequiringSetup = ProductContainer.products.Where(product => product.requiresSetup).ToHashSet(); var productsHandlingAllSetups = productsRequiringSetup.ToHashSet(); // Do not show product setups if another product already // includes all the same plugins or more. For example, // if both Bolt and Ludiq require setup, but Bolt requires // all of the Ludiq plugins, then only the Bolt setup wizard // should be shown. foreach (var product in productsRequiringSetup) { foreach (var otherProduct in productsRequiringSetup) { if (product == otherProduct) { continue; } var productPlugins = product.plugins.ResolveDependencies().ToHashSet(); var otherProductPlugins = otherProduct.plugins.ResolveDependencies().ToHashSet(); if (productPlugins.IsSubsetOf(otherProductPlugins)) { productsHandlingAllSetups.Remove(product); } } } foreach (var product in productsHandlingAllSetups) { // Delay call is used here to avoid showing multiple wizards during an import EditorApplication.delayCall += () => product.setupWizard.Show(); } } } using (ProfilingUtility.SampleBlock($"Launch Update Wizard")) { // Automatically show update wizard if (!EditorApplication.isPlayingOrWillChangePlaymode && plugins.Any(plugin => plugin.manifest.versionMismatch)) { // Delay call seems to be needed here to avoid arcane exceptions... // Too lazy to debug why, it works that way. EditorApplication.delayCall += () => UpdateWizard.global.Show(); } } } }