Skip to content

Instantly share code, notes, and snippets.

@Creta5164
Last active May 2, 2021 12:54
Show Gist options
  • Save Creta5164/92af723389a2867a814eb1c31a53e884 to your computer and use it in GitHub Desktop.
Save Creta5164/92af723389a2867a814eb1c31a53e884 to your computer and use it in GitHub Desktop.
Automated macro to remove sprites from deprecated field in point type 2D lights. (URP 11.0.0^)
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;
public static class RefactorCookies {
[MenuItem("Tools/RefactorAllCookies")]
public static void RefactorAll() {
var allLights = GameObject.FindObjectsOfType<Light2D>();
Debug.Log($"Gathered {allLights.Length} lights.");
var pointLights = allLights.Where(component => component.lightType == Light2D.LightType.Point)
.Select(light => new SerializedObject(light))
.ToList();
Debug.Log($"Gathered {pointLights.Count} point lights.");
int fixedCount = 0;
foreach (var lightCookie in pointLights) {
lightCookie.Update();
if (lightCookie.FindProperty("m_DeprecatedPointLightCookieSprite") is SerializedProperty depLightCookieProp) {
if (depLightCookieProp.objectReferenceValue) {
depLightCookieProp.objectReferenceValue = null;
fixedCount++;
}
}
lightCookie.ApplyModifiedProperties();
}
//Based on : https://twitter.com/AdaRoseCannon/status/1380881598409740292
Debug.Log($"Query OK, {fixedCount} Light2Ds affected.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment