using System.Collections; using System.Collections.Generic; using UnityEngine; public class Ellipse : MonoBehaviour { public ParticleSystem particleSystem; List arrayList = new List(); public Transform ellipseTran; public Transform cameraXTran; public Transform cameraYTran; public Transform cameraZTran; // Start is called before the first frame update void Start() { /*ArrayList arrayList = new ArrayList(); for (int i = 0; i < 100000; i++) { int xSymbol = Random.value > 0.5 ? -1 : 1; int ySymbol = Random.value > 0.5 ? -1 : 1; int zSymbol = Random.value > 0.5 ? -1 : 1; var vec = new Vector3(Random.value* xSymbol, Random.value* ySymbol, Random.value* zSymbol); arrayList.Add(vec); } this.DrawPointCloud(arrayList);*/ } // Update is called once per frame void Update() { } //绘制椭圆的大小 public void setEllipseLocalScaleAndCenter(Vector3 radius,Vector3 center) { this.ellipseTran.localScale = radius; this.ellipseTran.localPosition = center; } //设置camera 的观测位置 public void setCameraPos(Vector3 center) { this.cameraXTran.localPosition = new Vector3(this.cameraXTran.localPosition.x, center.y, center.z); this.cameraYTran.localPosition = new Vector3(center.x, this.cameraYTran.localPosition.y,center.z ); this.cameraZTran.localPosition = new Vector3(center.x, center.y, this.cameraZTran.localPosition.z); } public void AddAndUpdatePointArray(Vector3 addPoint) { this.arrayList.Add(addPoint); this.DrawPointCloud(this.arrayList); } public void ClearAndUpdatePointArray() { this.arrayList.Clear(); this.DrawPointCloud(this.arrayList); } ParticleSystem.Particle[] allParticles; public void DrawPointCloud(List drawList) { var main = this.particleSystem.main; main.startSpeed = 0.0f; main.startLifetime = 1000.0f; var pointCount = drawList.Count; allParticles = new ParticleSystem.Particle[pointCount]; main.maxParticles = pointCount; this.particleSystem.Emit(pointCount); this.particleSystem.GetParticles(allParticles); for (int i = 0; i < pointCount; i++) { allParticles[i].position = (Vector3)drawList[i]; allParticles[i].startColor = Color.yellow; allParticles[i].startSize = 0.02f; } this.particleSystem.SetParticles(allParticles, pointCount); } }