コード例 #1
0
        public static List <UxmlAttributeDescription> GetAttributeDescriptions(this VisualElement ve)
        {
            var attributeList     = new List <UxmlAttributeDescription>();
            var uxmlQualifiedName = GetUxmlQualifiedName(ve);

            if (!VisualElementFactoryRegistry.TryGetValue(uxmlQualifiedName, out var factoryList))
            {
                return(attributeList);
            }

            foreach (IUxmlFactory f in factoryList)
            {
                foreach (var a in f.uxmlAttributesDescription)
                {
                    if (s_SkippedAttributeNames.Contains(a.name))
                    {
                        continue;
                    }

                    attributeList.Add(a);
                }
            }

            return(attributeList);
        }
コード例 #2
0
        public static List <UxmlAttributeDescription> GetAttributeDescriptions(this VisualElement ve)
        {
            var attributeList     = new List <UxmlAttributeDescription>();
            var uxmlQualifiedName = GetUxmlQualifiedName(ve);

            if (!VisualElementFactoryRegistry.TryGetValue(uxmlQualifiedName, out var factoryList))
            {
                return(attributeList);
            }

            foreach (IUxmlFactory f in factoryList)
            {
                // For user created types, they may return null for uxmlAttributeDescription, so we need to check in order not to crash.
                if (f.uxmlAttributesDescription != null)
                {
                    foreach (var a in f.uxmlAttributesDescription)
                    {
                        // For user created types, they may `yield return null` which would create an array with a null, so we need
                        // to check in order not to crash.
                        if (a == null || s_SkippedAttributeNames.Contains(a.name))
                        {
                            continue;
                        }

                        attributeList.Add(a);
                    }
                }
            }

            return(attributeList);
        }
コード例 #3
0
        static PackageManagerUXMLFactories()
        {
            if (k_Registered)
            {
                return;
            }

            k_Registered = true;

            IUxmlFactory[] factories =
            {
                new Alert.UxmlFactory(),
                new ArrowToggle.UxmlFactory(),
                new DropdownButton.UxmlFactory(),
                new LoadingSpinner.UxmlFactory(),
                new PackageDependencies.UxmlFactory(),
                new PackageDetails.UxmlFactory(),
                new PackageItem.UxmlFactory(),
                new PackageList.UxmlFactory(),
                new PackageLoadBar.UxmlFactory(),
                new PackageManagerToolbar.UxmlFactory(),
                new PackageSampleList.UxmlFactory(),
                new PackageStatusBar.UxmlFactory(),
                new PackageToolbar.UxmlFactory(),
                new ProgressBar.UxmlFactory(),
                new SplitView.UxmlFactory()
            };

            foreach (IUxmlFactory factory in factories)
            {
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }
        }
コード例 #4
0
        static PackageManagerUXMLFactories()
        {
            if (k_Registered)
            {
                return;
            }

            k_Registered = true;

            IUxmlFactory[] factories =
            {
                new Alert.UxmlFactory(),
                new ArrowToggle.UxmlFactory(),
                new LoadingSpinner.UxmlFactory(),
                new PackageAddFromIdField.UxmlFactory(),
                new PackageAddFromUrlField.UxmlFactory(),
                new PackageDependencies.UxmlFactory(),
                new PackageDetails.UxmlFactory(),
                new PackageGroup.UxmlFactory(),
                new PackageItem.UxmlFactory(),
                new PackageList.UxmlFactory(),
                new PackageManagerToolbar.UxmlFactory(),
                new PackageSampleList.UxmlFactory(),
                new PackageSearchToolbar.UxmlFactory(),
                new PackageStatusBar.UxmlFactory(),
                new PackageToolbar.UxmlFactory(),
            };

            foreach (IUxmlFactory factory in factories)
            {
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }
        }
コード例 #5
0
        void CallInitOnElement()
        {
            var attributeList = new List <UxmlAttributeDescription>();
            var fullTypeName  = currentVisualElement.GetType().ToString();
            List <IUxmlFactory> factoryList;

            if (VisualElementFactoryRegistry.TryGetValue(fullTypeName, out factoryList))
            {
                var factory     = factoryList[0];
                var traitsField = factory.GetType().GetField("m_Traits", BindingFlags.Instance | BindingFlags.NonPublic);
                if (traitsField == null)
                {
                    Debug.LogError("UI Builder: IUxmlFactory.m_Traits field has not been found! Update the reflection code!");
                    return;
                }

                var traitObj = traitsField.GetValue(factory);
                var trait    = traitObj as UxmlTraits;

                var context = new CreationContext();
                var vea     = currentVisualElement.GetVisualElementAsset();

                try
                {
                    trait.Init(currentVisualElement, vea, context);
                }
                catch
                {
                    // HACK: This throws in 2019.3.0a4 because usageHints property throws when set after the element has already been added to the panel.
                }
            }
        }
コード例 #6
0
        // Called from native code when preparing assets for a build
        public static List <Type> ExtractTypesFromVisualTreeAsset(VisualTreeAsset asset)
        {
            if (s_PrecompiledUnityAssemblies == null)
            {
                // Ignore all precompiled Unity assemblies, but include those from users
                CompilationPipeline.PrecompiledAssemblySources sources = CompilationPipeline.PrecompiledAssemblySources.All;
                sources &= ~CompilationPipeline.PrecompiledAssemblySources.UserAssembly;
                s_PrecompiledUnityAssemblies = new HashSet <string>(CompilationPipeline.GetPrecompiledAssemblyPaths(sources));
            }

            s_FactoryTypesUsedInAsset.Clear();
            s_UsedTypesInsideAsset.Clear();

            asset.ExtractUsedUxmlQualifiedNames(s_UsedTypesInsideAsset);

            foreach (var qualifiedName in s_UsedTypesInsideAsset)
            {
                if (VisualElementFactoryRegistry.TryGetValue(qualifiedName, out List <IUxmlFactory> factoryList))
                {
                    foreach (var factory in factoryList)
                    {
                        var type = factory.GetType();

                        if (s_PrecompiledUnityAssemblies.Contains(type.Assembly.Location))
                        {
                            continue;
                        }

                        s_FactoryTypesUsedInAsset.Add(type);
                    }
                }
            }

            return(s_FactoryTypesUsedInAsset);
        }
コード例 #7
0
        public static List <UxmlAttributeDescription> GetAttributeDescriptions(this VisualElement ve)
        {
            var attributeList = new List <UxmlAttributeDescription>();

            var fullTypeName = ve.GetType().ToString();
            List <IUxmlFactory> factoryList;

            if (!VisualElementFactoryRegistry.TryGetValue(fullTypeName, out factoryList))
            {
                return(attributeList);
            }

            foreach (IUxmlFactory f in factoryList)
            {
                foreach (var a in f.uxmlAttributesDescription)
                {
                    if (s_SkippedAttributeNames.Contains(a.name))
                    {
                        continue;
                    }

                    attributeList.Add(a);
                }
            }

            return(attributeList);
        }
コード例 #8
0
        static BuilderUXMLEditorFactories()
        {
            if (k_Registered)
            {
                return;
            }

            k_Registered = true;

            IUxmlFactory[] factories =
            {
                new BuilderPane.UxmlFactory(),
                new BuilderNewSelectorField.UxmlFactory(),
                new BuilderStyleRow.UxmlFactory(),
                new BuilderAnchorer.UxmlFactory(),
                new BuilderMover.UxmlFactory(),
                new BuilderParentTracker.UxmlFactory(),
                new BuilderResizer.UxmlFactory(),
                new BuilderSelectionIndicator.UxmlFactory(),
                new BuilderCanvasStyleControls.UxmlFactory(),
                new BuilderTooltipPreview.UxmlFactory(),
                new BuilderCanvas.UxmlFactory(),
                new BuilderNotifications.UxmlFactory(),
                new CheckerboardBackground.UxmlFactory(),
                new OverlayPainterHelperElement.UxmlFactory(),
                new FoldoutField.UxmlFactory(),
                new FoldoutColorField.UxmlFactory(),
                new FoldoutNumberField.UxmlFactory(),
                new FoldoutWithCheckbox.UxmlFactory(),
                new FontStyleStrip.UxmlFactory(),
                new HelpBox.UxmlFactory(),
                new LibraryFoldout.UxmlFactory(),
                new ModalPopup.UxmlFactory(),
                new PercentSlider.UxmlFactory(),
                new PersistedFoldout.UxmlFactory(),
                new BuilderAttributesTestElement.UxmlFactory(),
                new BuilderPlacementIndicator.UxmlFactory(),
                new DimensionStyleField.UxmlFactory(),
                new ImageStyleField.UxmlFactory(),
                new NumericStyleField.UxmlFactory(),
                new IntegerStyleField.UxmlFactory(),
                new TextAlignStrip.UxmlFactory(),
                new TextShadowStyleField.UxmlFactory(),
                new ToggleButtonStrip.UxmlFactory(),
                new TwoPaneSplitView.UxmlFactory(),
                new UnityUIBuilderSelectionMarker.UxmlFactory()
            };

            foreach (IUxmlFactory factory in factories)
            {
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }
        }
コード例 #9
0
        static void OnEditTextFinished()
        {
            if (s_EditedElement == null)
            {
                return;
            }

            // Undo/Redo
            Undo.RegisterCompleteObjectUndo(s_Viewport.paneWindow.document.visualTreeAsset, BuilderConstants.ChangeAttributeValueUndoMessage);

            var newValue = s_Viewport.textEditor.value;
            var type     = s_EditedElement.GetType();
            var vea      = s_EditedElement.GetVisualElementAsset();
            var oldValue = vea.GetAttributeValue(s_EditedTextAttribute.name);

            if (newValue != oldValue)
            {
                // Set value in asset.
                vea.SetAttributeValue(s_EditedTextAttribute.name, newValue);

                var fullTypeName = type.ToString();

                if (VisualElementFactoryRegistry.TryGetValue(fullTypeName, out var factoryList))
                {
                    var traits = factoryList[0].GetTraits();

                    if (traits == null)
                    {
                        CloseEditor();
                        return;
                    }

                    var context = new CreationContext();

                    try
                    {
                        traits.Init(s_EditedElement, vea, context);
                    }
                    catch
                    {
                        // HACK: This throws in 2019.3.0a4 because usageHints property throws when set after the element has already been added to the panel.
                    }
                }

                s_Viewport.selection.NotifyOfHierarchyChange(s_Viewport);
            }
            CloseEditor();
        }
コード例 #10
0
        internal static void RegisterAll()
        {
            if (s_Registered)
            {
                return;
            }

            s_Registered = true;

            IUxmlFactory[] factories =
            {
                // Primitives
                new FloatField.FloatFieldFactory(),
                new DoubleField.DoubleFieldFactory(),
                new IntegerField.IntegerFieldFactory(),
                new LongField.LongFieldFactory(),
                new CurveField.CurveFieldFactory(),
                new ObjectField.ObjectFieldFactory(),
                new ColorField.ColorFieldFactory(),
                new EnumField.EnumFieldFactory(),
                new GradientField.GradientFieldFactory(),

                // Compounds
                new RectField.RectFieldFactory(),
                new Vector2Field.Vector2FieldFactory(),
                new Vector3Field.Vector3FieldFactory(),
                new Vector4Field.Vector4FieldFactory(),
                new BoundsField.BoundsFieldFactory(),
                new PropertyControl <int> .PropertyControlFactory(),
                new PropertyControl <long> .PropertyControlFactory(),
                new PropertyControl <float> .PropertyControlFactory(),
                new PropertyControl <double> .PropertyControlFactory(),
                new PropertyControl <string> .PropertyControlFactory(),
            };
            foreach (IUxmlFactory factory in factories)
            {
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }
        }
コード例 #11
0
        static UXMLEditorFactories()
        {
            if (k_Registered)
            {
                return;
            }

            k_Registered = true;

            IUxmlFactory[] factories =
            {
                // Primitives
                new TextElement.UxmlFactory(),

                // Compounds
                new PropertyControl <int> .UxmlFactory(),
                new PropertyControl <long> .UxmlFactory(),
                new PropertyControl <float> .UxmlFactory(),
                new PropertyControl <double> .UxmlFactory(),
                new PropertyControl <string> .UxmlFactory(),

                new VisualSplitter.UxmlFactory(),

                // Toolbar
                new Toolbar.UxmlFactory(),
                new ToolbarButton.UxmlFactory(),
                new ToolbarToggle.UxmlFactory(),
                new ToolbarSpacer.UxmlFactory(),
                new ToolbarMenu.UxmlFactory(),
                new ToolbarSearchField.UxmlFactory(),
                new ToolbarPopupSearchField.UxmlFactory(),
                new ToolbarBreadcrumbs.UxmlFactory(),
                // Bound
                new PropertyField.UxmlFactory(),
                new InspectorElement.UxmlFactory(),

                // Fields
                new FloatField.UxmlFactory(),
                new DoubleField.UxmlFactory(),
                new IntegerField.UxmlFactory(),
                new LongField.UxmlFactory(),
                new CurveField.UxmlFactory(),
                new ObjectField.UxmlFactory(),
                new ColorField.UxmlFactory(),
                new EnumField.UxmlFactory(),
                new MaskField.UxmlFactory(),
                new LayerMaskField.UxmlFactory(),
                new LayerField.UxmlFactory(),
                new TagField.UxmlFactory(),
                new GradientField.UxmlFactory(),
                new EnumFlagsField.UxmlFactory(),
                new Hash128Field.UxmlFactory(),

#if !UNITY_2021_1_OR_NEWER
                new ProgressBar.UxmlFactory(),
#endif
                // Compounds
                new RectField.UxmlFactory(),
                new Vector2Field.UxmlFactory(),
                new Vector3Field.UxmlFactory(),
                new Vector4Field.UxmlFactory(),
                new BoundsField.UxmlFactory(),


                new RectIntField.UxmlFactory(),
                new Vector2IntField.UxmlFactory(),
                new Vector3IntField.UxmlFactory(),
                new BoundsIntField.UxmlFactory(),

                new EventTypeSelectField.UxmlFactory()
            };

            foreach (IUxmlFactory factory in factories)
            {
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }

            // Discover packages and user factories.
            HashSet <string> userAssemblies = new HashSet <string>(ScriptingRuntime.GetAllUserAssemblies());
            var types = TypeCache.GetTypesDerivedFrom <IUxmlFactory>();

            foreach (var type in types)
            {
                if (type.IsAbstract ||
                    !userAssemblies.Contains(type.Assembly.GetName().Name + ".dll") ||
                    !typeof(IUxmlFactory).IsAssignableFrom(type) ||
                    type.IsInterface ||
                    type.IsGenericType ||
                    type.Assembly.GetName().Name == "UnityEngine.UIElementsModule" ||
                    type.Assembly.GetName().Name == "UnityEditor.UIElementsModule")
                {
                    continue;
                }

                var factory = (IUxmlFactory)Activator.CreateInstance(type);
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }
        }
コード例 #12
0
        static UXMLEditorFactories()
        {
            if (s_Registered)
            {
                return;
            }

            s_Registered = true;

            IUxmlFactory[] factories =
            {
                // Primitives
                new TextElement.UxmlFactory(),
                new FloatField.UxmlFactory(),
                new DoubleField.UxmlFactory(),
                new IntegerField.UxmlFactory(),
                new LongField.UxmlFactory(),
                new CurveField.UxmlFactory(),
                new ObjectField.UxmlFactory(),
                new ColorField.UxmlFactory(),
                new EnumField.UxmlFactory(),
                new MaskField.UxmlFactory(),
                new LayerMaskField.UxmlFactory(),
                new LayerField.UxmlFactory(),
                new TagField.UxmlFactory(),
                new GradientField.UxmlFactory(),

                // Compounds
                new RectField.UxmlFactory(),
                new Vector2Field.UxmlFactory(),
                new Vector3Field.UxmlFactory(),
                new Vector4Field.UxmlFactory(),
                new BoundsField.UxmlFactory(),
                new PropertyControl <int> .UxmlFactory(),
                new PropertyControl <long> .UxmlFactory(),
                new PropertyControl <float> .UxmlFactory(),
                new PropertyControl <double> .UxmlFactory(),
                new PropertyControl <string> .UxmlFactory(),

                new RectIntField.UxmlFactory(),
                new Vector2IntField.UxmlFactory(),
                new Vector3IntField.UxmlFactory(),
                new BoundsIntField.UxmlFactory(),
                new VisualSplitter.UxmlFactory(),
                // Toolbar
                new Toolbar.UxmlFactory(),
                new ToolbarButton.UxmlFactory(),
                new ToolbarToggle.UxmlFactory(),
                new ToolbarSpacer.UxmlFactory(),
                new ToolbarFlexSpacer.UxmlFactory(),
                new ToolbarMenu.UxmlFactory(),
                new ToolbarPopup.UxmlFactory(),
                new ToolbarSearchField.UxmlFactory(),
                new ToolbarPopupSearchField.UxmlFactory(),
                // Bound
                new PropertyField.UxmlFactory(),
                new InspectorElement.UxmlFactory(),
            };

            foreach (IUxmlFactory factory in factories)
            {
                VisualElementFactoryRegistry.RegisterFactory(factory);
            }
        }
コード例 #13
0
 static void RegisterAll()
 {
     VisualElementFactoryRegistry.RegisterFactory(new Pill.PillFactory());
 }
コード例 #14
0
ファイル: InternalBridge.cs プロジェクト: Fleezey/phygames
 /// <summary>
 /// Register customElement factory
 /// </summary>
 public static void RegisterFactory(IUxmlFactory factory)
 {
     VisualElementFactoryRegistry.RegisterFactory(factory);
 }
コード例 #15
0
 static void RegisterAll()
 {
     VisualElementFactoryRegistry.RegisterFactory(new Pill.UxmlFactory());
     VisualElementFactoryRegistry.RegisterFactory(new ResizableElement.UxmlFactory());
     VisualElementFactoryRegistry.RegisterFactory(new StickyNote.UxmlFactory());
 }
コード例 #16
0
        internal static IEnumerable <string> GenerateSchemaFiles(string baseDir = null)
        {
            Dictionary <string, SchemaInfo> schemas           = new Dictionary <string, SchemaInfo>();
            List <IUxmlFactory>             deferredFactories = new List <IUxmlFactory>();
            FactoryProcessingHelper         processingData    = new FactoryProcessingHelper();

            if (baseDir == null)
            {
                baseDir = Application.temporaryCachePath + "/";
            }
            VisualElementFactoryRegistry.DiscoverFactories();

            // Convert the factories into schemas info.
            foreach (var factories in VisualElementFactoryRegistry.factories)
            {
                if (factories.Value.Count == 0)
                {
                    continue;
                }

                // Only process the first factory, as the other factories define the same element.
                IUxmlFactory factory = factories.Value[0];
                if (!ProcessFactory(factory, schemas, processingData))
                {
                    // Could not process the factory now, because it depends on a yet unprocessed factory.
                    // Defer its processing.
                    deferredFactories.Add(factory);
                }
            }

            List <IUxmlFactory> deferredFactoriesCopy;

            do
            {
                deferredFactoriesCopy = new List <IUxmlFactory>(deferredFactories);
                foreach (var factory in deferredFactoriesCopy)
                {
                    deferredFactories.Remove(factory);
                    if (!ProcessFactory(factory, schemas, processingData))
                    {
                        // Could not process the factory now, because it depends on a yet unprocessed factory.
                        // Defer its processing again.
                        deferredFactories.Add(factory);
                    }
                }
            }while (deferredFactoriesCopy.Count > deferredFactories.Count);

            if (deferredFactories.Count > 0)
            {
                Debug.Log("Some factories could not be processed because their base type is missing.");
            }

            // Compile schemas.
            XmlSchemaSet schemaSet    = new XmlSchemaSet();
            XmlSchema    masterSchema = new XmlSchema();

            masterSchema.ElementFormDefault = XmlSchemaForm.Qualified;

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("xs", k_XmlSchemaNamespace);

            File.Delete(baseDir + k_MainSchemaFileName);

            foreach (var schema in schemas)
            {
                if (schema.Value.schema.TargetNamespace != null)
                {
                    nsmgr.AddNamespace(schema.Value.namepacePrefix, schema.Value.schema.TargetNamespace);

                    // Import schema into the master schema.
                    XmlSchemaImport import = new XmlSchemaImport();
                    import.Namespace = schema.Value.schema.TargetNamespace;
                    string schemaLocation = GetFileNameForNamespace(schema.Value.schema.TargetNamespace);
                    File.Delete(baseDir + schemaLocation);
                    import.SchemaLocation = schemaLocation;
                    masterSchema.Includes.Add(import);
                }
                else
                {
                    XmlSchemaInclude include        = new XmlSchemaInclude();
                    string           schemaLocation = GetFileNameForNamespace(null);
                    File.Delete(baseDir + schemaLocation);
                    include.SchemaLocation = schemaLocation;
                    masterSchema.Includes.Add(include);
                }

                // Import referenced schemas into this XSD
                foreach (string ns in schema.Value.importNamespaces)
                {
                    if (ns != schema.Value.schema.TargetNamespace && ns != k_XmlSchemaNamespace)
                    {
                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Namespace      = ns;
                        import.SchemaLocation = GetFileNameForNamespace(ns);
                        schema.Value.schema.Includes.Add(import);
                    }
                }

                schemaSet.Add(schema.Value.schema);
            }
            schemaSet.Add(masterSchema);
            schemaSet.Compile();

            // Now generate the schema textual data.
            foreach (XmlSchema compiledSchema in schemaSet.Schemas())
            {
                string schemaName = compiledSchema.TargetNamespace;

                // Three possible cases:
                // TargetNamespace == null and Items.Count == 0: the main schema, that include/import all other schema files
                // TargetNamespace == null and Items.Count != 0: the schema file for the global namespace
                // TargetNamespace != null: the schema file for TargetNamespace
                if (schemaName == null && compiledSchema.Items.Count == 0)
                {
                    schemaName = k_MainSchemaFileName;
                }
                else
                {
                    schemaName = GetFileNameForNamespace(compiledSchema.TargetNamespace);
                }

                yield return(baseDir + schemaName);

                StringWriter strWriter = new UTF8StringWriter();
                compiledSchema.Write(strWriter, nsmgr);
                yield return(strWriter.ToString());
            }
        }