summaryrefslogtreecommitdiff
path: root/Runtime/Export/ParticleSystemBindings.txt
blob: f3d3a0785eb28bd2bd830a9612ac2c92021d6cfa (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
C++RAW

#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
//#include "Runtime/Graphics/ParticleSystem/ParticleCollisionEvents.h"
#include "Runtime/Graphics/ParticleSystem/ParticleSystem.h"
#include "Runtime/Graphics/ParticleSystem/ParticleSystemRenderer.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Filters/Mesh/LodMesh.h"
#include "Runtime/Scripting/Scripting.h"
#if ENABLE_PHYSICS
#include "Runtime/Dynamics/Collider.h"
#endif

#if UNITY_EDITOR
#include "Editor/Src/ParticleSystem/ParticleSystemEditor.h"
#endif

using namespace Unity;
using namespace std;

CSRAW
using System;
using System.Collections.Generic;

namespace UnityEngine
{

C++RAW

// The rendering mode for particle systems (Shuriken).
ENUM ParticleSystemRenderMode
	// Render particles as billboards facing the player. (Default)
	Billboard = 0,
	// Stretch particles in the direction of motion.
	Stretch = 1,
	// Render particles as billboards always facing up along the y-Axis.
	HorizontalBillboard = 2,
	// Render particles as billboards always facing the player, but not pitching along the x-Axis.
	VerticalBillboard = 3,
	
	// Render particles as meshes.
	Mesh = 4
END

// The simulation space for particle systems (Shuriken).
ENUM ParticleSystemSimulationSpace
	// Use local simulation space. (Default)
	Local = 0,
	// Use world simulation space.
	World = 1
END

// Script interface for particle systems (Shuriken).

CLASS ParticleSystem : Component

// Script interface for a Particle
STRUCT Particle
	CSRAW
	private Vector3 m_Position;
	private Vector3 m_Velocity;
	private Vector3 m_AnimatedVelocity;
	private Vector3 m_AxisOfRotation;
	private float m_Rotation;
	private float m_AngularVelocity;
	private float m_Size;
	private Color32 m_Color;
	private UInt32 m_RandomSeed;
	private float m_Lifetime;
	private float m_StartLifetime;
	private float m_EmitAccumulator0;
	private float m_EmitAccumulator1;
	
	// The position of the particle.
	CSRAW public Vector3 position { get { return m_Position; } set { m_Position = value; } }
		
	// The velocity of the particle.
	CSRAW public Vector3 velocity { get { return m_Velocity; } set { m_Velocity = value; } }

	// The lifetime of the particle.
	CSRAW public float lifetime { get { return m_Lifetime; } set { m_Lifetime = value; } }

	// The starting lifetime of the particle.
	CSRAW public float startLifetime { get { return m_StartLifetime; } set { m_StartLifetime = value; } }
	
	// The size of the particle.
	CSRAW public float size { get { return m_Size; } set { m_Size = value; } }
	
	// The rotation axis of the particle.
	CSRAW public Vector3 axisOfRotation { get { return m_AxisOfRotation; } set { m_AxisOfRotation = value; } }

	// The rotation of the particle.
	CSRAW public float rotation { get { return m_Rotation * Mathf.Rad2Deg; } set { m_Rotation = value * Mathf.Deg2Rad; } }

	// The angular velocity of the particle.
	CSRAW public float angularVelocity { get { return m_AngularVelocity * Mathf.Rad2Deg; } set { m_AngularVelocity = value * Mathf.Deg2Rad; } }

	// The color of the particle.
	CSRAW public Color32 color { get { return m_Color; } set { m_Color = value; } }	

	// The random value of the particle.
	CONDITIONAL !UNITY_FLASH
	OBSOLETE warning randomValue property is deprecated. Use randomSeed instead to control random behavior of particles.
	CSRAW public float randomValue { get { return BitConverter.ToSingle(BitConverter.GetBytes(m_RandomSeed), 0); } set { m_RandomSeed = BitConverter.ToUInt32(BitConverter.GetBytes(value), 0); } }	
	
	// The random seed of the particle.
	CSRAW public UInt32 randomSeed { get { return m_RandomSeed; } set { m_RandomSeed = value; } }	
END

CONDITIONAL ENABLE_PHYSICS
CUSTOM static internal Collider InstanceIDToCollider(int instanceID)
 { 
    return instanceID != 0 ? Scripting::ScriptingWrapperFor (PPtr<Collider> (instanceID)) : SCRIPTING_NULL;
 }

// Script interface for a Particle collision event
STRUCT CollisionEvent
	CSRAW
	private Vector3 m_Intersection;
	private Vector3 m_Normal;
	private Vector3 m_Velocity;
	private int m_ColliderInstanceID;

	CSRAW public Vector3 intersection { get { return m_Intersection; }  }
	CSRAW public Vector3 normal { get { return m_Normal; }  }
	CSRAW public Vector3 velocity { get { return m_Velocity; }  }
	CONDITIONAL ENABLE_PHYSICS
	CSRAW public Collider collider { get { return InstanceIDToCollider(m_ColliderInstanceID); } }
END

	// Start delay in seconds.
	SYNC_JOBS AUTO_PROP float startDelay GetStartDelay SetStartDelay

	// Is the particle system playing right now ?
	SYNC_JOBS AUTO_PROP bool isPlaying IsPlaying

	// Is the particle system stopped right now ?
	SYNC_JOBS AUTO_PROP bool isStopped IsStopped	
	
	// Is the particle system paused right now ?
	SYNC_JOBS AUTO_PROP bool isPaused IsPaused
	
	// Is the particle system looping?
	SYNC_JOBS AUTO_PROP bool loop GetLoop SetLoop
	
	// If set to true, the particle system will automatically start playing on startup.
	SYNC_JOBS AUTO_PROP bool playOnAwake GetPlayOnAwake SetPlayOnAwake

	// Playback position in seconds.
	SYNC_JOBS AUTO_PROP float time GetSecPosition SetSecPosition

	// The duration of the particle system in seconds (Read Only)
	SYNC_JOBS AUTO_PROP float duration GetLengthInSec

	// The playback speed of the particle system. 1 is normal playback speed.
	SYNC_JOBS AUTO_PROP float playbackSpeed GetPlaybackSpeed SetPlaybackSpeed

	// The current number of particles (Read Only).
	SYNC_JOBS AUTO_PROP int particleCount GetParticleCount

	// Safe array size for the collision event array used with GetCollisionEvents (Read Only).
	AUTO_PROP int safeCollisionEventSize GetSafeCollisionEventSize	
	
	// When set to false, the particle system will not emit particles
	SYNC_JOBS AUTO_PROP bool enableEmission GetEnableEmission SetEnableEmission
	
	// The rate of emission
	SYNC_JOBS AUTO_PROP float emissionRate GetEmissionRate SetEmissionRate
	
	// The initial speed of particles when emitted. When using curves, this values acts as a scale on the curve.
	SYNC_JOBS AUTO_PROP float startSpeed GetStartSpeed SetStartSpeed
	
	// The initial size of particles when emitted. When using curves, this values acts as a scale on the curve.
	SYNC_JOBS AUTO_PROP float startSize GetStartSize SetStartSize
	
	// The initial color of particles when emitted.
	SYNC_JOBS AUTO_PROP Color startColor GetStartColor SetStartColor
	
	// The initial rotation of particles when emitted. When using curves, this values acts as a scale on the curve.
	SYNC_JOBS AUTO_PROP float startRotation GetStartRotation SetStartRotation
	
	// The total lifetime in seconds that particles will have when emitted. When using curves, this values acts as a scale on the curve. This value is set in the particle when it is create by the particle system.
	SYNC_JOBS AUTO_PROP float startLifetime GetStartLifeTime SetStartLifeTime
	
	// Scale being applied to the gravity defined by [[Physics.gravity]].
	SYNC_JOBS AUTO_PROP float gravityModifier GetGravityModifier SetGravityModifier

	// Maximum number of particles.
	SYNC_JOBS AUTO_PROP int maxParticles GetMaxNumParticles SetMaxNumParticles
	
	// Selects the space in which to simulate particles; can be local (default) or world.
	SYNC_JOBS AUTO_PROP ParticleSystemSimulationSpace simulationSpace GetSimulationSpace SetSimulationSpace

	// Random seed used for the particle system emission. If set to 0, it will be assigned a random value on awake.
	SYNC_JOBS AUTO_PROP UInt32 randomSeed GetRandomSeed SetRandomSeed
	
	// Set the particles of this particle system. /size/ is the number of particles that is set.
	SYNC_JOBS CUSTOM void SetParticles (ParticleSystem.Particle[] particles, int size)
	{
		unsigned int actualSize = GetScriptingArraySize(particles);
		if (size < 0 || actualSize < size)
			size = actualSize;
	
		self->SetParticlesExternal (Scripting::GetScriptingArrayStart<ParticleSystemParticle>(particles), size);
	}
	
	// Get the particles of this particle system. Returns the number of particles written to the input particle array. 
	SYNC_JOBS CUSTOM int GetParticles (ParticleSystem.Particle[] particles)
	{
		int size = std::min<unsigned int>(self->GetParticleCount(), GetScriptingArraySize(particles));
		self->GetParticlesExternal (Scripting::GetScriptingArrayStart<ParticleSystemParticle>(particles), size);
		return size;
	}
	
	// Get the particle collision events recorded for this particle system. Returns the number of particles written to the input collision event array. 
	CUSTOM int GetCollisionEvents (GameObject go, ParticleSystem.CollisionEvent[] collisionEvents)
	{
		return self->GetCollisionEventsExternal (go->GetInstanceID (), Scripting::GetScriptingArrayStart<MonoParticleCollisionEvent>(collisionEvents), GetScriptingArraySize(collisionEvents));
	}

	SYNC_JOBS CUSTOM private void Internal_Simulate (float t, bool restart) { self->Simulate (t, restart); }
	SYNC_JOBS CUSTOM private void Internal_Play () { self->Play (); }
	SYNC_JOBS CUSTOM private void Internal_Stop () { self->Stop (); }
	SYNC_JOBS CUSTOM private void Internal_Pause () { self->Pause (); }
	SYNC_JOBS CUSTOM private void Internal_Clear () { self->Clear (); }
	SYNC_JOBS CUSTOM private bool Internal_IsAlive () { return self->IsAlive(); }

	// Fastforwards the particle system by simulating particles over given period of time, then pauses it.
	CSRAW public void Simulate (float t, bool withChildren = true, bool restart = true)
	{
		if (withChildren)
		{	
			ParticleSystem[] emitters = GetParticleSystems (this);
			foreach (var emitter in emitters)
				emitter.Internal_Simulate (t, restart);
		}
		else
		{
			Internal_Simulate (t, restart);
		}		
	}
	
	// Plays the particle system.
	CSRAW public void Play (bool withChildren = true)
	{
		if (withChildren)
		{	
			ParticleSystem[] emitters = GetParticleSystems (this);
			foreach (var emitter in emitters)
				emitter.Internal_Play ();
		}
		else
		{
			Internal_Play ();
		}
	}
	
	// Stops playing the particle system.
	CSRAW public void Stop (bool withChildren = true)
	{
		if (withChildren)
		{	
			ParticleSystem[] emitters = GetParticleSystems (this);
			foreach (var emitter in emitters)
				emitter.Internal_Stop ();
		}
		else
		{
			Internal_Stop ();
		}	
	}
	
	// Pauses playing the particle system.
	CSRAW public void Pause (bool withChildren = true)
	{
		if (withChildren)
		{	
			ParticleSystem[] emitters = GetParticleSystems (this);
			foreach (var emitter in emitters)
				emitter.Internal_Pause ();
		}
		else
		{
			Internal_Pause ();
		}
		
	}

	// Remove all particles in the particle system
	CSRAW public void Clear (bool withChildren = true)
	{
		if (withChildren)
		{	
			ParticleSystem[] emitters = GetParticleSystems (this);
			foreach (var emitter in emitters)
				emitter.Internal_Clear ();
		}
		else
		{
			Internal_Clear ();
		}	
	}

	// Is the particle system done emitting particles and are all particles dead?
	CSRAW public bool IsAlive (bool withChildren = true)
	{
		if (withChildren)
		{
			ParticleSystem[] emitters = GetParticleSystems (this);
			foreach (var emitter in emitters)
				if(emitter.Internal_IsAlive())
					return true;
			return false;
		}

		return this.Internal_IsAlive ();
	}
	
	// Emit /count/ particles immediately.
	SYNC_JOBS AUTO void Emit (int count);
	
	// Emit a single particle with given parameters.
	CSRAW public void Emit(Vector3 position, Vector3 velocity, float size, float lifetime, Color32 color)
	{
		ParticleSystem.Particle particle = new ParticleSystem.Particle();
		particle.position = position; 
		particle.velocity = velocity;
		particle.lifetime = lifetime; 
		particle.startLifetime = lifetime;
		particle.size = size;
		particle.rotation = 0.0f;
		particle.angularVelocity = 0.0f;
		particle.color = color;
		particle.randomSeed = 5;
		Internal_Emit(ref particle);
	}

	// Emit a single particle.
	CSRAW public void Emit(ParticleSystem.Particle particle)
	{
		Internal_Emit(ref particle);
	}	
	
	SYNC_JOBS CUSTOM private void Internal_Emit (ref ParticleSystem.Particle particle)
	{
		self->EmitParticleExternal (&particle);
	}


	// Returns a list with 'root' and all its direct children.
	CSRAW static internal ParticleSystem[] GetParticleSystems (ParticleSystem root)
	{
		if (!root)
			return null;

		List<ParticleSystem> particleSystems = new List<ParticleSystem>();
		particleSystems.Add(root);
		GetDirectParticleSystemChildrenRecursive(root.transform, particleSystems);
		return particleSystems.ToArray();
	}

	// Adds only active Particle Systems
	CSRAW static private void GetDirectParticleSystemChildrenRecursive(Transform transform, List<ParticleSystem> particleSystems)
	{
		foreach (Transform childTransform in transform)
		{
			ParticleSystem ps = childTransform.gameObject.GetComponent<ParticleSystem>();
			if (ps != null)
			{
				// Note: we do not check for if the gameobject is active (we want inactive particle systems as well due prefabs)
				particleSystems.Add (ps);
				GetDirectParticleSystemChildrenRecursive(childTransform, particleSystems);
			}
		}
	}
	
	CONDITIONAL UNITY_EDITOR
	//*undocumented
	CUSTOM internal void SetupDefaultType (int type)
	{	
		ParticleSystemEditor::SetupDefaultParticleSystemType(*self, (ParticleSystemSubType)type);
	}
END

// Renders particles on to the screen (Shuriken).
CLASS ParticleSystemRenderer : Renderer

	//  How particles are drawn.
	AUTO_PROP ParticleSystemRenderMode renderMode GetRenderMode SetRenderMode

	// How much are the particles stretched in their direction of motion.
	AUTO_PROP float lengthScale GetLengthScale SetLengthScale

	// How much are the particles strectched depending on "how fast they move"
	AUTO_PROP float velocityScale GetVelocityScale SetVelocityScale

	// How much are the particles strected depending on the [[Camera]]'s speed.
	AUTO_PROP float cameraVelocityScale GetCameraVelocityScale SetCameraVelocityScale

	// Clamp the maximum particle size.
	AUTO_PROP float maxParticleSize GetMaxParticleSize SetMaxParticleSize
	
	// Mesh used as particle instead of billboarded texture
	AUTO_PTR_PROP Mesh mesh GetMesh SetMesh

	CONDITIONAL UNITY_EDITOR
	CUSTOM_PROP internal bool editorEnabled { return self->GetEditorEnabled();} {self->SetEditorEnabled(value);} 
END

CSRAW
}