Ellipse.cs 2.6 KB

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