Merged in whatwapp/unity-ui-extensions (pull request #10)

Unity API auto-update in UIParticleSystem

Merging as it seems a good way to stop the ever evolving errors.  Will improve the script at a later date.
release
Mauro Ronchi 2017-06-30 16:12:14 +00:00 committed by Simon Jackson
commit d0836e3130
1 changed files with 297 additions and 292 deletions

View File

@ -74,7 +74,8 @@ namespace UnityEngine.UI.Extensions
} }
// automatically set scaling // automatically set scaling
_particleSystem.scalingMode = ParticleSystemScalingMode.Local; var main = _particleSystem.main;
main.scalingMode = ParticleSystemScalingMode.Local;
_particles = null; _particles = null;
setParticleSystemMaterial = true; setParticleSystemMaterial = true;
@ -113,7 +114,7 @@ namespace UnityEngine.UI.Extensions
// prepare particles array // prepare particles array
if (_particles == null) if (_particles == null)
{ {
_particles = new ParticleSystem.Particle[_particleSystem.maxParticles]; _particles = new ParticleSystem.Particle[_particleSystem.main.maxParticles];
} }
// prepare uvs // prepare uvs
@ -177,14 +178,14 @@ namespace UnityEngine.UI.Extensions
ParticleSystem.Particle particle = _particles[i]; ParticleSystem.Particle particle = _particles[i];
// get particle properties // get particle properties
Vector2 position = (_particleSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); Vector2 position = (_particleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
float rotation = -particle.rotation * Mathf.Deg2Rad; float rotation = -particle.rotation * Mathf.Deg2Rad;
float rotation90 = rotation + Mathf.PI / 2; float rotation90 = rotation + Mathf.PI / 2;
Color32 color = particle.GetCurrentColor(_particleSystem); Color32 color = particle.GetCurrentColor(_particleSystem);
float size = particle.GetCurrentSize(_particleSystem) * 0.5f; float size = particle.GetCurrentSize(_particleSystem) * 0.5f;
// apply scale // apply scale
if (_particleSystem.scalingMode == ParticleSystemScalingMode.Shape) if (_particleSystem.main.scalingMode == ParticleSystemScalingMode.Shape)
{ {
position /= canvas.scaleFactor; position /= canvas.scaleFactor;
} }
@ -193,7 +194,11 @@ namespace UnityEngine.UI.Extensions
Vector4 particleUV = _uv; Vector4 particleUV = _uv;
if (_textureSheetAnimation.enabled) if (_textureSheetAnimation.enabled)
{ {
#if UNITY_5_5_OR_NEWER
float frameProgress = 1 - (particle.remainingLifetime / particle.startLifetime);
#else
float frameProgress = 1 - (particle.lifetime / particle.startLifetime); float frameProgress = 1 - (particle.lifetime / particle.startLifetime);
#endif
// float frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.lifetime / particle.startLifetime)); // TODO - once Unity allows MinMaxCurve reading // float frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.lifetime / particle.startLifetime)); // TODO - once Unity allows MinMaxCurve reading
frameProgress = Mathf.Repeat(frameProgress * _textureSheetAnimation.cycleCount, 1); frameProgress = Mathf.Repeat(frameProgress * _textureSheetAnimation.cycleCount, 1);
int frame = 0; int frame = 0;