コード例 #1
0
ファイル: Converters.cs プロジェクト: vault51/Graphics
        internal static void BatchConverters(List <RenderPipelineConverter> converters)
        {
            // This need to be sorted by Priority property
            converters = converters.OrderBy(o => o.priority).ToList();

            foreach (RenderPipelineConverter converter in converters)
            {
                List <ConverterItemDescriptor> converterItemInfos = new List <ConverterItemDescriptor>();
                var initCtx = new InitializeConverterContext {
                    items = converterItemInfos
                };
                initCtx.isBatchMode = true;
                converter.OnInitialize(initCtx, () => { });

                converter.OnPreRun();
                for (int i = 0; i < initCtx.items.Count; i++)
                {
                    var item = new ConverterItemInfo()
                    {
                        index      = i,
                        descriptor = initCtx.items[i],
                    };
                    var ctx = new RunItemContext(item);
                    ctx.isBatchMode = true;
                    converter.OnRun(ref ctx);

                    string converterStatus = ctx.didFail ? $"Fail\nInfo: {ctx.info}" : "Pass";
                    Debug.Log($"Name: {ctx.item.descriptor.name}\nConverter Status: {converterStatus}");
                }

                converter.OnPostRun();

                AssetDatabase.SaveAssets();
            }
        }
コード例 #2
0
        void GetAndSetData(int i)
        {
            // This need to be in Init method
            // Need to get the assets that this converter is converting.
            // Need to return Name, Path, Initial info, Help link.
            // New empty list of ConverterItemInfos
            List <ConverterItemDescriptor> converterItemInfos = new List <ConverterItemDescriptor>();
            var initCtx = new InitializeConverterContext {
                items = converterItemInfos
            };

            var conv = m_CoreConvertersList[i];

            // This should also go to the init method
            // This will fill out the converter item infos list
            conv.OnInitialize(initCtx);

            // Set the item infos list to to the right index
            m_ItemsToConvert[i]        = converterItemInfos;
            m_ConverterStates[i].items = new List <ConverterItemState>(converterItemInfos.Count);

            // Default all the entries to true
            for (var j = 0; j < converterItemInfos.Count; j++)
            {
                string message = string.Empty;
                Status status;
                bool   active = true;
                // If this data hasn't been filled in from the init phase then we can assume that there are no issues / warnings
                if (string.IsNullOrEmpty(converterItemInfos[j].warningMessage))
                {
                    status = Status.Pending;
                }
                else
                {
                    status  = Status.Warning;
                    message = converterItemInfos[j].warningMessage;
                    active  = false;
                    m_ConverterStates[i].warnings++;
                }

                m_ConverterStates[i].items.Add(new ConverterItemState
                {
                    isActive     = active,
                    message      = message,
                    status       = status,
                    hasConverted = false,
                });
            }

            m_ConverterStates[i].isInitialized = true;

            // Making sure that the pending amount is set to the amount of items needs converting
            m_ConverterStates[i].pending = m_ConverterStates[i].items.Count;

            EditorUtility.SetDirty(this);
            m_SerializedObject.Update();
        }
コード例 #3
0
        public override void OnInitialize(InitializeConverterContext context, Action callback)
        {
            m_SettingsItems  = new List <SettingsItem>();
            m_RenderingModes = new List <RenderingMode>();

            // check graphics tiers
            GatherGraphicsTiers();

            // check quality levels
            GatherQualityLevels(ref context);

            callback?.Invoke();
        }
コード例 #4
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();
        }
コード例 #5
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);
        }
コード例 #6
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);
            }
        }
コード例 #7
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();
        }
コード例 #8
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();
        }
コード例 #9
0
        public override void OnInitialize(InitializeConverterContext context, Action callback)
        {
            // Converters should already be set to null on domain reload,
            // but we're doing it here just in case anything somehow lingers.
            effectConverters = null;

            postConversionDestroyables = new List <Object>();

            // We are using separate searchContexts here and Adding them in this order:
            //      - Components from Prefabs & Scenes (Volumes & Layers)
            //      - ScriptableObjects (Profiles)
            //
            // This allows the old objects to be both re-referenced and deleted safely as they are converted in OnRun.
            // The process of converting Volumes will convert Profiles as-needed, and then the explicit followup Profile
            // conversion step will convert any non-referenced assets and delete all old Profiles.
            Debug.Log("Running here");
            // Components First
            using var componentContext =
                      Search.SearchService.CreateContext("asset", "urp:convert-ppv2component");
            using var componentItems = Search.SearchService.Request(componentContext);
            {
                Debug.Log("First Search");
                AddSearchItemsAsConverterAssetEntries(componentItems, context);
            }

            // Then ScriptableObjects
            using var scriptableObjectContext =
                      Search.SearchService.CreateContext("asset", "urp:convert-ppv2scriptableobject");
            using var scriptableObjectItems = Search.SearchService.Request(scriptableObjectContext);
            {
                Debug.Log("Second Search");
                AddSearchItemsAsConverterAssetEntries(scriptableObjectItems, context);
            }

            callback.Invoke();
        }
コード例 #10
0
 /// <summary>
 /// This runs when initializing the converter. To gather data for the UI and also for the converter if needed.
 /// </summary>
 /// <param name="context">The context that will be used to initialize data for the converter.</param>
 public abstract void OnInitialize(InitializeConverterContext context, Action callback);
コード例 #11
0
 /// <summary>
 /// This runs when initializing the converter. To gather data for the UI and also for the converter if needed.
 /// </summary>
 /// <param name="context">The context that will be used to initialize data for the converter.</param>
 public abstract void OnInitialize(InitializeConverterContext context);
コード例 #12
0
        void GetAndSetData(int i, Action onAllConvertersCompleted = null)
        {
            // This need to be in Init method
            // Need to get the assets that this converter is converting.
            // Need to return Name, Path, Initial info, Help link.
            // New empty list of ConverterItemInfos
            List <ConverterItemDescriptor> converterItemInfos = new List <ConverterItemDescriptor>();
            var initCtx = new InitializeConverterContext {
                items = converterItemInfos
            };

            var conv = m_CoreConvertersList[i];

            m_ConverterStates[i].isLoading = true;

            // This should also go to the init method
            // This will fill out the converter item infos list
            int id = i;

            conv.OnInitialize(initCtx, OnConverterCompleteDataCollection);

            void OnConverterCompleteDataCollection()
            {
                // Set the item infos list to to the right index
                m_ItemsToConvert[id] = new ConverterItems {
                    itemDescriptors = converterItemInfos
                };
                m_ConverterStates[id].items = new List <ConverterItemState>(converterItemInfos.Count);

                // Default all the entries to true
                for (var j = 0; j < converterItemInfos.Count; j++)
                {
                    string message = string.Empty;
                    Status status;
                    bool   active = true;
                    // If this data hasn't been filled in from the init phase then we can assume that there are no issues / warnings
                    if (string.IsNullOrEmpty(converterItemInfos[j].warningMessage))
                    {
                        status = Status.Pending;
                    }
                    else
                    {
                        status  = Status.Warning;
                        message = converterItemInfos[j].warningMessage;
                        active  = false;
                        m_ConverterStates[id].warnings++;
                    }

                    m_ConverterStates[id].items.Add(new ConverterItemState
                    {
                        isActive     = active,
                        message      = message,
                        status       = status,
                        hasConverted = false,
                    });
                }

                m_ConverterStates[id].isLoading     = false;
                m_ConverterStates[id].isInitialized = true;

                // Making sure that the pending amount is set to the amount of items needs converting
                m_ConverterStates[id].pending = m_ConverterStates[id].items.Count;

                EditorUtility.SetDirty(this);
                m_SerializedObject.ApplyModifiedProperties();

                CheckAllConvertersCompleted();
                convertButtonActive = true;
                // Make sure that the Convert Button is turned back on
                var button = rootVisualElement.Q <Button>("convertButton");

                button.SetEnabled(convertButtonActive);
            }

            void CheckAllConvertersCompleted()
            {
                int convertersToInitialize = 0;
                int convertersInitialized  = 0;

                for (var j = 0; j < m_ConverterStates.Count; j++)
                {
                    var converter = m_ConverterStates[j];

                    // Skip inactive converters
                    if (!converter.isActiveAndEnabled)
                    {
                        continue;
                    }

                    if (converter.isInitialized)
                    {
                        convertersInitialized++;
                    }
                    else
                    {
                        convertersToInitialize++;
                    }
                }

                var sum = convertersToInitialize + convertersInitialized;

                Assert.IsFalse(sum == 0);

                // Show our progress so far
                EditorUtility.ClearProgressBar();
                EditorUtility.DisplayProgressBar($"Initializing converters", $"Initializing converters ({convertersInitialized}/{sum})...", (float)convertersInitialized / sum);

                // If all converters are initialized call the complete callback
                if (convertersToInitialize == 0)
                {
                    onAllConvertersCompleted?.Invoke();
                }
            }
        }