-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParticleMaster.cs
70 lines (65 loc) · 2.33 KB
/
ParticleMaster.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
using System;
using BaseX;
using FrooxEngine;
using FrooxEngine.UIX;
using CodeX;
namespace ParticleWorkshop
{
[Category("Gareth")]
class ParticleMaster : Component, ICustomInspector
{
private GradientStripTexture _gradientTexture;
public readonly SyncList<SyncLinearKey<color>> Colors;
public readonly SyncList<SyncLinearKey<float>> Alpha;
public void BuildInspectorUI(UIBuilder ui)
{
if (_gradientTexture == null || _gradientTexture.IsDisposed)
{
_gradientTexture = ui.Root.AttachComponent<GradientStripTexture>();
_gradientTexture.Format.Value = TextureFormat.RGB24;
UpdateGradient();
}
WorkerInspector.BuildInspectorUI(this, ui);
ui.RawImage(_gradientTexture);
ui.Button("Generate Particle", (b, e) => { GenerateParticle(); });
}
protected override void OnAttach()
{
Colors.Changed += Colors_Changed;
base.OnAttach();
}
private void Colors_Changed(IChangeable obj) => UpdateGradient();
private void UpdateGradient()
{
_gradientTexture.Gradient.Clear();
foreach (SyncLinearKey<color> key in Colors)
{
_gradientTexture.Gradient.Append(key);
}
}
private void GenerateParticle()
{
var pSlot = Slot.AddSlot("Generated Particle");
var pStyle = pSlot.AttachComponent<ParticleStyle>();
var mat = pSlot.AttachComponent<UnlitMaterial>();
foreach (SyncLinearKey<color> key in Colors)
{
pStyle.ColorOverLifetime.Append(key);
}
if (Alpha.Count != 0)
{
mat.BlendMode.Value = BlendMode.Alpha;
foreach (SyncLinearKey<float> key in Alpha)
{
pStyle.AlphaOverLifetime.Append(key);
}
}
pStyle.Material.Target = mat;
pStyle.UseColorOverLifetime.Value = true;
var pEmitter = pSlot.AttachComponent<PointEmitter>();
var pSystem = pSlot.AttachComponent<ParticleSystem>();
pEmitter.System.Target = pSystem;
pSystem.Style.Target = pStyle;
}
}
}