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.
pull/225/head
mob-sakai 2022-06-09 01:47:48 +09:00
parent c6644a2132
commit aa0d56f9fa
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -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;