pull/147/merge
Scott Richmond 2023-01-20 00:09:02 +10:00 committed by GitHub
commit fd84aa7079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -248,6 +248,8 @@ namespace Coffee.UISoftMask
#if UNITY_EDITOR
s_GameVPId = Shader.PropertyToID("_GameVP");
s_GameTVPId = Shader.PropertyToID("_GameTVP");
UnityEditor.SceneView.beforeSceneGui -= SceneView_beforeSceneGui; // For safety
UnityEditor.SceneView.beforeSceneGui += SceneView_beforeSceneGui;
#endif
}
@ -269,13 +271,16 @@ namespace Coffee.UISoftMask
MaterialCache.Unregister(_effectMaterialHash);
_effectMaterialHash = k_InvalidHash;
#if UNITY_EDITOR
UnityEditor.SceneView.beforeSceneGui -= SceneView_beforeSceneGui;
#endif
}
#if UNITY_EDITOR
private void UpdateMaterialForSceneView(Material mat)
{
if(!mat || !graphic || !graphic.canvas || !mat.shader || !mat.shader.name.EndsWith(" (SoftMaskable)")) return;
// Set view and projection matrices.
Profiler.BeginSample("Set view and projection matrices");
var c = graphic.canvas.rootCanvas;
@ -301,9 +306,12 @@ namespace Coffee.UISoftMask
Profiler.EndSample();
}
private void LateUpdate()
private void SceneView_beforeSceneGui(UnityEditor.SceneView obj)
{
UpdateMaterialForSceneView(modifiedMaterial);
var parentCanvas = GetComponentInParent<Canvas>(); // Don't think we can cache this in case this go is moved to another parent
if (parentCanvas != null && parentCanvas.enabled) // Only do this expensive call if the UI element is active
UpdateMaterialForSceneView(modifiedMaterial);
}