| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Ellipse : MonoBehaviour
- {
- private ParticleSystem particleSystem0;
- [System.NonSerialized] public List<Vector3> arrayList = new List<Vector3>();
- public Transform ellipseTran;
- public Transform cameraXTran;
- public Transform cameraYTran;
- public Transform cameraZTran;
- private Camera cameraX;
- private Camera cameraY;
- private Camera cameraZ;
- // Start is called before the first frame update
- void Start()
- {
- cameraX = cameraXTran.GetComponent<Camera>();
- cameraY = cameraYTran.GetComponent<Camera>();
- cameraZ = cameraZTran.GetComponent<Camera>();
- particleSystem0 = GetComponentInChildren<ParticleSystem>();
- /*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);*/
- }
- //绘制椭圆的大小
- public void setEllipseLocalScaleAndCenter(Vector3 radius,Vector3 center) {
- this.ellipseTran.localScale = radius;
- this.ellipseTran.localPosition = center;
- }
- public void setCameraPos(Vector3 center)
- {
- this.cameraXTran.localPosition = new Vector3(center.x - 10, center.y, center.z);
- this.cameraYTran.localPosition = new Vector3(center.x, center.y + 10, center.z);
- this.cameraZTran.localPosition = new Vector3(center.x, center.y, center.z - 10);
- // 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 setCameraSize(Vector3 circleSize) {
- Vector3 vs = new Vector3();
- vs.x = Mathf.Abs(circleSize.x);
- vs.y = Mathf.Abs(circleSize.y);
- vs.z = Mathf.Abs(circleSize.z);
- this.cameraX.orthographicSize = Mathf.Max(circleSize.y, circleSize.z) / 2 * 1.5f;
- this.cameraY.orthographicSize = Mathf.Max(circleSize.x, circleSize.z) / 2 * 1.5f;
- this.cameraZ.orthographicSize = Mathf.Max(circleSize.x, circleSize.y) / 2 * 1.5f;
- }
- 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<Vector3> drawList)
- {
- var main = this.particleSystem0.main;
- main.startSpeed = 0.0f;
- main.startLifetime = 1000.0f;
- var pointCount = drawList.Count;
- allParticles = new ParticleSystem.Particle[pointCount];
- main.maxParticles = pointCount;
- this.particleSystem0.Emit(pointCount);
- this.particleSystem0.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.particleSystem0.SetParticles(allParticles, pointCount);
- }
- }
|