-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRandomParticles.cs
82 lines (76 loc) · 3.41 KB
/
RandomParticles.cs
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
using System;
using BaseX;
using FrooxEngine;
using FrooxEngine.UIX;
namespace ParticleWorkshop
{
//TODO: Less weird repition, better use of objects!
[Category("Gareth")]
class RandomParticles : Component, ICustomInspector
{
[Range(1, 8)]
public readonly Sync<int> RandomIterations;
public void BuildInspectorUI(UIBuilder ui)
{
WorkerInspector.BuildInspectorUI(this, ui);
ui.Button("Random Color Particle", (b, e) => { RandomColorGenerator(); });
ui.Button("Random Alpha Particle", (b, e) => { RandomAlphaGenerator(); });
ui.Button("Random Color and Alpha Particle", (b, e) => { RandomColorAlphaGenerator(); });
}
protected override void OnAttach()
{
RandomIterations.Value = 1;
base.OnAttach();
}
private void RandomColorGenerator()
{
var pSlot = Slot.AddSlot("Random Colored Particle");
var pStyle = pSlot.AttachComponent<ParticleStyle>();
pStyle.Material.Target = pSlot.AttachComponent<UnlitMaterial>();
for (int i = 0; i < RandomIterations; i++)
{
pStyle.ColorOverLifetime.InsertKey(RandomX.Range(0.0f, 1.0f), new color(RandomX.Range(0.0f, 1.0f), RandomX.Range(0.0f, 1.0f), RandomX.Range(0.0f, 1.0f), 1.0f));
}
pStyle.UseColorOverLifetime.Value = true;
var pEmitter = pSlot.AttachComponent<PointEmitter>();
var pSystem = pSlot.AttachComponent<ParticleSystem>();
pEmitter.System.Target = pSystem;
pSystem.Style.Target = pStyle;
}
private void RandomAlphaGenerator()
{
var pSlot = Slot.AddSlot("Random Alpha Particle");
var pStyle = pSlot.AttachComponent<ParticleStyle>();
var mat = pSlot.AttachComponent<UnlitMaterial>();
mat.BlendMode.Value = BlendMode.Alpha;
pStyle.Material.Target = mat;
for (int i = 0; i < RandomIterations; i++)
{
pStyle.AlphaOverLifetime.InsertKey(RandomX.Range(0.0f, 1.0f), RandomX.Range(0.0f, 1.0f));
}
pStyle.UseColorOverLifetime.Value = true;
var pEmitter = pSlot.AttachComponent<PointEmitter>();
var pSystem = pSlot.AttachComponent<ParticleSystem>();
pEmitter.System.Target = pSystem;
pSystem.Style.Target = pStyle;
}
private void RandomColorAlphaGenerator()
{
var pSlot = Slot.AddSlot("Random Colored/Alpha Particle");
var pStyle = pSlot.AttachComponent<ParticleStyle>();
var mat = pSlot.AttachComponent<UnlitMaterial>();
mat.BlendMode.Value = BlendMode.Alpha;
pStyle.Material.Target = mat;
for (int i = 0; i < RandomIterations; i++)
{
pStyle.ColorOverLifetime.InsertKey(RandomX.Range(0.0f, 1.0f), new color(RandomX.Range(0.0f, 1.0f), RandomX.Range(0.0f, 1.0f), RandomX.Range(0.0f, 1.0f), 1.0f));
pStyle.AlphaOverLifetime.InsertKey(RandomX.Range(0.0f, 1.0f), RandomX.Range(0.0f, 1.0f));
}
pStyle.UseColorOverLifetime.Value = true;
var pEmitter = pSlot.AttachComponent<PointEmitter>();
var pSystem = pSlot.AttachComponent<ParticleSystem>();
pEmitter.System.Target = pSystem;
pSystem.Style.Target = pStyle;
}
}
}