Advertisement
polyfied

Particle Playground - Translate particles w. multithreading

Nov 11th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using ParticlePlayground;
  4.  
  5. /// <summary>
  6. /// Move all particles in a particle system. Enable multithreading to run the translation asynchronously on another thread.
  7. /// </summary>
  8. [ExecuteInEditMode()]
  9. public class TranslateParticles : MonoBehaviour {
  10.  
  11.     public PlaygroundParticlesC particles;
  12.     public Vector3 translation;
  13.     public bool multithreading;
  14.  
  15.     void Update () {
  16.         if (particles==null) return;
  17.         if (multithreading) {
  18.             PlaygroundC.RunAsync(()=>{
  19.                 Translate();
  20.             });
  21.         } else Translate();
  22.     }
  23.  
  24.     void Translate () {
  25.         for (int i = 0; i<particles.particleCount; i++)
  26.             particles.Translate (i, translation*PlaygroundC.globalDeltaTime);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement