mob-sakai / ParticleEffectForUGUI

Render particle effect in UnityUI(uGUI). Maskable, sortable, and no extra Camera/RenderTexture/Canvas.
MIT License
4.41k stars 625 forks source link

How to set particle system in attractor #253

Closed Babiosik closed 1 year ago

Babiosik commented 1 year ago

Hi. How I can change particle system in attractor programmatically? I need attracting many different particle systems, but this particle systems spawning in game process. And another situation when one particle system change attractor after time.

Babiosik commented 1 year ago

Maybe need add setter for m_ParticleSystem in UIParticleAttractor or make more overridable

huseyingulgen commented 1 year ago

I have no idea how to use this component.

Astral-Sheep commented 1 year ago

Hi. I'm a bit late so you may have already figured out, but I'll give an answer anyway since some people could look at this question too.

The field m_ParticleSystem in UIParticleAttractor is private and has no property, so you can't access it. However, C# has some tools to access fields, properties and other things in the namespace System.Reflection. In this case, the code would look like this:

Type type = attractor.GetType(); // Or typeof(UIParticleAttractor)

FieldInfo field = type.GetField("m_ParticleSystem", BindingFlags.NonPublic | BindingFlags.Instance);

field.SetValue(attractor, particleSystem);

If the attractor is disabled you also need to set enabled to true, but that's it.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.2.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: