From aa0d56f9faa05e9679d4b476bcf135eafb1b8af9 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Thu, 9 Jun 2022 01:47:48 +0900 Subject: [PATCH] feat: adaptive scaling for UI Changing the canvas size does not affect the effect size or position. This feature provides a constant-looking output and makes it easier to adjust effects. BREAKING CHANGE: If you update to v4, you may be required to adjust your UIParticle.scale. --- Scripts/UIParticle.cs | 4 ++++ Scripts/UIParticleRenderer.cs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index 4b576ae..55e188a 100644 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -212,6 +212,10 @@ namespace Coffee.UIExtensions public void UpdateRenderers() { var newScale = Vector3.one; + //if (uiScaling) + { + newScale = transform.parent.lossyScale.Inverse(); + } if (transform.localScale != newScale) { transform.localScale = newScale; diff --git a/Scripts/UIParticleRenderer.cs b/Scripts/UIParticleRenderer.cs index 25ca2eb..cb02a51 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -280,6 +280,10 @@ namespace Coffee.UIExtensions { Profiler.BeginSample("[UIParticleRenderer] GetWorldScale"); var scale = _parent.scale3D; + //if (_parent.uiScaling) + { + scale.Scale(_parent.transform.localScale.Inverse()); + } //else if (_parent.scalingMode == UIParticle.ScalingMode.UI && _particleSystem.main.scalingMode != ParticleSystemScalingMode.Hierarchy) //{ // var gscale = _parent.transform.lossyScale.GetScaled(canvas.transform.lossyScale.Inverse()); @@ -336,7 +340,8 @@ namespace Coffee.UIExtensions private void ResolveResolutionChange(Vector3 psPos, Vector3 scale) { var screenSize = new Vector2Int(Screen.width, Screen.height); - if ((_prevScreenSize != screenSize || _prevScale != scale) && _particleSystem.main.simulationSpace == ParticleSystemSimulationSpace.World && _parent.uiScaling) + //if ((_prevScreenSize != screenSize || _prevScale != scale) && _particleSystem.main.simulationSpace == ParticleSystemSimulationSpace.World && _parent.uiScaling) + if ((_prevScreenSize != screenSize || _prevScale != scale) && _particleSystem.main.simulationSpace == ParticleSystemSimulationSpace.World) { // Update particle array size and get particles. var size = _particleSystem.particleCount;