Ellipse.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Ellipse : MonoBehaviour
  5. {
  6. private ParticleSystem particleSystem0;
  7. List<Vector3> arrayList = new List<Vector3>();
  8. public Transform ellipseTran;
  9. public Transform cameraXTran;
  10. public Transform cameraYTran;
  11. public Transform cameraZTran;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. particleSystem0 = GetComponentInChildren<ParticleSystem>();
  16. /*ArrayList arrayList = new ArrayList();
  17. for (int i = 0; i < 100000; i++) {
  18. int xSymbol = Random.value > 0.5 ? -1 : 1;
  19. int ySymbol = Random.value > 0.5 ? -1 : 1;
  20. int zSymbol = Random.value > 0.5 ? -1 : 1;
  21. var vec = new Vector3(Random.value* xSymbol, Random.value* ySymbol, Random.value* zSymbol);
  22. arrayList.Add(vec);
  23. }
  24. this.DrawPointCloud(arrayList);*/
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. }
  30. //绘制椭圆的大小
  31. public void setEllipseLocalScaleAndCenter(Vector3 radius,Vector3 center) {
  32. this.ellipseTran.localScale = radius;
  33. this.ellipseTran.localPosition = center;
  34. }
  35. //设置camera 的观测位置
  36. public void setCameraPos(Vector3 center)
  37. {
  38. this.cameraXTran.localPosition = new Vector3(this.cameraXTran.localPosition.x, center.y, center.z);
  39. this.cameraYTran.localPosition = new Vector3(center.x, this.cameraYTran.localPosition.y,center.z );
  40. this.cameraZTran.localPosition = new Vector3(center.x, center.y, this.cameraZTran.localPosition.z);
  41. }
  42. public void AddAndUpdatePointArray(Vector3 addPoint) {
  43. this.arrayList.Add(addPoint);
  44. this.DrawPointCloud(this.arrayList);
  45. }
  46. public void ClearAndUpdatePointArray() {
  47. this.arrayList.Clear();
  48. this.DrawPointCloud(this.arrayList);
  49. }
  50. ParticleSystem.Particle[] allParticles;
  51. public void DrawPointCloud(List<Vector3> drawList)
  52. {
  53. var main = this.particleSystem0.main;
  54. main.startSpeed = 0.0f;
  55. main.startLifetime = 1000.0f;
  56. var pointCount = drawList.Count;
  57. allParticles = new ParticleSystem.Particle[pointCount];
  58. main.maxParticles = pointCount;
  59. this.particleSystem0.Emit(pointCount);
  60. this.particleSystem0.GetParticles(allParticles);
  61. for (int i = 0; i < pointCount; i++)
  62. {
  63. allParticles[i].position = (Vector3)drawList[i];
  64. allParticles[i].startColor = Color.yellow;
  65. allParticles[i].startSize = 0.02f;
  66. }
  67. this.particleSystem0.SetParticles(allParticles, pointCount);
  68. }
  69. }