internal static void RegisterAll() { if (CoreFactories.< > f__mg$cache0 == null) { CoreFactories.< > f__mg$cache0 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateButton); } Factories.RegisterFactory <Button>(CoreFactories.< > f__mg$cache0); if (CoreFactories.< > f__mg$cache1 == null) { CoreFactories.< > f__mg$cache1 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateIMGUIContainer); } Factories.RegisterFactory <IMGUIContainer>(CoreFactories.< > f__mg$cache1); Factories.RegisterFactory <Image>((IUxmlAttributes _, CreationContext __) => new Image()); Factories.RegisterFactory <Label>((IUxmlAttributes _, CreationContext __) => new Label()); if (CoreFactories.< > f__mg$cache2 == null) { CoreFactories.< > f__mg$cache2 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateRepeatButton); } Factories.RegisterFactory <RepeatButton>(CoreFactories.< > f__mg$cache2); if (CoreFactories.< > f__mg$cache3 == null) { CoreFactories.< > f__mg$cache3 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateScrollerButton); } Factories.RegisterFactory <ScrollerButton>(CoreFactories.< > f__mg$cache3); Factories.RegisterFactory <ScrollView>((IUxmlAttributes _, CreationContext __) => new ScrollView()); if (CoreFactories.< > f__mg$cache4 == null) { CoreFactories.< > f__mg$cache4 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateScroller); } Factories.RegisterFactory <Scroller>(CoreFactories.< > f__mg$cache4); if (CoreFactories.< > f__mg$cache5 == null) { CoreFactories.< > f__mg$cache5 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateSlider); } Factories.RegisterFactory <Slider>(CoreFactories.< > f__mg$cache5); Factories.RegisterFactory <TextField>((IUxmlAttributes _, CreationContext __) => new TextField()); if (CoreFactories.< > f__mg$cache6 == null) { CoreFactories.< > f__mg$cache6 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateToggle); } Factories.RegisterFactory <Toggle>(CoreFactories.< > f__mg$cache6); Factories.RegisterFactory <VisualContainer>((IUxmlAttributes _, CreationContext __) => new VisualContainer()); Factories.RegisterFactory <VisualElement>((IUxmlAttributes _, CreationContext __) => new VisualElement()); if (CoreFactories.< > f__mg$cache7 == null) { CoreFactories.< > f__mg$cache7 = new Func <IUxmlAttributes, CreationContext, VisualElement>(CoreFactories.CreateTemplate); } Factories.RegisterFactory <TemplateContainer>(CoreFactories.< > f__mg$cache7); }
internal static void RegisterAll() { Factories.RegisterFactory <Button>(CreateButton); Factories.RegisterFactory <IMGUIContainer>(CreateIMGUIContainer); Factories.RegisterFactory <Image>((_, __) => new Image()); Factories.RegisterFactory <Label>((_, __) => new Label()); Factories.RegisterFactory <RepeatButton>(CreateRepeatButton); Factories.RegisterFactory <ScrollerButton>(CreateScrollerButton); Factories.RegisterFactory <ScrollView>((_, __) => new ScrollView()); Factories.RegisterFactory <Scroller>(CreateScroller); Factories.RegisterFactory <Slider>(CreateSlider); Factories.RegisterFactory <TextField>((_, __) => new TextField()); Factories.RegisterFactory <Toggle>(CreateToggle); Factories.RegisterFactory <VisualContainer>((_, __) => new VisualContainer()); Factories.RegisterFactory <VisualElement>((_, __) => new VisualElement()); Factories.RegisterFactory <TemplateContainer>(CreateTemplate); }
private static void DiscoverFactories() { if (Factories.s_Factories == null) { Factories.s_Factories = new Dictionary <string, Func <IUxmlAttributes, CreationContext, VisualElement> >(); CoreFactories.RegisterAll(); AppDomain currentDomain = AppDomain.CurrentDomain; HashSet <string> hashSet = new HashSet <string>(ScriptingRuntime.GetAllUserAssemblies()); Assembly[] assemblies = currentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { Assembly assembly = assemblies[i]; if (hashSet.Contains(assembly.GetName().Name + ".dll")) { try { Type[] types = assembly.GetTypes(); for (int j = 0; j < types.Length; j++) { Type type = types[j]; if (typeof(IUxmlFactory).IsAssignableFrom(type)) { IUxmlFactory uxmlFactory = (IUxmlFactory)Activator.CreateInstance(type); Factories.RegisterFactory(uxmlFactory.CreatesType.FullName, new Func <IUxmlAttributes, CreationContext, VisualElement>(uxmlFactory.Create)); } } } catch (TypeLoadException ex) { Debug.LogWarningFormat("Error while loading types from assembly {0}: {1}", new object[] { assembly.FullName, ex }); } } } } }
internal static void RegisterFactory <T>(Func <IUxmlAttributes, CreationContext, VisualElement> factory) where T : VisualElement { Factories.RegisterFactory(typeof(T).FullName, factory); }