Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using sharemesh mode, same effect will display errors at different scales #333

Open
showrabbit opened this issue Sep 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working v5 feature

Comments

@showrabbit
Copy link

showrabbit commented Sep 23, 2024

When using sharemesh mode, same effect will display errors at different scales.

I have made modifications to the UIParticleUpdater and UIParticle script, tested and fixed this issue. If deemed appropriate, I can consider submitting them to the repository.
The function is modified as follows:

UIParticleUpdater.Refresh

private static void Refresh()
{
    // Do not allow it to be called in the same frame.
    if (s_FrameCount == Time.frameCount) return;
    s_FrameCount = Time.frameCount;
	s_PrimaryParentScales.Clear();
	// Simulate -> Primary
	for (var i = 0; i < s_ActiveParticles.Count; i++)
    {
        var uip = s_ActiveParticles[i];
        if (!uip || !uip.canvas || !uip.isPrimary || !s_UpdatedGroupIds.Add(uip.groupId)) continue;
		var parentLossyScale = uip.transform.parent.lossyScale;
		s_PrimaryParentScales.Add(uip.groupId, parentLossyScale);
		uip.UpdateTransformScale(Vector3.one);
        uip.UpdateRenderers();
    }

    // Simulate -> Others
    for (var i = 0; i < s_ActiveParticles.Count; i++)
    {
        var uip = s_ActiveParticles[i];
        if (!uip || !uip.canvas) continue;

		if (uip.useMeshSharing && s_PrimaryParentScales.TryGetValue(uip.groupId, out var primaryScale))
		{
			var myScale = uip.transform.parent.lossyScale;
			if ((myScale.x < 0.0001 && myScale.x > -0.0001f) ||
				(myScale.y < 0.0001 && myScale.y > -0.0001f) ||
				(myScale.z < 0.0001 && myScale.z > -0.0001f))
			{
				uip.UpdateTransformScale(Vector3.one);
			}
			else
			{
				var ratio = new Vector3(primaryScale.x / myScale.x, primaryScale.y / myScale.y, primaryScale.z / myScale.z);
				uip.UpdateTransformScale(ratio);
			}
		}
		else
		{
			uip.UpdateTransformScale(Vector3.one);
		}


		if (!uip.useMeshSharing)
        {
            uip.UpdateRenderers();
        }
        else if (s_UpdatedGroupIds.Add(uip.groupId))
        {
			s_UpdatedGroupIds.Add(uip.groupId);
			var parentLossyScale = uip.transform.parent.lossyScale;
			s_PrimaryParentScales.Add(uip.groupId, parentLossyScale);
			uip.UpdateRenderers();
        }
    }

    s_UpdatedGroupIds.Clear();

    // Attract
    for (var i = 0; i < s_ActiveAttractors.Count; i++)
    {
        s_ActiveAttractors[i].Attract();
    }
}

UIParticle.UpdateTransformScale

internal void UpdateTransformScale(Vector3 ratio)
{
    _tracker.Clear();
    canvasScale = canvas.rootCanvas.transform.localScale.Inverse();
    parentScale = transform.parent.lossyScale;
    if (autoScalingMode != AutoScalingMode.Transform)
    {
        if (_isScaleStored)
        {
            transform.localScale = _storedScale;
        }

        _isScaleStored = false;
        return;
    }

    var currentScale = transform.localScale;
    if (!_isScaleStored)
    {
        _storedScale = currentScale.IsVisible() ? currentScale : Vector3.one;
        _isScaleStored = true;
    }

    _tracker.Add(this, rectTransform, DrivenTransformProperties.Scale);
	var tempScale = parentScale;
	tempScale.x *= ratio.x;
	tempScale.y *= ratio.y;
	tempScale.z *= ratio.z;
	var newScale = tempScale.Inverse();
    if (currentScale != newScale)
    {
        transform.localScale = newScale;
    }
}
@showrabbit showrabbit added the bug Something isn't working label Sep 23, 2024
@mob-sakai
Copy link
Owner

Thank you for your reporting! (I have made some corrections to your comment)

Pull requests are always welcome.
Please check out the develop branch. 👍

mob-sakai added a commit that referenced this issue Sep 26, 2024
…Particle affects the replicas.

close #333

NOTE: This fix may cause changes in the rendering of existing UIParticles.
@mob-sakai
Copy link
Owner

I have made some adjustments and committed changes based on your comments.
But, this fix may cause changes in the rendering of existing shared UIParticles.
Therefore, we should be cautious about merging this into the release stream.

If you're interested, please use the fix-333 branch for installation.

"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git?path=Packages/src#fix-333"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v5 feature
Projects
None yet
Development

No branches or pull requests

2 participants