public override void OnRun(ref RunItemContext context) { string result = string.Empty; string ext = Path.GetExtension(context.item.descriptor.info); if (ext == ".prefab") { result = URP2DConverterUtility.UpgradePrefab(context.item.descriptor.info, UpgradeGameObject); } else if (ext == ".unity") { URP2DConverterUtility.UpgradeScene(context.item.descriptor.info, UpgradeGameObject); } else if (ext == ".mat") { URP2DConverterUtility.UpgradeMaterial(context.item.descriptor.info, m_SpritesDefaultShader, m_SpriteLitDefaultShader); } if (result != string.Empty) { context.didFail = true; context.info = result; } else { context.hasConverted = true; } }
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(); }
public static bool IsMaterialPath(string path, string id) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (path.StartsWith("Packages")) { return(false); } if (path.EndsWith(".mat")) { return(URP2DConverterUtility.DoesFileContainString(path, new string[] { id })); } return(false); }
public static bool IsPrefabOrScenePath(string path, string[] ids) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (path.StartsWith("Packages")) { return(false); } if (path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase) || path.EndsWith(".unity", StringComparison.OrdinalIgnoreCase)) { return(URP2DConverterUtility.DoesFileContainString(path, ids)); } return(false); }
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(); }