Example #1
0
        public override void OnInitialize(InitializeConverterContext context, Action callback)
        {
            Renderer2DData data = Light2DEditorUtility.GetRenderer2DData();

            if (data != null)
            {
                m_SpriteLitDefaultMat = data.GetDefaultMaterial(DefaultMaterialType.Sprite);
            }
            else
            {
                m_SpriteLitDefaultMat = AssetDatabase.LoadAssetAtPath <Material>("Packages/com.unity.render-pipelines.universal/Runtime/Materials/Sprite-Lit-Default.mat");
            }

            m_SpritesDefaultMat      = AssetDatabase.GetBuiltinExtraResource <Material>("Sprites-Default.mat");
            m_SpriteMaskDefaultMat   = AssetDatabase.LoadAssetAtPath <Material>("Packages/com.unity.render-pipelines.universal/Runtime/Materials/SpriteMask-Default.mat");
            m_SpritesMaskMat         = AssetDatabase.GetBuiltinExtraResource <Material>("Sprites-Mask.mat");
            m_SpriteLitDefaultShader = m_SpriteLitDefaultMat.shader;
            m_SpritesDefaultShader   = m_SpritesDefaultMat.shader;
            m_SpritesDefaultShaderId = URP2DConverterUtility.GetObjectIDString(m_SpritesDefaultShader);
            m_SpritesDefaultMatId    = URP2DConverterUtility.GetObjectIDString(m_SpritesDefaultMat);
            m_SpritesMaskMatId       = URP2DConverterUtility.GetObjectIDString(m_SpritesMaskMat);

            string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();

            foreach (string path in allAssetPaths)
            {
                if (URP2DConverterUtility.IsMaterialPath(path, m_SpritesDefaultShaderId) || URP2DConverterUtility.IsPrefabOrScenePath(path, new string[] { m_SpritesDefaultMatId, m_SpritesMaskMatId }))
                {
                    ConverterItemDescriptor desc = new ConverterItemDescriptor()
                    {
                        name           = Path.GetFileNameWithoutExtension(path),
                        info           = path,
                        warningMessage = String.Empty,
                        helpLink       = String.Empty
                    };

                    // Each converter needs to add this info using this API.
                    m_AssetsToConvert.Add(path);
                    context.AddAssetToConvert(desc);
                }
            }

            callback.Invoke();
        }
Example #2
0
        /// <summary>
        /// Iterates over all Quality Settings and saves relevant settings to a RenderSettingsItem.
        /// This will also create the required information for the Render Pipeline Converter UI.
        /// </summary>
        /// <param name="context">Converter context to add elements to.</param>
        private void GatherQualityLevels(ref InitializeConverterContext context)
        {
            var currentQuality = QualitySettings.GetQualityLevel();
            var id             = 0;

            foreach (var levelName in QualitySettings.names)
            {
                QualitySettings.SetQualityLevel(id);

                var projectSettings = new RenderSettingItem
                {
                    Index              = id,
                    LevelName          = levelName,
                    PixelLightCount    = QualitySettings.pixelLightCount,
                    MSAA               = QualitySettings.antiAliasing,
                    Shadows            = QualitySettings.shadows,
                    ShadowResolution   = QualitySettings.shadowResolution,
                    ShadowDistance     = QualitySettings.shadowDistance,
                    ShadowCascadeCount = QualitySettings.shadowCascades,
                    CascadeSplit2      = QualitySettings.shadowCascade2Split,
                    CascadeSplit4      = QualitySettings.shadowCascade4Split,
                    SoftParticles      = QualitySettings.softParticles,
                };
                m_SettingsItems.Add(projectSettings);

                var setting = QualitySettings.GetRenderPipelineAssetAt(id);
                var item    = new ConverterItemDescriptor {
                    name = $"Quality Level {id}: {levelName}"
                };

                if (setting != null)
                {
                    item.warningMessage = setting.GetType() == typeof(UniversalRenderPipelineAsset)
                        ? "Contains URP Asset, will override existing asset."
                        : "Contains SRP Asset, will override existing asset with URP asset.";
                }

                context.AddAssetToConvert(item);
                id++;
            }

            QualitySettings.SetQualityLevel(currentQuality);
        }
Example #3
0
        private void AddSearchItemsAsConverterAssetEntries(ISearchList searchItems, InitializeConverterContext context)
        {
            foreach (var searchItem in searchItems)
            {
                if (searchItem == null || !GlobalObjectId.TryParse(searchItem.id, out var globalId))
                {
                    continue;
                }

                var description = searchItem.provider.fetchDescription(searchItem, searchItem.context);

                var item = new ConverterItemDescriptor()
                {
                    name = description.Split('/').Last().Split('.').First(),
                    info = $"{ReturnType(globalId)}",
                };

                guids.Add(globalId.ToString());
                context.AddAssetToConvert(item);
            }
        }
Example #4
0
        public override void OnInitialize(InitializeConverterContext ctx, Action callback)
        {
            var context = Search.SearchService.CreateContext("asset", "urp:convert-readonly");

            Search.SearchService.Request(context, (c, items) =>
            {
                // we're going to do this step twice in order to get them ordered, but it should be fast
                var orderedRequest = items.OrderBy(req =>
                {
                    GlobalObjectId.TryParse(req.id, out var gid);
                    return(gid.assetGUID);
                });

                foreach (var r in orderedRequest)
                {
                    if (r == null || !GlobalObjectId.TryParse(r.id, out var gid))
                    {
                        continue;
                    }

                    var label       = r.provider.fetchLabel(r, r.context);
                    var description = r.provider.fetchDescription(r, r.context);

                    var item = new ConverterItemDescriptor()
                    {
                        name = description.Split('/').Last().Split('.').First(),
                        info = $"{label}",
                    };
                    guids.Add(gid.ToString());

                    ctx.AddAssetToConvert(item);
                }

                callback.Invoke();
            });
            context?.Dispose();
        }
Example #5
0
        public override void OnInitialize(InitializeConverterContext context, Action callback)
        {
            string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();

            foreach (string path in allAssetPaths)
            {
                if (URP2DConverterUtility.IsPrefabOrScenePath(path, "m_LightType: 0"))
                {
                    ConverterItemDescriptor desc = new ConverterItemDescriptor()
                    {
                        name           = Path.GetFileNameWithoutExtension(path),
                        info           = path,
                        warningMessage = String.Empty,
                        helpLink       = String.Empty
                    };

                    // Each converter needs to add this info using this API.
                    m_AssetsToConvert.Add(path);
                    context.AddAssetToConvert(desc);
                }
            }

            callback.Invoke();
        }
        public void CreateGUI()
        {
            m_SerializedObject = new SerializedObject(this);
            converterEditorAsset.CloneTree(rootVisualElement);

            // This is temp now to get the information filled in
            RenderPipelineConverterContainer converterContainer =
                (RenderPipelineConverterContainer)Activator.CreateInstance(m_ConverterContainers[0]);

            rootVisualElement.Q <Label>("conversionName").text       = converterContainer.name;
            rootVisualElement.Q <TextElement>("conversionInfo").text = converterContainer.info;

            rootVisualElement.Q <Image>("converterContainerHelpIcon").image = CoreEditorStyles.iconHelp;

            // Getting the scrollview where the converters should be added
            m_ScrollView = rootVisualElement.Q <ScrollView>("convertersScrollView");
            for (int i = 0; i < m_CoreConvertersList.Count; ++i)
            {
                // Making an item using the converterListAsset as a template.
                // Then adding the information needed for each converter
                VisualElement item = new VisualElement();
                converterListAsset.CloneTree(item);
                var conv = m_CoreConvertersList[i];
                item.SetEnabled(conv.IsEnabled);
                item.Q <Label>("converterName").text = conv.name;
                item.Q <Label>("converterInfo").text = conv.info;
                item.Q <VisualElement>("converterTopVisualElement").tooltip = conv.info;

                // setup the images
                item.Q <Image>("pendingImage").image   = CoreEditorStyles.iconPending;
                item.Q <Image>("pendingImage").tooltip = "Pending";
                var pendingLabel = item.Q <Label>("pendingLabel");
                item.Q <Image>("warningImage").image   = CoreEditorStyles.iconWarn;
                item.Q <Image>("warningImage").tooltip = "Warnings";
                var warningLabel = item.Q <Label>("warningLabel");
                item.Q <Image>("errorImage").image   = CoreEditorStyles.iconFail;
                item.Q <Image>("errorImage").tooltip = "Failed";
                var errorLabel = item.Q <Label>("errorLabel");
                item.Q <Image>("successImage").image   = CoreEditorStyles.iconSuccess;
                item.Q <Image>("successImage").tooltip = "Success";
                var successLabel = item.Q <Label>("successLabel");

                var converterEnabledToggle = item.Q <Toggle>("converterEnabled");
                converterEnabledToggle.bindingPath =
                    $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.isActive)}";
                pendingLabel.bindingPath =
                    $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.pending)}";
                warningLabel.bindingPath =
                    $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.warnings)}";
                errorLabel.bindingPath =
                    $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.errors)}";
                successLabel.bindingPath =
                    $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.success)}";

                VisualElement child    = item;
                ListView      listView = child.Q <ListView>("converterItems");

                listView.showBoundCollectionSize = false;
                listView.bindingPath             = $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.items)}";

                int id = i;
                listView.makeItem = () =>
                {
                    var convertItem = converterItem.CloneTree();
                    // Adding the contextual menu for each item
                    convertItem.AddManipulator(new ContextualMenuManipulator(evt => AddToContextMenu(evt, id)));
                    return(convertItem);
                };

                listView.bindItem = (element, index) =>
                {
                    m_SerializedObject.Update();
                    var property = m_SerializedObject.FindProperty($"{listView.bindingPath}.Array.data[{index}]");

                    // ListView doesn't bind the child elements for us properly, so we do that for it
                    // In the UXML our root is a BindableElement, as we can't bind otherwise.
                    var bindable = (BindableElement)element;
                    bindable.BindProperty(property);

                    // Adding index here to userData so it can be retrieved later
                    element.userData = index;

                    Status status = (Status)property.FindPropertyRelative("status").enumValueIndex;
                    string info   = property.FindPropertyRelative("message").stringValue;

                    // Update the amount of things to convert
                    child.Q <Label>("converterStats").text = $"{m_ItemsToConvert[id].Count} items";

                    ConverterItemDescriptor convItemDesc = m_ItemsToConvert[id][index];

                    element.Q <Label>("converterItemName").text = convItemDesc.name;
                    element.Q <Label>("converterItemPath").text = convItemDesc.info;

                    element.Q <Image>("converterItemHelpIcon").image   = CoreEditorStyles.iconHelp;
                    element.Q <Image>("converterItemHelpIcon").tooltip = convItemDesc.helpLink;

                    // Changing the icon here depending on the status.
                    Texture2D icon = null;

                    switch (status)
                    {
                    case Status.Pending:
                        icon = CoreEditorStyles.iconPending;
                        break;

                    case Status.Error:
                        icon = CoreEditorStyles.iconFail;
                        break;

                    case Status.Warning:
                        icon = CoreEditorStyles.iconWarn;
                        break;

                    case Status.Success:
                        icon = CoreEditorStyles.iconSuccess;
                        break;
                    }

                    element.Q <Image>("converterItemStatusIcon").image   = icon;
                    element.Q <Image>("converterItemStatusIcon").tooltip = info;
                };
                listView.onSelectionChange += obj => { m_CoreConvertersList[id].OnClicked(listView.selectedIndex); };
                listView.unbindItem         = (element, index) =>
                {
                    var bindable = (BindableElement)element;
                    bindable.Unbind();
                };

                m_ScrollView.Add(item);
            }

            rootVisualElement.Bind(m_SerializedObject);
            var button = rootVisualElement.Q <Button>("convertButton");

            button.RegisterCallback <ClickEvent>(Convert);

            var initButton = rootVisualElement.Q <Button>("initializeButton");

            initButton.RegisterCallback <ClickEvent>(Init);
        }
Example #7
0
 /// <summary>
 /// Add to the list of assets to be converted.
 /// This will be used to display information to the user in the UI.
 /// </summary>
 /// <param name="item">The item to add to the list items to convert</param>
 internal void AddAssetToConvert(ConverterItemDescriptor item)
 {
     items.Add(item);
 }
        void Init(ClickEvent evt)
        {
            for (int i = 0; i < m_ConverterStates.Count; ++i)
            {
                // Need to clear selection here otherwise we get an error for the listview refresh
                VisualElement child    = m_ScrollView[i];
                ListView      listView = child.Q <ListView>("converterItems");
                listView.ClearSelection();

                var state = m_ConverterStates[i];
                if (state.isInitialized || !state.isEnabled || !state.isActive)
                {
                    continue;
                }

                GetAndSetData(i);

                var id = i;
                if (m_ConverterStates[i].isActive)
                {
                    var converterItemInfos = m_ItemsToConvert[i];
                    // Update the amount of things to convert
                    child.Q <Label>("converterStats").text = $"{converterItemInfos.Count} items";

                    listView.makeItem = () =>
                    {
                        var convertItem = converterItem.CloneTree();
                        // Adding the contextual menu for each item
                        convertItem.AddManipulator(new ContextualMenuManipulator(evt => AddToContextMenu(evt, id)));
                        return(convertItem);
                    };

                    listView.showBoundCollectionSize = false;

                    listView.bindingPath =
                        $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.items)}";
                    // I would like this to work, have a separate method and not inlined like this
                    listView.bindItem = (element, index) =>
                    {
                        // ListView doesn't bind the child elements for us properly, so we do that for it
                        var property = m_SerializedObject.FindProperty($"{listView.bindingPath}.Array.data[{index}]");
                        // In the UXML our root is a BindableElement, as we can't bind otherwise.
                        var bindable = (BindableElement)element;
                        bindable.BindProperty(property);

                        // Adding index here to userData so it can be retrieved later
                        element.userData = index;

                        ConverterItemDescriptor convItemDesc = converterItemInfos[index];

                        element.Q <Label>("converterItemName").text = convItemDesc.name;
                        element.Q <Label>("converterItemPath").text = convItemDesc.info;

                        element.Q <Image>("converterItemHelpIcon").image   = CoreEditorStyles.iconHelp;
                        element.Q <Image>("converterItemHelpIcon").tooltip = convItemDesc.helpLink;

                        // Changing the icon here depending on the status.
                        Status    status = m_ConverterStates[id].items[index].status;
                        string    info   = m_ConverterStates[id].items[index].message;
                        Texture2D icon   = null;

                        switch (status)
                        {
                        case Status.Pending:
                            icon = CoreEditorStyles.iconPending;
                            break;

                        case Status.Error:
                            icon = CoreEditorStyles.iconFail;
                            break;

                        case Status.Warning:
                            icon = CoreEditorStyles.iconWarn;
                            break;

                        case Status.Success:
                            icon = CoreEditorStyles.iconSuccess;
                            break;
                        }

                        element.Q <Image>("converterItemStatusIcon").image   = icon;
                        element.Q <Image>("converterItemStatusIcon").tooltip = info;
                    };
                    listView.onSelectionChange += obj =>
                    {
                        m_CoreConvertersList[id].OnClicked(listView.selectedIndex);
                    };
                    listView.unbindItem = (element, index) =>
                    {
                        var bindable = (BindableElement)element;
                        bindable.Unbind();
                    };

                    listView.Refresh();
                }
            }

            rootVisualElement.Bind(m_SerializedObject);
        }