-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivergence_out
More file actions
105 lines (79 loc) · 2.82 KB
/
Divergence_out
File metadata and controls
105 lines (79 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Part_sys2 : MonoBehaviour {
ParticleSystem ps;
ParticleSystem.Particle[] particles;
private int arraySize = 3;
public Transform gameobj;
int totalParticles;
private void Awake()
{
ps = GetComponent<ParticleSystem>();
// cache particles
totalParticles = arraySize * arraySize * arraySize;
particles = new ParticleSystem.Particle[totalParticles];
InitiateParticles();
}
public void InitiateParticles()
{
int i = 0;
for (int z = 0; z < arraySize; z++)
{
for (int y = 0; y < arraySize; y++)
{
for (int x = 0; x < arraySize; x++)
{
// set positions/rotations in grid
particles[i].startColor = Color.white;
particles[i].position = new Vector3(x - (arraySize - 1) * 0.5f, y - (arraySize - 1) * 0.5f, z - (arraySize - 1) * 0.5f);
particles[i].startSize3D = new Vector3(0.5f, 0.5f, 0.5f);
particles[i].rotation3D = Quaternion.identity.eulerAngles; // rotation.eulerAngles;
i++;
}
}
}
RefreshParticles();
}
void RefreshParticles()
{
// Apply the particle changes to the particle system
ps.SetParticles(particles, totalParticles);
}
public void Divergence_out(Transform target, bool invert)
{
if (target == null) return;
int i = 0;
for (int z = 0; z < arraySize; z++)
{
for (int y = 0; y < arraySize; y++)
{
for (int x = 0; x < arraySize; x++)
{
var ppos = new Vector3(x - (arraySize - 1) * 0.5f, y - (arraySize - 1) * 0.5f, z - (arraySize - 1) * 0.5f);//fixing the whole array centered at (0,0,0)
Vector3 relativePos = target.position - ppos;
if (relativePos.magnitude > Mathf.Epsilon)
{
if (invert == true)
{
relativePos = ppos - target.position;
}
Quaternion rotation = Quaternion.LookRotation(relativePos);
particles[i].rotation3D = rotation.eulerAngles;
}
else // hide, if too close
{
particles[i].startSize3D = Vector3.zero;
}
i++;
}
}
}
RefreshParticles();
}
void Start()
{
Divergence_out(gameobj, true);
}
//var ppos = new Vector3(x - (arraySize - 1), y - (arraySize - 1), z - (arraySize - 1));
}