static void UpgradeMaterial(Material mat) { Renderer2DData data = Light2DEditorUtility.GetRenderer2DData(); if (data != null) { Material defaultMat = data.GetDefaultMaterial(DefaultMaterialType.Sprite); if (mat.shader.name == "Sprites/Default") { mat.shader = defaultMat.shader; } } }
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(); }
static void UpgradeGameObject(GameObject go) { Renderer[] spriteRenderers = go.GetComponentsInChildren <Renderer>(true); Renderer2DData data = Light2DEditorUtility.GetRenderer2DData(); if (data != null) { Material defaultMat = data.GetDefaultMaterial(DefaultMaterialType.Sprite); bool upgraded = false; foreach (Renderer renderer in spriteRenderers) { int materialCount = renderer.sharedMaterials.Length; Material[] newMaterials = new Material[materialCount]; for (int i = 0; i < materialCount; i++) { Material mat = renderer.sharedMaterials[i]; if (mat != null && mat.shader.name == "Sprites/Default") { newMaterials[i] = defaultMat; upgraded = true; } else { newMaterials[i] = renderer.sharedMaterials[i]; } } if (upgraded) { renderer.sharedMaterials = newMaterials; } } if (upgraded) { Debug.Log(go.name + " was upgraded.", go); EditorSceneManager.MarkSceneDirty(go.scene); } } }
static bool CreateLightValidation() { return(Light2DEditorUtility.IsUsing2DRenderer()); }
void OnEnable() { m_Analytics = Analytics.Renderer2DAnalytics.instance; m_ModifiedLights = new HashSet <Light2D>(); m_SortingLayerDropDown = new SortingLayerDropDown(); m_BlendingSettingsFoldout = new SavedBool($"{target.GetType()}.2DURPBlendingSettingsFoldout", false); m_ShadowsSettingsFoldout = new SavedBool($"{target.GetType()}.2DURPShadowsSettingsFoldout", false); m_VolumetricSettingsFoldout = new SavedBool($"{target.GetType()}.2DURPVolumetricSettingsFoldout", false); m_NormalMapsSettingsFoldout = new SavedBool($"{target.GetType()}.2DURPNormalMapsSettingsFoldout", false); m_LightType = serializedObject.FindProperty("m_LightType"); m_LightColor = serializedObject.FindProperty("m_Color"); m_LightIntensity = serializedObject.FindProperty("m_Intensity"); m_UseNormalMap = serializedObject.FindProperty("m_UseNormalMap"); m_ShadowIntensity = serializedObject.FindProperty("m_ShadowIntensity"); m_ShadowIntensityEnabled = serializedObject.FindProperty("m_ShadowIntensityEnabled"); m_ShadowVolumeIntensity = serializedObject.FindProperty("m_ShadowVolumeIntensity"); m_ShadowVolumeIntensityEnabled = serializedObject.FindProperty("m_ShadowVolumeIntensityEnabled"); m_ApplyToSortingLayers = serializedObject.FindProperty("m_ApplyToSortingLayers"); m_VolumetricIntensity = serializedObject.FindProperty("m_LightVolumeIntensity"); m_VolumetricIntensityEnabled = serializedObject.FindProperty("m_LightVolumeIntensityEnabled"); m_BlendStyleIndex = serializedObject.FindProperty("m_BlendStyleIndex"); m_FalloffIntensity = serializedObject.FindProperty("m_FalloffIntensity"); m_NormalMapZDistance = serializedObject.FindProperty("m_NormalMapDistance"); m_NormalMapQuality = serializedObject.FindProperty("m_NormalMapQuality"); m_LightOrder = serializedObject.FindProperty("m_LightOrder"); m_OverlapOperation = serializedObject.FindProperty("m_OverlapOperation"); // Point Light m_PointInnerAngle = serializedObject.FindProperty("m_PointLightInnerAngle"); m_PointOuterAngle = serializedObject.FindProperty("m_PointLightOuterAngle"); m_PointInnerRadius = serializedObject.FindProperty("m_PointLightInnerRadius"); m_PointOuterRadius = serializedObject.FindProperty("m_PointLightOuterRadius"); m_DeprecatedPointLightSprite = serializedObject.FindProperty("m_DeprecatedPointLightCookieSprite"); // Shape Light m_ShapeLightParametricRadius = serializedObject.FindProperty("m_ShapeLightParametricRadius"); m_ShapeLightFalloffSize = serializedObject.FindProperty("m_ShapeLightFalloffSize"); m_ShapeLightParametricSides = serializedObject.FindProperty("m_ShapeLightParametricSides"); m_ShapeLightSprite = serializedObject.FindProperty("m_LightCookieSprite"); m_AnyBlendStyleEnabled = false; var blendStyleIndices = new List <int>(); var blendStyleNames = new List <string>(); var rendererData = Light2DEditorUtility.GetRenderer2DData(); if (rendererData != null) { for (int i = 0; i < rendererData.lightBlendStyles.Length; ++i) { blendStyleIndices.Add(i); ref var blendStyle = ref rendererData.lightBlendStyles[i]; if (blendStyle.maskTextureChannel == Light2DBlendStyle.TextureChannel.None) { blendStyleNames.Add(blendStyle.name); } else { var name = string.Format("{0} ({1})", blendStyle.name, blendStyle.maskTextureChannel); blendStyleNames.Add(name); } m_AnyBlendStyleEnabled = true; } }