public void GenerateProviderScripts() { if (Directory.Exists(LudiqCore.Paths.propertyProviders)) { foreach (var file in Directory.GetFiles(LudiqCore.Paths.propertyProviders)) { File.Delete(file); } } if (Directory.Exists(LudiqCore.Paths.propertyProvidersEditor)) { foreach (var file in Directory.GetFiles(LudiqCore.Paths.propertyProvidersEditor)) { File.Delete(file); } } PathUtility.CreateDirectoryIfNeeded(LudiqCore.Paths.propertyProviders); PathUtility.CreateDirectoryIfNeeded(LudiqCore.Paths.propertyProvidersEditor); foreach (var type in Codebase.ludiqTypes.Where(SerializedPropertyUtility.HasCustomDrawer)) { var directory = Codebase.IsEditorType(type) ? LudiqCore.Paths.propertyProvidersEditor : LudiqCore.Paths.propertyProviders; var path = Path.Combine(directory, GetProviderScriptName(type) + ".cs"); VersionControlUtility.Unlock(path); File.WriteAllText(path, GenerateProviderSource(type)); } AssetDatabase.Refresh(); }
internal static IEnumerable <Type> GetMappedTypes(Type type, string pluginId) { Ensure.That(nameof(type)).IsNotNull(type); // Too performance intensive, slowing down startup // Ensure.That(nameof(linkedType)).IsOfType<IPluginLinked>(linkedType); return(Codebase.GetTypeRegistrations <MapToPluginAttribute>().Where(r => r.pluginId == pluginId && type.IsAssignableFrom(r.type) && r.type.IsConcrete()).Select(r => r.type)); }
public MemberOptionTree(IEnumerable <Type> types, MemberFilter memberFilter, TypeFilter memberTypeFilter, MemberAction action) : base(new GUIContent("Member")) { favorites = new Favorites(this); codebase = Codebase.Subset(types, memberFilter.Configured(), memberTypeFilter?.Configured()); this.action = action; this.types = types; this.memberFilter = memberFilter; this.memberTypeFilter = memberTypeFilter; expectingBoolean = memberTypeFilter?.ExpectsBoolean ?? false; }
internal static void Initialize() { initializing = true; productTypesById = Codebase.GetTypeRegistrations <RegisterProductAttribute>().ToDictionary(r => r.id, r => r.type); var productIdsByPluginType = Codebase.GetTypeRegistrations <MapToProductAttribute>().ToDictionary(r => r.type, r => r.productId); productsById = new Dictionary <string, Product>(); foreach (var productTypeById in productTypesById) { var productId = productTypeById.Key; var productType = productTypeById.Value; Product product; try { product = (Product)productType.Instantiate(); } catch (Exception ex) { throw new TargetInvocationException($"Could not instantiate product '{productId}' ('{productType.CSharpName()}').", ex); } foreach (var plugin in PluginContainer.plugins) { if (productIdsByPluginType.TryGetValue(plugin.GetType(), out var pluginProductId) && productId == pluginProductId) { product._plugins.Add(plugin); } } productsById.Add(productId, product); } foreach (var product in products) { try { product.Initialize(); } catch (Exception ex) { Debug.LogException(new Exception($"Failed to initialize product '{product.id}'.", ex)); } } initializing = false; initialized = true; }
static BackgroundWorker() { try { AsyncProgressBarType = typeof(EditorWindow).Assembly.GetType("UnityEditor.AsyncProgressBar", true); AsyncProgressBar_Display = AsyncProgressBarType.GetMethod("Display", BindingFlags.Static | BindingFlags.Public); AsyncProgressBar_Clear = AsyncProgressBarType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public); if (AsyncProgressBar_Display == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Display"); } if (AsyncProgressBar_Clear == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Clear"); } } catch (Exception ex) { throw new UnityEditorInternalException(ex); } queue = new Queue <Action>(); ClearProgress(); foreach (var registration in Codebase.GetTypeRegistrations <RegisterBackgroundWorkerAttribute>()) { var backgroundWorkMethod = registration.type.GetMethod(registration.methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (backgroundWorkMethod != null) { tasks += () => backgroundWorkMethod.Invoke(null, new object[0]); } else { Debug.LogWarningFormat($"Missing '{registration.methodName}' method for '{registration.type}' background worker."); } } EditorApplication.update += DisplayProgress; EditorApplication.delayCall += delegate { new Thread(Work) { Name = "Background Worker" }.Start(); }; }
static BackgroundWorker() { queue = new Queue <Action>(); foreach (var registration in Codebase.GetTypeRegistrations <RegisterBackgroundWorkerAttribute>()) { var backgroundWorkMethod = registration.type.GetMethod(registration.methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (backgroundWorkMethod != null) { tasks += () => backgroundWorkMethod.Invoke(null, new object[0]); } else { Debug.LogWarningFormat($"Missing '{registration.methodName}' method for '{registration.type}' background worker."); } } EditorApplication.delayCall += delegate { new Thread(Work) { Name = "Background Worker" }.Start(); }; }
public override void Prewarm() { base.Prewarm(); codebase = Codebase.Subset(types, memberFilter.Configured(), memberTypeFilter?.Configured()); }
private static void Initialize() { using (ProfilingUtility.SampleBlock("Plugin Container Initialization")) { if (initialized || initializing) { Debug.LogWarning("Attempting to re-initialize plugin container, ignoring.\n"); return; } if (!isAssetDatabaseReliable) { Debug.LogWarning("Initializing plugin container while asset database is not initialized.\nLoading assets might fail!"); } initializing = true; pluginTypesById = Codebase.GetTypeRegistrations <RegisterPluginAttribute>() .ToDictionary(r => r.id, r => r.type); pluginDependencies = new Dictionary <string, HashSet <string> >(); foreach (var pluginId in pluginTypesById.Keys) { pluginDependencies.Add(pluginId, new HashSet <string>()); } foreach (var pluginDependencyRegistration in Codebase.GetAssemblyAttributes <RegisterPluginDependencyAttribute>()) { if (!pluginDependencies.TryGetValue(pluginDependencyRegistration.dependerId, out var dependencies)) { dependencies = new HashSet <string>(); pluginDependencies.Add(pluginDependencyRegistration.dependerId, dependencies); } dependencies.Add(pluginDependencyRegistration.dependencyId); } var moduleTypeRegistrations = Codebase.GetTypeRegistrations <RegisterPluginModuleTypeAttribute>(); 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}').", ex); } var modules = new List <IPluginModule>(); foreach (var moduleTypeRegistration in moduleTypeRegistrations) { var moduleType = moduleTypeRegistration.type; var required = moduleTypeRegistration.required; try { var moduleProperty = pluginType.GetProperties().FirstOrDefault(p => p.PropertyType.IsAssignableFrom(moduleType)); if (moduleProperty == null) { continue; } IPluginModule module = null; var moduleOverrideType = Codebase.GetTypeRegistrations <MapToPluginAttribute>() .FirstOrDefault(r => r.pluginId == pluginId && moduleType.IsAssignableFrom(r.type) && r.type.IsConcrete())?.type; if (moduleOverrideType != null) { try { using (ProfilingUtility.SampleBlock($"{moduleOverrideType.Name} (Instantiation)")) { module = (IPluginModule)InstantiateMappedType(moduleOverrideType, plugin); } } catch (Exception ex) { throw new TargetInvocationException($"Failed to instantiate user-defined plugin module '{moduleOverrideType}' for '{pluginId}'.", ex); } } else if (moduleType.IsConcrete()) { try { using (ProfilingUtility.SampleBlock($"{moduleType.Name} (Instantiation)")) { module = (IPluginModule)InstantiateMappedType(moduleType, plugin); } } catch (Exception ex) { throw new TargetInvocationException($"Failed to instantiate built-in plugin module '{moduleType}' for '{pluginId}'.", ex); } } else if (required) { throw new InvalidImplementationException($"Missing implementation of plugin module '{moduleType}' 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()}'.", ex)); } } if (plugin.manifest.versionMismatch) { anyVersionMismatch = true; } } initializing = false; initialized = true; using (ProfilingUtility.SampleBlock($"Product Container Initialization")) { ProductContainer.Initialize(); } 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()}'.", ex)); } } var afterPluginTypes = Codebase.GetRegisteredTypes <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($"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 += () => SetupWizard.Show(product); } } } 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.Show; } } using (ProfilingUtility.SampleBlock($"Delayed Calls")) { lock (delayQueue) { while (delayQueue.Count > 0) { delayQueue.Dequeue().Invoke(); } } } InternalEditorUtility.RepaintAllViews(); ProfilingUtility.Clear(); //ConsoleProfiler.Dump(); } }