コード例 #1
0
        public VisualElement Create(CreationContext ctx)
        {
            Func <IUxmlAttributes, CreationContext, VisualElement> factory;

            if (!Factories.TryGetValue(fullTypeName, out factory))
            {
                Debug.LogErrorFormat("Visual Element Type '{0}' has no factory method.", fullTypeName);
                return(new Label(string.Format("Unknown type: '{0}'", fullTypeName)));
            }

            if (factory == null)
            {
                Debug.LogErrorFormat("Visual Element Type '{0}' has a null factory method.", fullTypeName);
                return(new Label(string.Format("Type with no factory method: '{0}'", fullTypeName)));
            }

            VisualElement res = factory(this, ctx);

            if (res == null)
            {
                Debug.LogErrorFormat("The factory of Visual Element Type '{0}' has returned a null object", fullTypeName);
                return(new Label(string.Format("The factory of Visual Element Type '{0}' has returned a null object", fullTypeName)));
            }
            res.name = name;

            if (classes != null)
            {
                for (int i = 0; i < classes.Length; i++)
                {
                    res.AddToClassList(classes[i]);
                }
            }

            if (stylesheets != null)
            {
                for (int i = 0; i < stylesheets.Count; i++)
                {
                    res.AddStyleSheetPath(stylesheets[i]);
                }
            }

            var textEle = res as BaseTextElement;

            if (textEle != null && !string.IsNullOrEmpty(text))
            {
                textEle.text = text;
            }

            res.pickingMode = pickingMode;

            return(res);
        }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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
                     });
                 }
             }
         }
     }
 }
コード例 #5
0
 internal static bool TryGetValue(string fullTypeName, out Func <IUxmlAttributes, CreationContext, VisualElement> factory)
 {
     Factories.DiscoverFactories();
     factory = null;
     return(Factories.s_Factories != null && Factories.s_Factories.TryGetValue(fullTypeName, out factory));
 }
コード例 #6
0
 internal static void RegisterFactory <T>(Func <IUxmlAttributes, CreationContext, VisualElement> factory) where T : VisualElement
 {
     Factories.RegisterFactory(typeof(T).FullName, factory);
 }
コード例 #7
0
 internal static void RegisterFactory(string fullTypeName, Func <IUxmlAttributes, CreationContext, VisualElement> factory)
 {
     Factories.DiscoverFactories();
     Factories.s_Factories.Add(fullTypeName, factory);
 }