WFX_ParticleMeshBillboard.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(ParticleSystemRenderer))]
  4. public class WFX_ParticleMeshBillboard : BaseBehaviour
  5. {
  6. private void Awake()
  7. {
  8. this.mesh = UnityEngine.Object.Instantiate<Mesh>(base.GetComponent<ParticleSystemRenderer>().mesh);
  9. base.GetComponent<ParticleSystemRenderer>().mesh = this.mesh;
  10. this.vertices = new Vector3[this.mesh.vertices.Length];
  11. for (int i = 0; i < this.vertices.Length; i++)
  12. {
  13. this.vertices[i] = this.mesh.vertices[i];
  14. }
  15. this.rvertices = new Vector3[this.vertices.Length];
  16. }
  17. private void OnWillRenderObject()
  18. {
  19. if (this.mesh == null || Camera.current == null)
  20. {
  21. return;
  22. }
  23. Quaternion rotation = Quaternion.LookRotation(Camera.current.transform.forward, Camera.current.transform.up);
  24. Quaternion rotation2 = Quaternion.Inverse(base.transform.rotation);
  25. for (int i = 0; i < this.rvertices.Length; i++)
  26. {
  27. this.rvertices[i] = rotation * this.vertices[i];
  28. this.rvertices[i] = rotation2 * this.rvertices[i];
  29. }
  30. this.mesh.vertices = this.rvertices;
  31. }
  32. private Mesh mesh;
  33. private Vector3[] vertices;
  34. private Vector3[] rvertices;
  35. }