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; } }
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(); } }
public override void OnRun(ref RunItemContext context) { var item = context.item; // is quality item if (m_SettingsItems[item.index].GetType() == typeof(RenderSettingItem)) { GeneratePipelineAsset(m_SettingsItems[item.index] as RenderSettingItem); } }
private Object GetContextObject(ref RunItemContext ctx) { var item = ctx.item; var guid = guids[item.index]; if (GlobalObjectId.TryParse(guid, out var globalId)) { // Try loading the object // TODO: Upcoming changes to GlobalObjectIdentifierToObjectSlow will allow it // to return direct references to prefabs and their children. // Once that change happens there are several items which should be adjusted. var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalId); // If the object was not loaded, it is probably part of an unopened scene; // if so, then the solution is to first load the scene here. var objIsInSceneOrPrefab = globalId.identifierType == 2; // 2 is IdentifierType.kSceneObject if (!obj && objIsInSceneOrPrefab) { // Open the Containing Scene Asset in the Hierarchy so the Object can be manipulated var mainAssetPath = AssetDatabase.GUIDToAssetPath(globalId.assetGUID); var mainAsset = AssetDatabase.LoadAssetAtPath <Object>(mainAssetPath); AssetDatabase.OpenAsset(mainAsset); // If a prefab stage was opened, then mainAsset is the root of the // prefab that contains the target object, so reference that for now, // until GlobalObjectIdentifierToObjectSlow is updated if (PrefabStageUtility.GetCurrentPrefabStage() != null) { obj = mainAsset; } // Reload object if it is still null (because it's in a previously unopened scene) if (!obj) { obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalId); if (!obj) { ctx.didFail = true; ctx.info = $"Object {globalId.assetGUID} failed to load..."; } } } return(obj); } ctx.didFail = true; ctx.info = $"Failed to parse Global ID {item.descriptor.info}..."; return(null); }
public override void OnRun(ref RunItemContext ctx) { var obj = LoadObject(ref ctx); var result = true; var errorString = new StringBuilder(); if (obj != null) { var materials = MaterialReferenceBuilder.GetMaterialsFromObject(obj); foreach (var material in materials) { if (material == null) { continue; } // there might be multiple materials on this object, we only care about the ones we explicitly try to remap that fail if (!MaterialReferenceBuilder.GetIsReadonlyMaterial(material)) { continue; } if (!ReadonlyMaterialMap.Map.ContainsKey(material.name)) { continue; } if (!ReassignMaterial(obj, material.name, ReadonlyMaterialMap.Map[material.name])) { result = false; errorString.AppendLine($"Material {material.name} failed to be reassigned"); } } } else { result = false; errorString.AppendLine($"Object {ctx.item.descriptor.name} could not be loaded"); } if (!result) { ctx.didFail = true; ctx.info = errorString.ToString(); } else { // make sure the changes get saved EditorUtility.SetDirty(obj); var currentScene = SceneManager.GetActiveScene(); EditorSceneManager.SaveScene(currentScene); } }
void ConvertIndex(int coreConverterIndex, int index) { if (!m_ConverterStates[coreConverterIndex].items[index].hasConverted) { m_ConverterStates[coreConverterIndex].items[index].hasConverted = true; var item = new ConverterItemInfo() { index = index, descriptor = m_ItemsToConvert[coreConverterIndex][index], }; var ctx = new RunItemContext(item); m_CoreConvertersList[coreConverterIndex].OnRun(ref ctx); UpdateInfo(coreConverterIndex, ctx); } }
private Object LoadObject(ref RunItemContext ctx) { var item = ctx.item; var guid = guids[item.index]; if (GlobalObjectId.TryParse(guid, out var gid)) { var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid); if (!obj) { // Open container scene if (gid.identifierType == (int)IdentifierType.kSceneObject) { var containerPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID); var mainInstanceID = AssetDatabase.LoadAssetAtPath <Object>(containerPath); AssetDatabase.OpenAsset(mainInstanceID); // if we have a prefab open, then we already have the object we need to update var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { obj = mainInstanceID; } // Reload object if it is still null if (obj == null) { obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid); if (!obj) { ctx.didFail = true; ctx.info = $"Object {gid.assetGUID} failed to load..."; } } } } return(obj); } ctx.didFail = true; ctx.info = $"Failed to parse Global ID {item.descriptor.info}..."; return(null); }
void UpdateInfo(int stateIndex, RunItemContext ctx) { if (ctx.didFail) { m_ConverterStates[stateIndex].items[ctx.item.index].message = ctx.info; m_ConverterStates[stateIndex].items[ctx.item.index].status = Status.Error; m_ConverterStates[stateIndex].errors++; } else { m_ConverterStates[stateIndex].items[ctx.item.index].status = Status.Success; m_ConverterStates[stateIndex].success++; } m_ConverterStates[stateIndex].pending--; // Making sure that this is set here so that if user is clicking Convert again it will not run again. ctx.hasConverted = true; VisualElement child = m_ScrollView[stateIndex]; child.Q <ListView>("converterItems").Refresh(); }
/// <summary> /// The method that will be run when converting the assets. /// </summary> /// <param name="context">The context that will be used when executing converter.</param> public abstract void OnRun(ref RunItemContext context);
public override void OnRun(ref RunItemContext context) { var obj = GetContextObject(ref context); if (!obj) { context.didFail = true; context.info = "Could not be converted because the target object was lost."; return; } BIRPRendering.PostProcessVolume[] oldVolumes = null; BIRPRendering.PostProcessLayer[] oldLayers = null; // TODO: Upcoming changes to GlobalObjectIdentifierToObjectSlow will allow // this to be inverted, and the else to be deleted. #if false if (obj is GameObject go) { oldVolumes = go.GetComponents <BIRPRendering.PostProcessVolume>(); oldLayers = go.GetComponents <BIRPRendering.PostProcessLayer>(); } else if (obj is MonoBehaviour mb) { oldVolumes = mb.GetComponents <BIRPRendering.PostProcessVolume>(); oldLayers = mb.GetComponents <BIRPRendering.PostProcessLayer>(); } #else if (obj is GameObject go) { oldVolumes = go.GetComponentsInChildren <BIRPRendering.PostProcessVolume>(); oldLayers = go.GetComponentsInChildren <BIRPRendering.PostProcessLayer>(); } else if (obj is MonoBehaviour mb) { oldVolumes = mb.GetComponentsInChildren <BIRPRendering.PostProcessVolume>(); oldLayers = mb.GetComponentsInChildren <BIRPRendering.PostProcessLayer>(); } #endif // Note: even if nothing needs to be converted, that should still count as success, // though it shouldn't ever actually occur. var succeeded = true; var errorString = new StringBuilder(); if (effectConverters == null || effectConverters.Count() == 0 || effectConverters.Any(converter => converter == null)) { effectConverters = GetAllBIRPConverters(); } if (oldVolumes != null) { foreach (var oldVolume in oldVolumes) { ConvertVolume(oldVolume, ref succeeded, errorString); } } if (oldLayers != null) { foreach (var oldLayer in oldLayers) { ConvertLayer(oldLayer, ref succeeded, errorString); } } if (obj is BIRPRendering.PostProcessProfile oldProfile) { ConvertProfile(oldProfile, ref succeeded, errorString); } if (!succeeded) { context.didFail = true; context.info = errorString.ToString(); } else { var currentScene = SceneManager.GetActiveScene(); EditorSceneManager.SaveScene(currentScene); } }