added animation package and made small changes
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
[RequireComponent(typeof(Light))]
|
||||
|
||||
public class AnimatedLight : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
new Light light;
|
||||
|
||||
public float time { get; set; }
|
||||
public float duration = 1.0f;
|
||||
|
||||
bool evaluating = true;
|
||||
|
||||
public Gradient colourOverLifetime;
|
||||
|
||||
public AnimationCurve intensityOverLifetime = new AnimationCurve(
|
||||
|
||||
new Keyframe(0.0f, 0.0f),
|
||||
new Keyframe(0.5f, 1.0f),
|
||||
new Keyframe(1.0f, 0.0f));
|
||||
|
||||
// ...
|
||||
|
||||
public bool loop = true;
|
||||
public bool autoDestruct = false;
|
||||
|
||||
// ...
|
||||
|
||||
Color startColour;
|
||||
float startIntensity;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
light = GetComponent<Light>();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
startColour = light.color;
|
||||
startIntensity = light.intensity;
|
||||
|
||||
light.color = startColour * colourOverLifetime.Evaluate(0.0f);
|
||||
light.intensity = startIntensity * intensityOverLifetime.Evaluate(0.0f);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
// Reset for next OnEnable if required.
|
||||
|
||||
light.color = startColour;
|
||||
light.intensity = startIntensity;
|
||||
|
||||
time = 0.0f;
|
||||
evaluating = true;
|
||||
|
||||
light.color = startColour * colourOverLifetime.Evaluate(0.0f);
|
||||
light.intensity = startIntensity * intensityOverLifetime.Evaluate(0.0f);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (evaluating)
|
||||
{
|
||||
if (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
|
||||
if (time > duration)
|
||||
{
|
||||
if (autoDestruct)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else if (loop)
|
||||
{
|
||||
time = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
time = duration;
|
||||
evaluating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
if (time <= duration)
|
||||
{
|
||||
float normalizedTime = time / duration;
|
||||
|
||||
light.color = startColour * colourOverLifetime.Evaluate(normalizedTime);
|
||||
light.intensity = startIntensity * intensityOverLifetime.Evaluate(normalizedTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 244de3f32e1c0b1439bb7ff73ac59484
|
||||
timeCreated: 1436042081
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class Billboard : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
transform.LookAt(Camera.main.transform.position);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2eb8dd8b78862644282595779b5ba819
|
||||
timeCreated: 1458196122
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,244 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
public enum CameraShakeTarget
|
||||
{
|
||||
Position,
|
||||
Rotation
|
||||
}
|
||||
public enum CameraShakeAmplitudeCurve
|
||||
{
|
||||
Constant,
|
||||
|
||||
// Fade in fully at 25%, 50%, and 75% of lifetime.
|
||||
|
||||
FadeInOut25,
|
||||
FadeInOut50,
|
||||
FadeInOut75,
|
||||
}
|
||||
public enum CameraShakeAmplitudeOverDistanceCurve
|
||||
{
|
||||
Constant,
|
||||
|
||||
LinearFadeIn,
|
||||
LinearFadeOut
|
||||
}
|
||||
|
||||
public class CameraShake : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Shake
|
||||
{
|
||||
public float amplitude = 1.0f;
|
||||
public float frequency = 1.0f;
|
||||
|
||||
public float duration;
|
||||
|
||||
[HideInInspector]
|
||||
public CameraShakeTarget target;
|
||||
|
||||
float timeRemaining;
|
||||
|
||||
Vector2 perlinNoiseX;
|
||||
Vector2 perlinNoiseY;
|
||||
Vector2 perlinNoiseZ;
|
||||
|
||||
[HideInInspector]
|
||||
public Vector3 noise;
|
||||
|
||||
public AnimationCurve amplitudeOverLifetimeCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 0.0f));
|
||||
|
||||
public void Init()
|
||||
{
|
||||
timeRemaining = duration;
|
||||
ApplyRandomSeed();
|
||||
}
|
||||
void Init(float amplitude, float frequency, float duration, CameraShakeTarget target)
|
||||
{
|
||||
this.amplitude = amplitude;
|
||||
this.frequency = frequency;
|
||||
|
||||
this.duration = duration;
|
||||
timeRemaining = duration;
|
||||
|
||||
this.target = target;
|
||||
|
||||
ApplyRandomSeed();
|
||||
}
|
||||
|
||||
public void ApplyRandomSeed()
|
||||
{
|
||||
float randomRange = 32.0f;
|
||||
|
||||
perlinNoiseX.x = Random.Range(-randomRange, randomRange);
|
||||
perlinNoiseX.y = Random.Range(-randomRange, randomRange);
|
||||
|
||||
perlinNoiseY.x = Random.Range(-randomRange, randomRange);
|
||||
perlinNoiseY.y = Random.Range(-randomRange, randomRange);
|
||||
|
||||
perlinNoiseZ.x = Random.Range(-randomRange, randomRange);
|
||||
perlinNoiseZ.y = Random.Range(-randomRange, randomRange);
|
||||
}
|
||||
|
||||
public Shake(float amplitude, float frequency, float duration, CameraShakeTarget target, AnimationCurve amplitudeOverLifetimeCurve)
|
||||
{
|
||||
Init(amplitude, frequency, duration, target);
|
||||
this.amplitudeOverLifetimeCurve = amplitudeOverLifetimeCurve;
|
||||
}
|
||||
|
||||
public Shake(float amplitude, float frequency, float duration, CameraShakeTarget target, CameraShakeAmplitudeCurve amplitudeOverLifetimeCurve)
|
||||
{
|
||||
Init(amplitude, frequency, duration, target);
|
||||
|
||||
switch (amplitudeOverLifetimeCurve)
|
||||
{
|
||||
case CameraShakeAmplitudeCurve.Constant:
|
||||
{
|
||||
this.amplitudeOverLifetimeCurve = AnimationCurve.Linear(0.0f, 1.0f, 1.0f, 1.0f);
|
||||
break;
|
||||
}
|
||||
case CameraShakeAmplitudeCurve.FadeInOut25:
|
||||
{
|
||||
this.amplitudeOverLifetimeCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.25f, 1.0f), new Keyframe(1.0f, 0.0f));
|
||||
break;
|
||||
}
|
||||
case CameraShakeAmplitudeCurve.FadeInOut50:
|
||||
{
|
||||
this.amplitudeOverLifetimeCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.50f, 1.0f), new Keyframe(1.0f, 0.0f));
|
||||
break;
|
||||
}
|
||||
case CameraShakeAmplitudeCurve.FadeInOut75:
|
||||
{
|
||||
this.amplitudeOverLifetimeCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.75f, 1.0f), new Keyframe(1.0f, 0.0f));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new System.Exception("Unknown enum.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAlive()
|
||||
{
|
||||
return timeRemaining > 0.0f;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (timeRemaining < 0.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 frequencyVector = Time.deltaTime * new Vector2(frequency, frequency);
|
||||
|
||||
perlinNoiseX += frequencyVector;
|
||||
perlinNoiseY += frequencyVector;
|
||||
perlinNoiseZ += frequencyVector;
|
||||
|
||||
noise.x = Mathf.PerlinNoise(perlinNoiseX.x, perlinNoiseX.y) - 0.5f;
|
||||
noise.y = Mathf.PerlinNoise(perlinNoiseY.x, perlinNoiseY.y) - 0.5f;
|
||||
noise.z = Mathf.PerlinNoise(perlinNoiseZ.x, perlinNoiseZ.y) - 0.5f;
|
||||
|
||||
float amplitudeOverLifetime = amplitudeOverLifetimeCurve.Evaluate(1.0f - (timeRemaining / duration));
|
||||
|
||||
noise *= amplitude * amplitudeOverLifetime;
|
||||
|
||||
timeRemaining -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public float smoothDampTime = 0.025f;
|
||||
|
||||
Vector3 smoothDampPositionVelocity;
|
||||
|
||||
float smoothDampRotationVelocityX;
|
||||
float smoothDampRotationVelocityY;
|
||||
float smoothDampRotationVelocityZ;
|
||||
|
||||
List<Shake> shakes = new List<Shake>();
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Add(float amplitude, float frequency, float duration, CameraShakeTarget target, AnimationCurve amplitudeOverLifetimeCurve)
|
||||
{
|
||||
shakes.Add(new Shake(amplitude, frequency, duration, target, amplitudeOverLifetimeCurve));
|
||||
}
|
||||
public void Add(float amplitude, float frequency, float duration, CameraShakeTarget target, CameraShakeAmplitudeCurve amplitudeOverLifetimeCurve)
|
||||
{
|
||||
shakes.Add(new Shake(amplitude, frequency, duration, target, amplitudeOverLifetimeCurve));
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
Add(0.25f, 1.0f, 2.0f, CameraShakeTarget.Position, CameraShakeAmplitudeCurve.FadeInOut25);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.G))
|
||||
{
|
||||
Add(15.0f, 1.0f, 2.0f, CameraShakeTarget.Rotation, CameraShakeAmplitudeCurve.FadeInOut25);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.H))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Vector3 positionOffset = Vector3.zero;
|
||||
Vector3 rotationOffset = Vector3.zero;
|
||||
|
||||
for (int i = 0; i < shakes.Count; i++)
|
||||
{
|
||||
shakes[i].Update();
|
||||
|
||||
if (shakes[i].target == CameraShakeTarget.Position)
|
||||
{
|
||||
positionOffset += shakes[i].noise;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotationOffset += shakes[i].noise;
|
||||
}
|
||||
}
|
||||
|
||||
shakes.RemoveAll(x => !x.IsAlive());
|
||||
|
||||
transform.localPosition = Vector3.SmoothDamp(transform.localPosition, positionOffset, ref smoothDampPositionVelocity, smoothDampTime);
|
||||
|
||||
Vector3 eulerAngles = transform.localEulerAngles;
|
||||
|
||||
eulerAngles.x = Mathf.SmoothDampAngle(eulerAngles.x, rotationOffset.x, ref smoothDampRotationVelocityX, smoothDampTime);
|
||||
eulerAngles.y = Mathf.SmoothDampAngle(eulerAngles.y, rotationOffset.y, ref smoothDampRotationVelocityY, smoothDampTime);
|
||||
eulerAngles.z = Mathf.SmoothDampAngle(eulerAngles.z, rotationOffset.z, ref smoothDampRotationVelocityZ, smoothDampTime);
|
||||
|
||||
transform.localEulerAngles = eulerAngles;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c59e681925ba2d41b68052c25820eca
|
||||
timeCreated: 1510113832
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class DestroyAfterTime : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public float time = 2.0f;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
Destroy(gameObject, time);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46df1812d137b7c45a66ae8c8afafb9c
|
||||
timeCreated: 1458196122
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class DestroyOnParticlesDead : ParticleSystems
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// ...
|
||||
|
||||
//onParticleSystemsDeadEvent += onParticleSystemsDead;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void onParticleSystemsDead()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void LateUpdate()
|
||||
{
|
||||
base.LateUpdate();
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92185d158b4c73943ab5df02d7a09647
|
||||
timeCreated: 1427838459
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,94 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class DestroyOnTrailsDestroyed : TrailRenderers
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
// ...
|
||||
|
||||
bool destroy = true;
|
||||
|
||||
for (int i = 0; i < trailRenderers.Length; i++)
|
||||
{
|
||||
if (trailRenderers[i] != null)
|
||||
{
|
||||
destroy = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (destroy)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26270466e2a568b4e98f7d0aa4c82c20
|
||||
timeCreated: 1433783220
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,105 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ParticleSystemTimeRemap : MonoBehaviour
|
||||
{
|
||||
ParticleSystem[] particleSystems;
|
||||
|
||||
float[] startTimes;
|
||||
float[] simulationTimes;
|
||||
|
||||
public float startTime = 2.0f;
|
||||
public float simulationSpeedScale = 1.0f;
|
||||
|
||||
public bool useFixedDeltaTime = true;
|
||||
|
||||
bool gameObjectDeactivated;
|
||||
|
||||
public bool reverseSimulation;
|
||||
|
||||
float elapsedTime;
|
||||
|
||||
public AnimationCurve simulationSpeedOverTime = AnimationCurve.Linear(0.0f, 1.0f, 5.0f, 1.0f);
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
bool particleSystemsNotInitialized = particleSystems == null;
|
||||
|
||||
if (particleSystemsNotInitialized)
|
||||
{
|
||||
particleSystems = GetComponentsInChildren<ParticleSystem>(false);
|
||||
|
||||
startTimes = new float[particleSystems.Length];
|
||||
simulationTimes = new float[particleSystems.Length];
|
||||
}
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
simulationTimes[i] = 0.0f;
|
||||
|
||||
if (particleSystemsNotInitialized || gameObjectDeactivated)
|
||||
{
|
||||
startTimes[i] = startTime;
|
||||
particleSystems[i].Simulate(startTimes[i], false, false, useFixedDeltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
startTimes[i] = particleSystems[i].time;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reverseSimulation)
|
||||
{
|
||||
particleSystems[0].Play(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
particleSystems[0].Play(true);
|
||||
gameObjectDeactivated = !gameObject.activeInHierarchy;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
float simulationSpeed = simulationSpeedScale * simulationSpeedOverTime.Evaluate(elapsedTime);
|
||||
|
||||
if (!reverseSimulation)
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
ParticleSystem.MainModule mainModule = particleSystems[i].main;
|
||||
mainModule.simulationSpeed = simulationSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
particleSystems[0].Stop(true,
|
||||
ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
bool useAutoRandomSeed = particleSystems[i].useAutoRandomSeed;
|
||||
particleSystems[i].useAutoRandomSeed = false;
|
||||
|
||||
particleSystems[i].Play(false);
|
||||
|
||||
float deltaTime = particleSystems[i].main.useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
simulationTimes[i] -= (deltaTime * particleSystems[i].main.simulationSpeed) * simulationSpeedScale;
|
||||
|
||||
float currentSimulationTime = startTimes[i] + simulationTimes[i];
|
||||
particleSystems[i].Simulate(currentSimulationTime, false, false, useFixedDeltaTime);
|
||||
|
||||
particleSystems[i].useAutoRandomSeed = useAutoRandomSeed;
|
||||
|
||||
if (currentSimulationTime < 0.0f)
|
||||
{
|
||||
particleSystems[i].Play(false);
|
||||
particleSystems[i].Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1be24e9eec15bd745a6876ffea5d3945
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,240 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class ParticleSystems : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
public ParticleSystem[] particleSystems { get; set; }
|
||||
|
||||
// Event delegates.
|
||||
|
||||
//public delegate void onParticleSystemsDeadEventHandler();
|
||||
//public event onParticleSystemsDeadEventHandler onParticleSystemsDeadEvent;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
particleSystems = GetComponentsInChildren<ParticleSystem>();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
//if (onParticleSystemsDeadEvent != null)
|
||||
//{
|
||||
// if (!IsAlive())
|
||||
// {
|
||||
// onParticleSystemsDeadEvent();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
//simulate(0.0f, true);
|
||||
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
particleSystems[i].time = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Play()
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
particleSystems[i].Play(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
particleSystems[i].Pause(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
particleSystems[i].Stop(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
particleSystems[i].Clear(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetLoop(bool loop)
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
ParticleSystem.MainModule m = particleSystems[i].main;
|
||||
m.loop = loop;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetPlaybackSpeed(float speed)
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
ParticleSystem.MainModule m = particleSystems[i].main;
|
||||
m.simulationSpeed = speed;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Simulate(float time, bool reset = false)
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
particleSystems[i].Simulate(time, false, reset);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public bool IsAlive()
|
||||
{
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
if (particleSystems[i])
|
||||
{
|
||||
if (particleSystems[i].IsAlive())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public bool IsPlaying(bool checkAll = false)
|
||||
{
|
||||
if (particleSystems.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!checkAll)
|
||||
{
|
||||
return particleSystems[0].isPlaying;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 0; i++)
|
||||
{
|
||||
if (!particleSystems[i].isPlaying)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public int GetParticleCount()
|
||||
{
|
||||
int pcount = 0;
|
||||
|
||||
for (int i = 0; i < particleSystems.Length; i++)
|
||||
{
|
||||
if (particleSystems[i])
|
||||
{
|
||||
pcount += particleSystems[i].particleCount;
|
||||
}
|
||||
}
|
||||
|
||||
return pcount;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a70f47e99623a5043adc11839706250a
|
||||
timeCreated: 1430262861
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,90 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
[System.Serializable]
|
||||
public class PerlinNoise
|
||||
{
|
||||
public void init()
|
||||
{
|
||||
// Don't make the range values too large, else floating point precision will result in jitter.
|
||||
|
||||
offset.x = Random.Range(-32.0f, 32.0f);
|
||||
offset.y = Random.Range(-32.0f, 32.0f);
|
||||
}
|
||||
//public PerlinNoise()
|
||||
//{
|
||||
// offset.x = Random.Range(0.0f, 99999.0f);
|
||||
// offset.y = Random.Range(0.0f, 99999.0f);
|
||||
//}
|
||||
|
||||
public float GetValue(float time)
|
||||
{
|
||||
float noiseTime = time * frequency;
|
||||
return (Mathf.PerlinNoise(noiseTime + offset.x, noiseTime + offset.y) - 0.5f) * amplitude;
|
||||
}
|
||||
|
||||
Vector2 offset;
|
||||
|
||||
public float amplitude = 1.0f;
|
||||
public float frequency = 1.0f;
|
||||
|
||||
public bool unscaledTime;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
[System.Serializable]
|
||||
public class PerlinNoiseXYZ
|
||||
{
|
||||
public void init()
|
||||
{
|
||||
x.init();
|
||||
y.init();
|
||||
z.init();
|
||||
}
|
||||
|
||||
public Vector3 GetXYZ(float time)
|
||||
{
|
||||
float frequencyScaledTime = time * frequencyScale;
|
||||
return new Vector3(x.GetValue(frequencyScaledTime), y.GetValue(frequencyScaledTime), z.GetValue(frequencyScaledTime)) * amplitudeScale;
|
||||
}
|
||||
|
||||
public PerlinNoise x;
|
||||
public PerlinNoise y;
|
||||
public PerlinNoise z;
|
||||
|
||||
public bool unscaledTime;
|
||||
|
||||
public float amplitudeScale = 1.0f;
|
||||
public float frequencyScale = 1.0f;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94a29da1715389f4b99bcd791b0fd993
|
||||
timeCreated: 1474948922
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
|
||||
public class RendererSortingOrder : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public int sortingOrder = 0;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
GetComponent<Renderer>().sortingOrder = sortingOrder;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e32eac08181599748b88d5b13f3e016b
|
||||
timeCreated: 1442712997
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RewindParticleSystem : MonoBehaviour
|
||||
{
|
||||
ParticleSystem[] particleSystems;
|
||||
|
||||
float[] startTimes;
|
||||
float[] simulationTimes;
|
||||
|
||||
public float startTime = 2.0f;
|
||||
public float simulationSpeedScale = 1.0f;
|
||||
|
||||
public bool useFixedDeltaTime = true;
|
||||
|
||||
bool gameObjectDeactivated;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
bool particleSystemsNotInitialized = particleSystems == null;
|
||||
|
||||
if (particleSystemsNotInitialized)
|
||||
{
|
||||
particleSystems = GetComponentsInChildren<ParticleSystem>(false);
|
||||
|
||||
startTimes = new float[particleSystems.Length];
|
||||
simulationTimes = new float[particleSystems.Length];
|
||||
}
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
simulationTimes[i] = 0.0f;
|
||||
|
||||
if (particleSystemsNotInitialized || gameObjectDeactivated)
|
||||
{
|
||||
startTimes[i] = startTime;
|
||||
particleSystems[i].Simulate(startTimes[i], false, false, useFixedDeltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
startTimes[i] = particleSystems[i].time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
particleSystems[0].Play(true);
|
||||
gameObjectDeactivated = !gameObject.activeInHierarchy;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
particleSystems[0].Stop(true,
|
||||
ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
bool useAutoRandomSeed = particleSystems[i].useAutoRandomSeed;
|
||||
particleSystems[i].useAutoRandomSeed = false;
|
||||
|
||||
particleSystems[i].Play(false);
|
||||
|
||||
float deltaTime = particleSystems[i].main.useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
simulationTimes[i] -= (deltaTime * particleSystems[i].main.simulationSpeed) * simulationSpeedScale;
|
||||
|
||||
float currentSimulationTime = startTimes[i] + simulationTimes[i];
|
||||
particleSystems[i].Simulate(currentSimulationTime, false, false, useFixedDeltaTime);
|
||||
|
||||
particleSystems[i].useAutoRandomSeed = useAutoRandomSeed;
|
||||
|
||||
if (currentSimulationTime < 0.0f)
|
||||
{
|
||||
particleSystems[i].Play(false);
|
||||
particleSystems[i].Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fadfd03b4dcf3d4aa5b592f849a7e29
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RewindParticleSystemSimple : MonoBehaviour
|
||||
{
|
||||
ParticleSystem[] particleSystems;
|
||||
|
||||
float simulationTime;
|
||||
public float startTime = 2.0f;
|
||||
|
||||
float internalStartTime;
|
||||
|
||||
bool gameObjectDeactivated;
|
||||
|
||||
public float simulationSpeed = 1.0f;
|
||||
public bool useFixedDeltaTime = true;
|
||||
|
||||
public bool rewind = true;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
bool particleSystemsNotInitialized = particleSystems == null;
|
||||
|
||||
if (particleSystemsNotInitialized)
|
||||
{
|
||||
particleSystems = GetComponentsInChildren<ParticleSystem>(false);
|
||||
}
|
||||
|
||||
simulationTime = 0.0f;
|
||||
|
||||
if (particleSystemsNotInitialized || gameObjectDeactivated)
|
||||
{
|
||||
internalStartTime = startTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note: ParticleSystem.Time will clamp to the duration of the system.
|
||||
// It's important to make sure the duration is long enough to accomodate the entire effect to prevent it from having a limited start offset.
|
||||
|
||||
internalStartTime = particleSystems[0].time;
|
||||
}
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
particleSystems[i].Simulate(internalStartTime, false, false, useFixedDeltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
particleSystems[0].Play(true);
|
||||
gameObjectDeactivated = !gameObject.activeInHierarchy;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
simulationTime -= Time.deltaTime * simulationSpeed;
|
||||
float currentSimulationTime = internalStartTime + simulationTime;
|
||||
|
||||
particleSystems[0].Stop(true,
|
||||
ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
bool useAutoRandomSeed = particleSystems[i].useAutoRandomSeed;
|
||||
particleSystems[i].useAutoRandomSeed = false;
|
||||
|
||||
particleSystems[i].Play(false);
|
||||
particleSystems[i].Simulate(currentSimulationTime, false, false, useFixedDeltaTime);
|
||||
|
||||
particleSystems[i].useAutoRandomSeed = useAutoRandomSeed;
|
||||
|
||||
if (currentSimulationTime < 0.0f)
|
||||
{
|
||||
particleSystems[i].Play();
|
||||
particleSystems[i].Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53c71aeb560b64f4cb01469c58baef4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RewindParticleSystemSuperSimple : MonoBehaviour
|
||||
{
|
||||
ParticleSystem[] particleSystems;
|
||||
|
||||
float[] simulationTimes;
|
||||
|
||||
public float startTime = 2.0f;
|
||||
public float simulationSpeedScale = 1.0f;
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
particleSystems = GetComponentsInChildren<ParticleSystem>(false);
|
||||
simulationTimes = new float[particleSystems.Length];
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (particleSystems == null)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
for (int i = 0; i < simulationTimes.Length; i++)
|
||||
{
|
||||
simulationTimes[i] = 0.0f;
|
||||
}
|
||||
|
||||
particleSystems[0].Simulate(startTime, true, false, true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
particleSystems[0].Stop(true,
|
||||
ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
|
||||
for (int i = particleSystems.Length - 1; i >= 0; i--)
|
||||
{
|
||||
bool useAutoRandomSeed = particleSystems[i].useAutoRandomSeed;
|
||||
particleSystems[i].useAutoRandomSeed = false;
|
||||
|
||||
particleSystems[i].Play(false);
|
||||
|
||||
float deltaTime = particleSystems[i].main.useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
simulationTimes[i] -= (deltaTime * particleSystems[i].main.simulationSpeed) * simulationSpeedScale;
|
||||
|
||||
float currentSimulationTime = startTime + simulationTimes[i];
|
||||
particleSystems[i].Simulate(currentSimulationTime, false, false, true);
|
||||
|
||||
particleSystems[i].useAutoRandomSeed = useAutoRandomSeed;
|
||||
|
||||
if (currentSimulationTime < 0.0f)
|
||||
{
|
||||
particleSystems[i].Play(false);
|
||||
particleSystems[i].Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a4a0b107de842541bf9aa1a1a43b800
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,128 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class Rotator : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
public Vector3 localRotationSpeed;
|
||||
public Vector3 worldRotationSpeed;
|
||||
|
||||
public bool executeInEditMode = false;
|
||||
|
||||
public bool unscaledTime;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
//StartCoroutine(cr());
|
||||
}
|
||||
|
||||
//System.Collections.IEnumerator cr()
|
||||
//{
|
||||
// while (true)
|
||||
// {
|
||||
// transform.Rotate(localRotationSpeed * Time.deltaTime, Space.Self);
|
||||
// yield return new WaitForSeconds(0.1f);
|
||||
// }
|
||||
//}
|
||||
|
||||
// ...
|
||||
|
||||
void OnRenderObject()
|
||||
{
|
||||
if (executeInEditMode)
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
rotate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
rotate();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void rotate()
|
||||
{
|
||||
// Calling Rotate can be expensive.
|
||||
// Doing the if-checks is worth it.
|
||||
|
||||
float deltaTime = !unscaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
|
||||
|
||||
if (localRotationSpeed != Vector3.zero)
|
||||
{
|
||||
transform.Rotate(localRotationSpeed * deltaTime, Space.Self);
|
||||
//transform.rotation = transform.rotation * Quaternion.AngleAxis(localRotationSpeed.y * Time.deltaTime, Vector3.up);
|
||||
}
|
||||
|
||||
if (worldRotationSpeed != Vector3.zero)
|
||||
{
|
||||
transform.Rotate(worldRotationSpeed * deltaTime, Space.World);
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e802dd5d18137f48810e4b6efcdaf59
|
||||
timeCreated: 1458196199
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,97 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class TrailRenderers : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
[HideInInspector]
|
||||
public TrailRenderer[] trailRenderers;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
trailRenderers = GetComponentsInChildren<TrailRenderer>();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void setAutoDestruct(bool value)
|
||||
{
|
||||
for (int i = 0; i < trailRenderers.Length; i++)
|
||||
{
|
||||
trailRenderers[i].autodestruct = value;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
//void Update()
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4de1fbf6fe23564995cc73212ce2a0e
|
||||
timeCreated: 1463643673
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,86 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class TransformNoise : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public PerlinNoiseXYZ positionNoise;
|
||||
public PerlinNoiseXYZ rotationNoise;
|
||||
|
||||
public bool unscaledTime;
|
||||
|
||||
float time;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
positionNoise.init();
|
||||
rotationNoise.init();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
time = !unscaledTime ? Time.time : Time.unscaledTime;
|
||||
|
||||
// I use Time.deltaTime vs. Time.time so that it starts off centered.
|
||||
// LEL, makes no difference.
|
||||
|
||||
//time += !unscaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
|
||||
|
||||
transform.localPosition = positionNoise.GetXYZ(time);
|
||||
transform.localEulerAngles = rotationNoise.GetXYZ(time);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29f509a7bc82bc94e896bfd0257bcec5
|
||||
timeCreated: 1474948492
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5ee12e41d91b5044a201dc5c79af997
|
||||
folderAsset: yes
|
||||
timeCreated: 1469056182
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,539 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class DemoManager : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
public enum ParticleMode
|
||||
{
|
||||
looping,
|
||||
oneshot,
|
||||
}
|
||||
|
||||
public enum Level
|
||||
{
|
||||
none,
|
||||
basic,
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
public Transform cameraRotationTransform;
|
||||
public Transform cameraTranslationTransform;
|
||||
|
||||
public Vector3 cameraLookAtPosition = new Vector3(0.0f, 3.0f, 0.0f);
|
||||
|
||||
public MouseFollow mouse;
|
||||
|
||||
Vector3 targetCameraPosition;
|
||||
Vector3 targetCameraRotation;
|
||||
|
||||
Vector3 cameraPositionStart;
|
||||
Vector3 cameraRotationStart;
|
||||
|
||||
Vector2 input;
|
||||
|
||||
// Because Euler angles wrap around 360, I use
|
||||
// a separate value to store the full rotation.
|
||||
|
||||
Vector3 cameraRotation;
|
||||
|
||||
public float cameraMoveAmount = 2.0f;
|
||||
public float cameraRotateAmount = 2.0f;
|
||||
|
||||
public float cameraMoveSpeed = 12.0f;
|
||||
public float cameraRotationSpeed = 12.0f;
|
||||
|
||||
public Vector2 cameraAngleLimits = new Vector2(-8.0f, 60.0f);
|
||||
|
||||
public GameObject[] levels;
|
||||
public Level currentLevel = Level.basic;
|
||||
|
||||
public ParticleMode particleMode = ParticleMode.looping;
|
||||
|
||||
public bool advancedRendering = true;
|
||||
|
||||
public Toggle loopingParticleModeToggle;
|
||||
public Toggle oneshotParticleModeToggle;
|
||||
|
||||
public Toggle advancedRenderingToggle;
|
||||
|
||||
public Toggle mouseParticlesToggle;
|
||||
|
||||
Toggle[] levelToggles;
|
||||
public ToggleGroup levelTogglesContainer;
|
||||
|
||||
LoopingParticleSystemsManager loopingParticleSystems;
|
||||
OneshotParticleSystemsManager oneshotParticleSystems;
|
||||
|
||||
public GameObject ui;
|
||||
|
||||
public Text particleCountText;
|
||||
public Text currentParticleSystemText;
|
||||
|
||||
public Text particleSpawnInstructionText;
|
||||
|
||||
public Slider timeScaleSlider;
|
||||
public Text timeScaleSliderValueText;
|
||||
|
||||
public Camera mainCamera;
|
||||
|
||||
public MonoBehaviour[] mainCameraPostEffects;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
loopingParticleSystems = FindObjectOfType<LoopingParticleSystemsManager>();
|
||||
oneshotParticleSystems = FindObjectOfType<OneshotParticleSystemsManager>();
|
||||
|
||||
loopingParticleSystems.Init();
|
||||
oneshotParticleSystems.Init();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
// ...
|
||||
|
||||
cameraPositionStart = cameraTranslationTransform.localPosition;
|
||||
cameraRotationStart = cameraRotationTransform.localEulerAngles;
|
||||
|
||||
ResetCameraTransformTargets();
|
||||
|
||||
// ...
|
||||
|
||||
switch (particleMode)
|
||||
{
|
||||
case ParticleMode.looping:
|
||||
{
|
||||
SetToLoopingParticleMode(true);
|
||||
|
||||
loopingParticleModeToggle.isOn = true;
|
||||
oneshotParticleModeToggle.isOn = false;
|
||||
|
||||
break;
|
||||
}
|
||||
case ParticleMode.oneshot:
|
||||
{
|
||||
SetToOneshotParticleMode(true);
|
||||
|
||||
loopingParticleModeToggle.isOn = false;
|
||||
oneshotParticleModeToggle.isOn = true;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
print("Unknown case.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
SetAdvancedRendering(advancedRendering);
|
||||
advancedRenderingToggle.isOn = advancedRendering;
|
||||
|
||||
// ...
|
||||
|
||||
levelToggles =
|
||||
levelTogglesContainer.GetComponentsInChildren<Toggle>(true);
|
||||
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
// Toggle's OnValueChanged handles
|
||||
// level state. No need to SetActive().
|
||||
|
||||
if (i == (int)currentLevel)
|
||||
{
|
||||
levels[i].SetActive(true);
|
||||
levelToggles[i].isOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
levels[i].SetActive(false);
|
||||
levelToggles[i].isOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
timeScaleSlider.onValueChanged.AddListener(OnTimeScaleSliderValueChanged);
|
||||
|
||||
OnTimeScaleSliderValueChanged(timeScaleSlider.value);
|
||||
|
||||
mouseParticlesToggle.isOn = mouse.gameObject.activeSelf;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void OnTimeScaleSliderValueChanged(float value)
|
||||
{
|
||||
Time.timeScale = value;
|
||||
timeScaleSliderValueText.text = value.ToString("0.00");
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetToLoopingParticleMode(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
oneshotParticleSystems.Clear();
|
||||
|
||||
loopingParticleSystems.gameObject.SetActive(true);
|
||||
oneshotParticleSystems.gameObject.SetActive(false);
|
||||
|
||||
particleSpawnInstructionText.gameObject.SetActive(false);
|
||||
|
||||
particleMode = ParticleMode.looping;
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetToOneshotParticleMode(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
loopingParticleSystems.gameObject.SetActive(false);
|
||||
oneshotParticleSystems.gameObject.SetActive(true);
|
||||
|
||||
particleSpawnInstructionText.gameObject.SetActive(true);
|
||||
|
||||
particleMode = ParticleMode.oneshot;
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetLevel(Level level)
|
||||
{
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
if (i == (int)level)
|
||||
{
|
||||
levels[i].SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
levels[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
currentLevel = level;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetLevelFromToggle(Toggle toggle)
|
||||
{
|
||||
if (toggle.isOn)
|
||||
{
|
||||
SetLevel((Level)System.Array.IndexOf(levelToggles, toggle));
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetAdvancedRendering(bool value)
|
||||
{
|
||||
advancedRendering = value;
|
||||
mainCamera.allowHDR = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
//QualitySettings.SetQualityLevel(32, true);
|
||||
//mainCamera.renderingPath = RenderingPath.UsePlayerSettings;
|
||||
|
||||
//mouse.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//QualitySettings.SetQualityLevel(0, true);
|
||||
//mainCamera.renderingPath = RenderingPath.VertexLit;
|
||||
|
||||
//mouse.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < mainCameraPostEffects.Length; i++)
|
||||
{
|
||||
if (mainCameraPostEffects[i])
|
||||
{
|
||||
mainCameraPostEffects[i].enabled = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetMouseParticlesRendering(bool value)
|
||||
{
|
||||
mouse.gameObject.SetActive(value);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public static Vector3 DampVector3(Vector3 from, Vector3 to, float speed, float dt)
|
||||
{
|
||||
return Vector3.Lerp(from, to, 1.0f - Mathf.Exp(-speed * dt));
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
Vector3 cameraPositionSmoothDampVelocity;
|
||||
Vector3 cameraRotationSmoothDampVelocity;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// ...
|
||||
|
||||
input.x = Input.GetAxis("Horizontal");
|
||||
input.y = Input.GetAxis("Vertical");
|
||||
|
||||
// Get targets.
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
targetCameraPosition.z += input.y * cameraMoveAmount;
|
||||
targetCameraPosition.z = Mathf.Clamp(targetCameraPosition.z, -6.3f, -1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
targetCameraRotation.y += input.x * cameraRotateAmount;
|
||||
targetCameraRotation.x += input.y * cameraRotateAmount;
|
||||
|
||||
targetCameraRotation.x = Mathf.Clamp(targetCameraRotation.x, cameraAngleLimits.x, cameraAngleLimits.y);
|
||||
}
|
||||
|
||||
// Camera position.
|
||||
|
||||
cameraTranslationTransform.localPosition = Vector3.SmoothDamp(
|
||||
cameraTranslationTransform.localPosition, targetCameraPosition, ref cameraPositionSmoothDampVelocity, 1.0f / cameraMoveSpeed, Mathf.Infinity, Time.unscaledDeltaTime);
|
||||
|
||||
// Camera container rotation.
|
||||
|
||||
cameraRotation = Vector3.SmoothDamp(
|
||||
cameraRotation, targetCameraRotation, ref cameraRotationSmoothDampVelocity, 1.0f / cameraRotationSpeed, Mathf.Infinity, Time.unscaledDeltaTime);
|
||||
|
||||
cameraRotationTransform.localEulerAngles = cameraRotation;
|
||||
|
||||
// Look at origin.
|
||||
|
||||
cameraTranslationTransform.LookAt(cameraLookAtPosition);
|
||||
|
||||
// Scroll through systems.
|
||||
|
||||
if (Input.GetAxis("Mouse ScrollWheel") < 0)
|
||||
{
|
||||
Next();
|
||||
}
|
||||
else if (Input.GetAxis("Mouse ScrollWheel") > 0)
|
||||
{
|
||||
Previous();
|
||||
}
|
||||
|
||||
// Toggle UI.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.U))
|
||||
{
|
||||
ui.SetActive(!ui.activeSelf);
|
||||
}
|
||||
|
||||
// Switch between one-shot and looping prefabs.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.O))
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
SetToOneshotParticleMode(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetToLoopingParticleMode(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle levels.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.L))
|
||||
{
|
||||
SetLevel((Level)((int)(currentLevel + 1) % System.Enum.GetNames(typeof(Level)).Length));
|
||||
}
|
||||
|
||||
// Random prefab while holding key.
|
||||
|
||||
else if (Input.GetKey(KeyCode.R))
|
||||
{
|
||||
//if (particleMode == ParticleMode.oneshot)
|
||||
//{
|
||||
// oneshotParticleSystems.randomize();
|
||||
// updateCurrentParticleSystemNameText();
|
||||
|
||||
// // If also holding down, auto-spawn at random point.
|
||||
|
||||
// if (Input.GetKey(KeyCode.T))
|
||||
// {
|
||||
// //oneshotParticleSystems.instantiateParticlePrefabRandom();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
// Left-click to spawn once.
|
||||
// Right-click to continously spawn.
|
||||
|
||||
if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
CameraShake cameraShake = FindObjectOfType<CameraShake>();
|
||||
|
||||
cameraShake.Add(0.2f, 5.0f, 0.2f, CameraShakeTarget.Position, CameraShakeAmplitudeCurve.FadeInOut25);
|
||||
cameraShake.Add(4.0f, 5.0f, 0.5f, CameraShakeTarget.Rotation, CameraShakeAmplitudeCurve.FadeInOut25);
|
||||
|
||||
oneshotParticleSystems.InstantiateParticlePrefab(mousePosition, mouse.distanceFromCamera);
|
||||
}
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
oneshotParticleSystems.InstantiateParticlePrefab(mousePosition, mouse.distanceFromCamera);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
ResetCameraTransformTargets();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
// Update particle count display.
|
||||
|
||||
particleCountText.text = "PARTICLE COUNT: ";
|
||||
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
particleCountText.text += loopingParticleSystems.GetParticleCount().ToString();
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
particleCountText.text += oneshotParticleSystems.GetParticleCount().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void ResetCameraTransformTargets()
|
||||
{
|
||||
targetCameraPosition = cameraPositionStart;
|
||||
targetCameraRotation = cameraRotationStart;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void UpdateCurrentParticleSystemNameText()
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
currentParticleSystemText.text = loopingParticleSystems.GetCurrentPrefabName(true);
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
currentParticleSystemText.text = oneshotParticleSystems.GetCurrentPrefabName(true);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Next()
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
loopingParticleSystems.Next();
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
oneshotParticleSystems.Next();
|
||||
}
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
|
||||
public void Previous()
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
loopingParticleSystems.Previous();
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
oneshotParticleSystems.Previous();
|
||||
}
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33d6fc44fae54d642925ba68dc57410f
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class FPSDisplay : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
float timer;
|
||||
public float updateTime = 1.0f;
|
||||
|
||||
int frameCount;
|
||||
float fpsAccum;
|
||||
|
||||
// Display.
|
||||
|
||||
Text fpsText;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
fpsText = GetComponent<Text>();
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
frameCount++;
|
||||
timer += Time.deltaTime;
|
||||
|
||||
fpsAccum += 1.0f / Time.deltaTime;
|
||||
|
||||
if (timer >= updateTime)
|
||||
{
|
||||
timer = 0.0f;
|
||||
|
||||
int fps = Mathf.RoundToInt(fpsAccum / frameCount);
|
||||
|
||||
fpsText.text = "Average FPS: " + fps;
|
||||
|
||||
frameCount = 0;
|
||||
fpsAccum = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f4f59ed613035409cd1a3760587dc0
|
||||
timeCreated: 1442945759
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class FPSTest : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public int targetFPS1 = 60;
|
||||
public int targetFPS2 = 10;
|
||||
|
||||
int previousVSyncCount;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
Application.targetFrameRate = targetFPS2;
|
||||
|
||||
previousVSyncCount = QualitySettings.vSyncCount;
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
else if (Input.GetKeyUp(KeyCode.Space))
|
||||
{
|
||||
Application.targetFrameRate = targetFPS1;
|
||||
QualitySettings.vSyncCount = previousVSyncCount;
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29ec48b8d9f9b294eab9a7f660adcdc3
|
||||
timeCreated: 1458196122
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,123 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class LoopingParticleSystemsManager : ParticleManager
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// ...
|
||||
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public override void Next()
|
||||
{
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(false);
|
||||
|
||||
base.Next();
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(true);
|
||||
}
|
||||
public override void Previous()
|
||||
{
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(false);
|
||||
|
||||
base.Previous();
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public override int GetParticleCount()
|
||||
{
|
||||
// Return particle count from active prefab.
|
||||
|
||||
int particleCount = 0;
|
||||
|
||||
ParticleSystem[] currentPrefab = particlePrefabs[currentParticlePrefabIndex];
|
||||
|
||||
for (int i = 0; i < currentPrefab.Length; i++)
|
||||
{
|
||||
particleCount += currentPrefab[i].particleCount;
|
||||
}
|
||||
|
||||
return particleCount;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c510a03d7e25f949891cc966a3b4cda
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class MouseFollow : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public float speed = 8.0f;
|
||||
public float distanceFromCamera = 5.0f;
|
||||
|
||||
public bool ignoreTimeScale;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
mousePosition.z = distanceFromCamera;
|
||||
|
||||
Vector3 mouseScreenToWorld = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
|
||||
float deltaTime = !ignoreTimeScale ? Time.deltaTime : Time.unscaledDeltaTime;
|
||||
Vector3 position = Vector3.Lerp(transform.position, mouseScreenToWorld, 1.0f - Mathf.Exp(-speed * deltaTime));
|
||||
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d060625387cf804ea2e5920cc7a829e
|
||||
timeCreated: 1459508605
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class MouseRotateCamera : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public float maxRotation = 5.0f;
|
||||
public float speed = 2.0f;
|
||||
|
||||
public bool unscaledTime;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector2 mousePosition = Input.mousePosition;
|
||||
|
||||
float screenHalfWidth = Screen.width / 2.0f;
|
||||
float screenHalfHeight = Screen.height / 2.0f;
|
||||
|
||||
float mouseNormalizedPositionHalfX = (mousePosition.x - screenHalfWidth) / screenHalfWidth;
|
||||
float mouseNormalizedPositionHalfY = (mousePosition.y - screenHalfHeight) / screenHalfHeight;
|
||||
|
||||
Vector3 localEulerAngles = transform.localEulerAngles;
|
||||
|
||||
localEulerAngles.y = mouseNormalizedPositionHalfX * -maxRotation;
|
||||
localEulerAngles.x = mouseNormalizedPositionHalfY * maxRotation;
|
||||
|
||||
float deltaTime = (!unscaledTime ? Time.deltaTime : Time.unscaledDeltaTime) * speed;
|
||||
|
||||
localEulerAngles.x = Mathf.LerpAngle(transform.localEulerAngles.x, localEulerAngles.x, deltaTime);
|
||||
localEulerAngles.y = Mathf.LerpAngle(transform.localEulerAngles.y, localEulerAngles.y, deltaTime);
|
||||
|
||||
transform.localEulerAngles = localEulerAngles;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a459c580f4cd938498d2d9aa94d3a03b
|
||||
timeCreated: 1475038359
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,214 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class OneshotParticleSystemsManager : ParticleManager
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
public LayerMask mouseRaycastLayerMask = ~0;
|
||||
List<ParticleSystem[]> spawnedPrefabs;
|
||||
|
||||
// Don't allow spawning if true.
|
||||
// Used for button clicks vs. empty-space clicks.
|
||||
|
||||
public bool disableSpawn { get; set; }
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// ...
|
||||
|
||||
disableSpawn = false;
|
||||
spawnedPrefabs = new List<ParticleSystem[]>();
|
||||
}
|
||||
|
||||
// Get rid of spawned systems when re-activated.
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
//clear();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (spawnedPrefabs != null)
|
||||
{
|
||||
for (int i = 0; i < spawnedPrefabs.Count; i++)
|
||||
{
|
||||
if (spawnedPrefabs[i][0])
|
||||
{
|
||||
Destroy(spawnedPrefabs[i][0].gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
spawnedPrefabs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void InstantiateParticlePrefab(Vector2 mousePosition, float maxDistance)
|
||||
{
|
||||
if (spawnedPrefabs != null)
|
||||
{
|
||||
if (!disableSpawn)
|
||||
{
|
||||
Vector3 position = mousePosition;
|
||||
|
||||
position.z = maxDistance;
|
||||
Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(position);
|
||||
|
||||
Vector3 directionToWorldMouse = worldMousePosition - Camera.main.transform.position;
|
||||
|
||||
RaycastHit rayHit;
|
||||
|
||||
// Start the raycast a little bit ahead of the camera because the camera starts right where a cube's edge is
|
||||
// and that causes the raycast to hit... spawning a prefab right at the camera position. It's fixed by moving the camera,
|
||||
// or I can just add this forward to prevent it from happening at all.
|
||||
|
||||
Physics.Raycast(Camera.main.transform.position + Camera.main.transform.forward * 0.01f, directionToWorldMouse, out rayHit, maxDistance);
|
||||
|
||||
Vector3 spawnPosition;
|
||||
|
||||
if (rayHit.collider)
|
||||
{
|
||||
spawnPosition = rayHit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnPosition = worldMousePosition;
|
||||
}
|
||||
|
||||
ParticleSystem[] prefab = particlePrefabs[currentParticlePrefabIndex];
|
||||
ParticleSystem newParticlePrefab = Instantiate(prefab[0], spawnPosition, prefab[0].transform.rotation);
|
||||
|
||||
newParticlePrefab.gameObject.SetActive(true);
|
||||
|
||||
// Parent to spawner.
|
||||
|
||||
newParticlePrefab.transform.parent = transform;
|
||||
|
||||
spawnedPrefabs.Add(newParticlePrefab.GetComponentsInChildren<ParticleSystem>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
//public void instantiateParticlePrefabRandom()
|
||||
//{
|
||||
// if (!disableSpawn)
|
||||
// {
|
||||
// instantiateParticlePrefab(new Vector3(
|
||||
// Random.Range(0.0f, Screen.width), Random.Range(0.0f, Screen.height), 0.0f));
|
||||
// }
|
||||
//}
|
||||
|
||||
// ...
|
||||
|
||||
public void Randomize()
|
||||
{
|
||||
currentParticlePrefabIndex = Random.Range(0, particlePrefabs.Count);
|
||||
}
|
||||
|
||||
// Get particle count from all spawned.
|
||||
|
||||
public override int GetParticleCount()
|
||||
{
|
||||
int particleCount = 0;
|
||||
|
||||
if (spawnedPrefabs != null)
|
||||
{
|
||||
for (int i = 0; i < spawnedPrefabs.Count; i++)
|
||||
{
|
||||
if (spawnedPrefabs[i][0])
|
||||
{
|
||||
for (int j = 0; j < spawnedPrefabs[i].Length; j++)
|
||||
{
|
||||
particleCount += spawnedPrefabs[i][j].particleCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnedPrefabs.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return particleCount;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b8e608e3ccbfe341885f855c07d6184
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,206 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class ParticleManager : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
protected List<ParticleSystem[]> particlePrefabs;
|
||||
|
||||
public int currentParticlePrefabIndex;
|
||||
|
||||
// Take only the part of the prefab name string after these many underscores.
|
||||
|
||||
public int prefabNameUnderscoreCountCutoff = 4;
|
||||
|
||||
// Since I may have prefabs as children I was using to set values.
|
||||
// But I don't want to disable/enable them each time I want to run
|
||||
// the build or change values. This will auto-disable all at start.
|
||||
|
||||
public bool disableChildrenAtStart = true;
|
||||
|
||||
// Already initialized?
|
||||
|
||||
bool initialized = false;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public void Init()
|
||||
{
|
||||
// Default.
|
||||
|
||||
//currentParticlePrefab = 0;
|
||||
|
||||
// Get all particles.
|
||||
|
||||
particlePrefabs = new List<ParticleSystem[]>();
|
||||
|
||||
int numChildren = transform.childCount;
|
||||
|
||||
for (int i = 0; i < numChildren; i++)
|
||||
{
|
||||
particlePrefabs.Add(transform.GetChild(i).GetComponentsInChildren<ParticleSystem>());
|
||||
}
|
||||
|
||||
// Disable all particle prefab object children.
|
||||
|
||||
if (disableChildrenAtStart)
|
||||
{
|
||||
for (int i = 0; i < particlePrefabs.Count; i++)
|
||||
{
|
||||
particlePrefabs[i][0].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public virtual void Next()
|
||||
{
|
||||
currentParticlePrefabIndex++;
|
||||
|
||||
if (currentParticlePrefabIndex > particlePrefabs.Count - 1)
|
||||
{
|
||||
currentParticlePrefabIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Previous()
|
||||
{
|
||||
currentParticlePrefabIndex--;
|
||||
|
||||
if (currentParticlePrefabIndex < 0)
|
||||
{
|
||||
currentParticlePrefabIndex = particlePrefabs.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public string GetCurrentPrefabName(bool shorten = false)
|
||||
{
|
||||
// Save object name for clarity.
|
||||
|
||||
string particleSystemName = particlePrefabs[currentParticlePrefabIndex][0].name;
|
||||
|
||||
// Only take name from after the last underscore to the end.
|
||||
|
||||
if (shorten)
|
||||
{
|
||||
int lastIndexOfUnderscore = 0;
|
||||
|
||||
for (int i = 0; i < prefabNameUnderscoreCountCutoff; i++)
|
||||
{
|
||||
// -1 if not found, 0 to n otherwise. +1 to move position forward.
|
||||
|
||||
lastIndexOfUnderscore = particleSystemName.IndexOf("_", lastIndexOfUnderscore) + 1;
|
||||
|
||||
// Not found. -1 + 1 == 0.
|
||||
|
||||
if (lastIndexOfUnderscore == 0)
|
||||
{
|
||||
// "Error"... sort of.
|
||||
|
||||
print("Iteration of underscore not found.");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
particleSystemName = particleSystemName.Substring(lastIndexOfUnderscore, particleSystemName.Length - lastIndexOfUnderscore);
|
||||
}
|
||||
|
||||
// Return display text.
|
||||
|
||||
return "PARTICLE SYSTEM: #" + (currentParticlePrefabIndex + 1).ToString("00") +
|
||||
" / " + particlePrefabs.Count.ToString("00") + " (" + particleSystemName + ")";
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public virtual int GetParticleCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4151f3ce4d5482d4786330fc08faeda1
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user