testing
This commit is contained in:
reedgamingstudio
2014-12-16 00:23:12 -06:00
parent c0c0755cc6
commit 5b8ebb7a35
1697 changed files with 1115979 additions and 0 deletions
@@ -0,0 +1,461 @@
using UnityEngine;
using System.Collections;
/*
Detonator - A parametric explosion system for Unity
Created by Ben Throop in August 2009 for the Unity Summer of Code
Simplest use case:
1) Use a prefab
OR
1) Attach a Detonator to a GameObject, either through code or the Unity UI
2) Either set the Detonator's ExplodeOnStart = true or call Explode() yourself when the time is right
3) View explosion :)
Medium Complexity Use Case:
1) Attach a Detonator as above
2) Change parameters, add your own materials, etc
3) Explode()
4) View Explosion
Super Fun Use Case:
1) Attach a Detonator as above
2) Drag one or more DetonatorComponents to that same GameObject
3) Tweak those parameters
4) Explode()
5) View Explosion
Better documentation is included as a PDF with this package, or is available online. Check the Unity site for a link
or visit my site, listed below.
Ben Throop
http://variancetheory.com
@benimaru
*/
/*
All pieces of Detonator inherit from this.
*/
public abstract class DetonatorComponent : MonoBehaviour
{
public bool on = true;
public bool detonatorControlled = true;
[HideInInspector]
public float startSize = 1f;
public float size = 1f;
public float explodeDelayMin = 0f;
public float explodeDelayMax = 0f;
[HideInInspector]
public float startDuration = 2f;
public float duration = 2f;
[HideInInspector]
public float timeScale = 1f;
[HideInInspector]
public float startDetail = 1f;
public float detail = 1f;
[HideInInspector]
public Color startColor = Color.white;
public Color color = Color.white;
[HideInInspector]
public Vector3 startLocalPosition = Vector3.zero;
public Vector3 localPosition = Vector3.zero;
[HideInInspector]
public Vector3 startForce = Vector3.zero;
public Vector3 force = Vector3.zero;
[HideInInspector]
public Vector3 startVelocity = Vector3.zero;
public Vector3 velocity = Vector3.zero;
public abstract void Explode();
//The main Detonator calls this instead of using Awake() or Start() on subcomponents
//which ensures it happens when we want.
public abstract void Init();
public float detailThreshold;
/*
This exists because Detonator makes relative changes
to set values once the game is running, so we need to store their beginning
values somewhere to calculate against. An improved design could probably
avoid this.
*/
public void SetStartValues()
{
startSize = size;
startForce = force;
startVelocity = velocity;
startDuration = duration;
startDetail = detail;
startColor = color;
startLocalPosition = localPosition;
}
//implement functions to find the Detonator on this GO and get materials if they are defined
public Detonator MyDetonator()
{
Detonator _myDetonator = GetComponent("Detonator") as Detonator;
return _myDetonator;
}
}
[AddComponentMenu("Detonator/Detonator")]
public class Detonator : MonoBehaviour {
private static float _baseSize = 30f;
private static Color _baseColor = new Color(1f, .423f, 0f, .5f);
private static float _baseDuration = 3f;
/*
_baseSize reflects the size that DetonatorComponents at size 1 match. Yes, this is really big (30m)
size below is the default Detonator size, which is more reasonable for typical useage.
It wasn't my intention for them to be different, and I may change that, but for now, that's how it is.
*/
public float size = 10f;
public Color color = Detonator._baseColor;
public bool explodeOnStart = true;
public float duration = Detonator._baseDuration;
public float detail = 1f;
public float upwardsBias = 0f;
public float destroyTime = 7f; //sorry this is not auto calculated... yet.
public bool useWorldSpace = true;
public Vector3 direction = Vector3.zero;
public Material fireballAMaterial;
public Material fireballBMaterial;
public Material smokeAMaterial;
public Material smokeBMaterial;
public Material shockwaveMaterial;
public Material sparksMaterial;
public Material glowMaterial;
public Material heatwaveMaterial;
private Component[] components;
private DetonatorFireball _fireball;
private DetonatorSparks _sparks;
private DetonatorShockwave _shockwave;
private DetonatorSmoke _smoke;
private DetonatorGlow _glow;
private DetonatorLight _light;
private DetonatorForce _force;
private DetonatorHeatwave _heatwave;
public bool autoCreateFireball = true;
public bool autoCreateSparks = true;
public bool autoCreateShockwave = true;
public bool autoCreateSmoke = true;
public bool autoCreateGlow = true;
public bool autoCreateLight = true;
public bool autoCreateForce = true;
public bool autoCreateHeatwave = false;
void Awake()
{
FillDefaultMaterials();
components = this.GetComponents(typeof(DetonatorComponent));
foreach (DetonatorComponent dc in components)
{
if (dc is DetonatorFireball)
{
_fireball = dc as DetonatorFireball;
}
if (dc is DetonatorSparks)
{
_sparks = dc as DetonatorSparks;
}
if (dc is DetonatorShockwave)
{
_shockwave = dc as DetonatorShockwave;
}
if (dc is DetonatorSmoke)
{
_smoke = dc as DetonatorSmoke;
}
if (dc is DetonatorGlow)
{
_glow = dc as DetonatorGlow;
}
if (dc is DetonatorLight)
{
_light = dc as DetonatorLight;
}
if (dc is DetonatorForce)
{
_force = dc as DetonatorForce;
}
if (dc is DetonatorHeatwave)
{
_heatwave = dc as DetonatorHeatwave;
}
}
if (!_fireball && autoCreateFireball)
{
_fireball = gameObject.AddComponent("DetonatorFireball") as DetonatorFireball;
_fireball.Reset();
}
if (!_smoke && autoCreateSmoke)
{
_smoke = gameObject.AddComponent("DetonatorSmoke") as DetonatorSmoke;
_smoke.Reset();
}
if (!_sparks && autoCreateSparks)
{
_sparks = gameObject.AddComponent("DetonatorSparks") as DetonatorSparks;
_sparks.Reset();
}
if (!_shockwave && autoCreateShockwave)
{
_shockwave = gameObject.AddComponent("DetonatorShockwave") as DetonatorShockwave;
_shockwave.Reset();
}
if (!_glow && autoCreateGlow)
{
_glow = gameObject.AddComponent("DetonatorGlow") as DetonatorGlow;
_glow.Reset();
}
if (!_light && autoCreateLight)
{
_light = gameObject.AddComponent("DetonatorLight") as DetonatorLight;
_light.Reset();
}
if (!_force && autoCreateForce)
{
_force = gameObject.AddComponent("DetonatorForce") as DetonatorForce;
_force.Reset();
}
if (!_heatwave && autoCreateHeatwave && SystemInfo.supportsImageEffects)
{
_heatwave = gameObject.AddComponent("DetonatorHeatwave") as DetonatorHeatwave;
_heatwave.Reset();
}
components = this.GetComponents(typeof(DetonatorComponent));
}
void FillDefaultMaterials()
{
if (!fireballAMaterial) fireballAMaterial = DefaultFireballAMaterial();
if (!fireballBMaterial) fireballBMaterial = DefaultFireballBMaterial();
if (!smokeAMaterial) smokeAMaterial = DefaultSmokeAMaterial();
if (!smokeBMaterial) smokeBMaterial = DefaultSmokeBMaterial();
if (!shockwaveMaterial) shockwaveMaterial = DefaultShockwaveMaterial();
if (!sparksMaterial) sparksMaterial = DefaultSparksMaterial();
if (!glowMaterial) glowMaterial = DefaultGlowMaterial();
if (!heatwaveMaterial) heatwaveMaterial = DefaultHeatwaveMaterial();
}
void Start()
{
if (explodeOnStart)
{
UpdateComponents();
this.Explode();
}
}
private float _lastExplosionTime = 1000f;
void Update ()
{
if (destroyTime > 0f)
{
if (_lastExplosionTime + destroyTime <= Time.time)
{
Destroy(gameObject);
}
}
}
private bool _firstComponentUpdate = true;
void UpdateComponents()
{
if (_firstComponentUpdate)
{
foreach (DetonatorComponent component in components)
{
component.Init();
component.SetStartValues();
}
_firstComponentUpdate = false;
}
if (!_firstComponentUpdate)
{
foreach (DetonatorComponent component in components)
{
if (component.detonatorControlled)
{
component.size = component.startSize * (size / _baseSize);
component.timeScale = (duration / _baseDuration);
component.detail = component.startDetail * detail;
component.force = (component.startForce * (size /_baseSize)) + (direction * (size /_baseSize));
component.velocity = (component.startVelocity * (size /_baseSize)) + (direction * (size /_baseSize));
//take the alpha of detonator color and consider it a weight - 1=use all detonator, 0=use all components
component.color = Color.Lerp(component.startColor, color, color.a);
}
}
}
}
private Component[] _subDetonators;
public void Explode()
{
_lastExplosionTime = Time.time;
foreach (DetonatorComponent component in components)
{
UpdateComponents();
component.Explode();
}
}
public void Reset()
{
size = 10f; //this is hardcoded because _baseSize up top is not really the default as much as what we match to
color = _baseColor;
duration = _baseDuration;
FillDefaultMaterials();
}
//Default Materials
//The statics are so that even if there are multiple Detonators in the world, they
//don't each create their own default materials. Theoretically this will reduce draw calls, but I haven't really
//tested that.
public static Material defaultFireballAMaterial;
public static Material defaultFireballBMaterial;
public static Material defaultSmokeAMaterial;
public static Material defaultSmokeBMaterial;
public static Material defaultShockwaveMaterial;
public static Material defaultSparksMaterial;
public static Material defaultGlowMaterial;
public static Material defaultHeatwaveMaterial;
public static Material DefaultFireballAMaterial()
{
if (defaultFireballAMaterial != null) return defaultFireballAMaterial;
defaultFireballAMaterial = new Material(Shader.Find("Particles/Additive"));
defaultFireballAMaterial.name = "FireballA-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Fireball") as Texture2D;
defaultFireballAMaterial.SetColor("_TintColor", Color.white);
defaultFireballAMaterial.mainTexture = tex;
defaultFireballAMaterial.mainTextureScale = new Vector2(0.5f, 1f);
return defaultFireballAMaterial;
}
public static Material DefaultFireballBMaterial()
{
if (defaultFireballBMaterial != null) return defaultFireballBMaterial;
defaultFireballBMaterial = new Material(Shader.Find("Particles/Additive"));
defaultFireballBMaterial.name = "FireballB-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Fireball") as Texture2D;
defaultFireballBMaterial.SetColor("_TintColor", Color.white);
defaultFireballBMaterial.mainTexture = tex;
defaultFireballBMaterial.mainTextureScale = new Vector2(0.5f, 1f);
defaultFireballBMaterial.mainTextureOffset = new Vector2(0.5f, 0f);
return defaultFireballBMaterial;
}
public static Material DefaultSmokeAMaterial()
{
if (defaultSmokeAMaterial != null) return defaultSmokeAMaterial;
defaultSmokeAMaterial = new Material(Shader.Find("Particles/Alpha Blended"));
defaultSmokeAMaterial.name = "SmokeA-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Smoke") as Texture2D;
defaultSmokeAMaterial.SetColor("_TintColor", Color.white);
defaultSmokeAMaterial.mainTexture = tex;
defaultSmokeAMaterial.mainTextureScale = new Vector2(0.5f, 1f);
return defaultSmokeAMaterial;
}
public static Material DefaultSmokeBMaterial()
{
if (defaultSmokeBMaterial != null) return defaultSmokeBMaterial;
defaultSmokeBMaterial = new Material(Shader.Find("Particles/Alpha Blended"));
defaultSmokeBMaterial.name = "SmokeB-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Smoke") as Texture2D;
defaultSmokeBMaterial.SetColor("_TintColor", Color.white);
defaultSmokeBMaterial.mainTexture = tex;
defaultSmokeBMaterial.mainTextureScale = new Vector2(0.5f, 1f);
defaultSmokeBMaterial.mainTextureOffset = new Vector2(0.5f, 0f);
return defaultSmokeBMaterial;
}
public static Material DefaultSparksMaterial()
{
if (defaultSparksMaterial != null) return defaultSparksMaterial;
defaultSparksMaterial = new Material(Shader.Find("Particles/Additive"));
defaultSparksMaterial.name = "Sparks-Default";
Texture2D tex = Resources.Load("Detonator/Textures/GlowDot") as Texture2D;
defaultSparksMaterial.SetColor("_TintColor", Color.white);
defaultSparksMaterial.mainTexture = tex;
return defaultSparksMaterial;
}
public static Material DefaultShockwaveMaterial()
{
if (defaultShockwaveMaterial != null) return defaultShockwaveMaterial;
defaultShockwaveMaterial = new Material(Shader.Find("Particles/Additive"));
defaultShockwaveMaterial.name = "Shockwave-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Shockwave") as Texture2D;
defaultShockwaveMaterial.SetColor("_TintColor", new Color(0.1f,0.1f,0.1f,1f));
defaultShockwaveMaterial.mainTexture = tex;
return defaultShockwaveMaterial;
}
public static Material DefaultGlowMaterial()
{
if (defaultGlowMaterial != null) return defaultGlowMaterial;
defaultGlowMaterial = new Material(Shader.Find("Particles/Additive"));
defaultGlowMaterial.name = "Glow-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Glow") as Texture2D;
defaultGlowMaterial.SetColor("_TintColor", Color.white);
defaultGlowMaterial.mainTexture = tex;
return defaultGlowMaterial;
}
public static Material DefaultHeatwaveMaterial()
{
//Unity Pro Only
if (SystemInfo.supportsImageEffects)
{
if (defaultHeatwaveMaterial != null) return defaultHeatwaveMaterial;
defaultHeatwaveMaterial = new Material(Shader.Find("HeatDistort"));
defaultHeatwaveMaterial.name = "Heatwave-Default";
Texture2D tex = Resources.Load("Detonator/Textures/Heatwave") as Texture2D;
defaultHeatwaveMaterial.SetTexture("_BumpMap", tex);
return defaultHeatwaveMaterial;
}
else
{
return null;
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9b4007f1233a9b74fa9be42583fafba6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,238 @@
using UnityEngine;
using System.Collections;
/*
DetonatorBurstEmitter is an interface for DetonatorComponents to use to create particles
- Handles common tasks for Detonator... almost every DetonatorComponent uses this for particles
- Builds the gameobject with emitter, animator, renderer
- Everything incoming is automatically scaled by size, timeScale, color
- Enable oneShot functionality
You probably don't want to use this directly... though you certainly can.
*/
public class DetonatorBurstEmitter : DetonatorComponent
{
private ParticleEmitter _particleEmitter;
private ParticleRenderer _particleRenderer;
private ParticleAnimator _particleAnimator;
private float _baseDamping = 0.1300004f;
private float _baseSize = 1f;
private Color _baseColor = Color.white;
public float damping = 1f;
public float startRadius = 1f;
public float maxScreenSize = 2f;
public bool explodeOnAwake = false;
public bool oneShot = true;
public float sizeVariation = 0f;
public float particleSize = 1f;
public float count = 1;
public float sizeGrow = 20f;
public bool exponentialGrowth = true;
public float durationVariation = 0f;
public bool useWorldSpace = true;
public float upwardsBias = 0f;
public float angularVelocity = 20f;
public bool randomRotation = true;
public ParticleRenderMode renderMode;
//TODO make this based on some var
/*
_sparksRenderer.particleRenderMode = ParticleRenderMode.Stretch;
_sparksRenderer.lengthScale = 0f;
_sparksRenderer.velocityScale = 0.7f;
*/
public bool useExplicitColorAnimation = false;
public Color[] colorAnimation = new Color[5];
private bool _delayedExplosionStarted = false;
private float _explodeDelay;
public Material material;
//unused
override public void Init()
{
print ("UNUSED");
}
public void Awake()
{
_particleEmitter = (gameObject.AddComponent("EllipsoidParticleEmitter")) as ParticleEmitter;
_particleRenderer = (gameObject.AddComponent("ParticleRenderer")) as ParticleRenderer;
_particleAnimator = (gameObject.AddComponent("ParticleAnimator")) as ParticleAnimator;
_particleEmitter.hideFlags = HideFlags.HideAndDontSave;
_particleRenderer.hideFlags = HideFlags.HideAndDontSave;
_particleAnimator.hideFlags = HideFlags.HideAndDontSave;
_particleAnimator.damping = _baseDamping;
_particleEmitter.emit = false;
_particleRenderer.maxParticleSize = maxScreenSize;
_particleRenderer.material = material;
_particleRenderer.material.color = Color.white; //workaround for this not being settable elsewhere
_particleAnimator.sizeGrow = sizeGrow;
if (explodeOnAwake)
{
Explode();
}
}
private float _emitTime;
private float speed = 3.0f;
private float initFraction = 0.1f;
static float epsilon = 0.01f;
void Update ()
{
//do exponential particle scaling once emitted
if (exponentialGrowth)
{
float elapsed = Time.time - _emitTime;
float oldSize = SizeFunction(elapsed - epsilon);
float newSize = SizeFunction(elapsed);
float growth = ((newSize / oldSize) - 1) / epsilon;
_particleAnimator.sizeGrow = growth;
}
else
{
_particleAnimator.sizeGrow = sizeGrow;
}
//delayed explosion
if (_delayedExplosionStarted)
{
_explodeDelay = (_explodeDelay - Time.deltaTime);
if (_explodeDelay <= 0f)
{
Explode();
}
}
}
private float SizeFunction (float elapsedTime)
{
float divided = 1 - (1 / (1 + elapsedTime * speed));
return initFraction + (1 - initFraction) * divided;
}
public void Reset()
{
size = _baseSize;
color = _baseColor;
damping = _baseDamping;
}
private float _tmpParticleSize; //calculated particle size... particleSize * randomized size (by sizeVariation)
private Vector3 _tmpPos; //calculated position... randomized inside sphere of incoming radius * size
private Vector3 _tmpDir; //calculated velocity - randomized inside sphere - incoming velocity * size
private Vector3 _thisPos; //handle on this gameobject's position, set inside
private float _tmpDuration; //calculated duration... incoming duration * incoming timescale
private float _tmpCount; //calculated count... incoming count * incoming detail
private float _scaledDuration; //calculated duration... duration * timescale
private float _scaledDurationVariation;
private float _scaledStartRadius;
private float _scaledColor; //color with alpha adjusted according to detail and duration
private float _randomizedRotation;
private float _tmpAngularVelocity; //random angular velocity from -angularVelocity to +angularVelocity, if randomRotation is true;
override public void Explode()
{
if (on)
{
_particleEmitter.useWorldSpace = useWorldSpace;
_scaledDuration = timeScale * duration;
_scaledDurationVariation = timeScale * durationVariation;
_scaledStartRadius = size * startRadius;
_particleRenderer.particleRenderMode = renderMode;
if (!_delayedExplosionStarted)
{
_explodeDelay = explodeDelayMin + (Random.value * (explodeDelayMax - explodeDelayMin));
}
if (_explodeDelay <= 0)
{
Color[] modifiedColors = _particleAnimator.colorAnimation;
if (useExplicitColorAnimation)
{
modifiedColors[0] = colorAnimation[0];
modifiedColors[1] = colorAnimation[1];
modifiedColors[2] = colorAnimation[2];
modifiedColors[3] = colorAnimation[3];
modifiedColors[4] = colorAnimation[4];
}
else //auto fade
{
modifiedColors[0] = new Color(color.r, color.g, color.b, (color.a * .7f));
modifiedColors[1] = new Color(color.r, color.g, color.b, (color.a * 1f));
modifiedColors[2] = new Color(color.r, color.g, color.b, (color.a * .5f));
modifiedColors[3] = new Color(color.r, color.g, color.b, (color.a * .3f));
modifiedColors[4] = new Color(color.r, color.g, color.b, (color.a * 0f));
}
_particleAnimator.colorAnimation = modifiedColors;
_particleRenderer.material = material;
_particleAnimator.force = force;
_tmpCount = count * detail;
if (_tmpCount < 1) _tmpCount = 1;
if (_particleEmitter.useWorldSpace == true)
{
_thisPos = this.gameObject.transform.position;
}
else
{
_thisPos = new Vector3(0,0,0);
}
for (int i = 1; i <= _tmpCount; i++)
{
_tmpPos = Vector3.Scale(Random.insideUnitSphere, new Vector3(_scaledStartRadius, _scaledStartRadius, _scaledStartRadius));
_tmpPos = _thisPos + _tmpPos;
_tmpDir = Vector3.Scale(Random.insideUnitSphere, new Vector3(velocity.x, velocity.y, velocity.z));
_tmpDir.y = (_tmpDir.y + (2 * (Mathf.Abs(_tmpDir.y) * upwardsBias)));
if (randomRotation == true)
{
_randomizedRotation = Random.Range(-1f,1f);
_tmpAngularVelocity = Random.Range(-1f,1f) * angularVelocity;
}
else
{
_randomizedRotation = 0f;
_tmpAngularVelocity = angularVelocity;
}
_tmpDir = Vector3.Scale(_tmpDir, new Vector3(size, size, size));
_tmpParticleSize = size * (particleSize + (Random.value * sizeVariation));
_tmpDuration = _scaledDuration + (Random.value * _scaledDurationVariation);
_particleEmitter.Emit(_tmpPos, _tmpDir, _tmpParticleSize, _tmpDuration, color, _randomizedRotation, _tmpAngularVelocity);
}
_emitTime = Time.time;
_delayedExplosionStarted = false;
_explodeDelay = 0f;
}
else
{
//tell update to start reducing the start delay and call explode again when it's zero
_delayedExplosionStarted = true;
}
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b739e859c3f20354bbd47c572d0b5aa5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,100 @@
using UnityEngine;
using System.Collections;
// This one isn't ready for prime time and is not in the menu. Feel free to modify or complete. :)
[RequireComponent (typeof (Detonator))]
public class DetonatorCloudRing : DetonatorComponent
{
private float _baseSize = 1f;
private float _baseDuration = 5f;
private Vector3 _baseVelocity = new Vector3(155f, 5f, 155f);
private Color _baseColor = Color.white;
private Vector3 _baseForce = new Vector3(0.162f, 2.56f, 0f);
private GameObject _cloudRing;
private DetonatorBurstEmitter _cloudRingEmitter;
public Material cloudRingMaterial;
override public void Init()
{
//make sure there are materials at all
FillMaterials(false);
BuildCloudRing();
}
//if materials are empty fill them with defaults
public void FillMaterials(bool wipe)
{
if (!cloudRingMaterial || wipe)
{
cloudRingMaterial = MyDetonator().smokeBMaterial;
}
}
//Build these to look correct at the stock Detonator size of 10m... then let the size parameter
//cascade through to the emitters and let them do the scaling work... keep these absolute.
public void BuildCloudRing()
{
_cloudRing = new GameObject("CloudRing");
_cloudRingEmitter = (DetonatorBurstEmitter)_cloudRing.AddComponent("DetonatorBurstEmitter");
_cloudRing.transform.parent = this.transform;
_cloudRing.transform.localPosition = localPosition;
_cloudRingEmitter.material = cloudRingMaterial;
_cloudRingEmitter.useExplicitColorAnimation = true;
}
public void UpdateCloudRing()
{
_cloudRing.transform.localPosition = Vector3.Scale(localPosition,(new Vector3(size, size, size)));
_cloudRingEmitter.color = color;
_cloudRingEmitter.duration = duration;
_cloudRingEmitter.durationVariation = duration/4f;
_cloudRingEmitter.count = (int)(detail * 50f);
_cloudRingEmitter.particleSize = 10f;
_cloudRingEmitter.sizeVariation = 2f;
_cloudRingEmitter.velocity = velocity;
_cloudRingEmitter.startRadius = 3f;
_cloudRingEmitter.size = size;
_cloudRingEmitter.force = force;
_cloudRingEmitter.explodeDelayMin = explodeDelayMin;
_cloudRingEmitter.explodeDelayMax = explodeDelayMax;
//make the starting colors more intense, towards white
Color color1 = Color.Lerp(color, (new Color(.2f, .2f, .2f, .6f)), 0.5f);
Color color2 = new Color(.2f, .2f, .2f, .5f);
Color color3 = new Color(.2f, .2f, .2f, .3f);
Color color4 = new Color(.2f, .2f, .2f, 0f);
_cloudRingEmitter.colorAnimation[0] = color1;
_cloudRingEmitter.colorAnimation[1] = color2;
_cloudRingEmitter.colorAnimation[2] = color2;
_cloudRingEmitter.colorAnimation[3] = color3;
_cloudRingEmitter.colorAnimation[4] = color4;
}
public void Reset()
{
FillMaterials(true);
on = true;
size = _baseSize;
duration = _baseDuration;
explodeDelayMin = 0f;
explodeDelayMax = 0f;
color = _baseColor;
velocity = _baseVelocity;
force = _baseForce;
}
override public void Explode()
{
if (on)
{
UpdateCloudRing();
_cloudRingEmitter.Explode();
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 31a304ef63fe9024d9a09477e1262f65
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: edba693a4a231da4e9434948a5dec7ee
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,109 @@
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Force")]
public class DetonatorForce : DetonatorComponent {
private float _baseRadius = 50.0f;
private float _basePower = 4000.0f;
private float _scaledRange;
private float _scaledIntensity;
private bool _delayedExplosionStarted = false;
private float _explodeDelay;
public float radius;
public float power;
public GameObject fireObject;
public float fireObjectLife;
private Collider[] _colliders;
private GameObject _tempFireObject;
override public void Init()
{
//unused
}
void Update()
{
if (_delayedExplosionStarted)
{
_explodeDelay = (_explodeDelay - Time.deltaTime);
if (_explodeDelay <= 0f)
{
Explode();
}
}
}
private Vector3 _explosionPosition;
override public void Explode()
{
if (!on) return;
if (detailThreshold > detail) return;
if (!_delayedExplosionStarted)
{
_explodeDelay = explodeDelayMin + (Random.value * (explodeDelayMax - explodeDelayMin));
}
if (_explodeDelay <= 0) //if the delayTime is zero
{
//tweak the position such that the explosion center is related to the explosion's direction
_explosionPosition = transform.position; //- Vector3.Normalize(MyDetonator().direction);
_colliders = Physics.OverlapSphere (_explosionPosition, radius);
foreach (Collider hit in _colliders)
{
if (!hit)
{
continue;
}
if (hit.rigidbody)
{
//align the force along the object's rotation
//this is wrong - need to attenuate the velocity according to distance from the explosion center
//offsetting the explosion force position by the negative of the explosion's direction may help
hit.rigidbody.AddExplosionForce((power * size), _explosionPosition, (radius * size), (4f * MyDetonator().upwardsBias * size));
SendMessage("OnDetonatorForceHit", null, SendMessageOptions.DontRequireReceiver);
//and light them on fire for Rune
if (fireObject)
{
//check to see if the object already is on fire. being on fire twice is silly
if (hit.transform.Find(fireObject.name+"(Clone)"))
{
return;
}
_tempFireObject = (Instantiate(fireObject, this.transform.position, this.transform.rotation)) as GameObject;
_tempFireObject.transform.parent = hit.transform;
_tempFireObject.transform.localPosition = new Vector3(0f,0f,0f);
if (_tempFireObject.particleEmitter)
{
_tempFireObject.particleEmitter.emit = true;
Destroy(_tempFireObject,fireObjectLife);
}
}
}
}
_delayedExplosionStarted = false;
_explodeDelay = 0f;
}
else
{
//tell update to start reducing the start delay and call explode again when it's zero
_delayedExplosionStarted = true;
}
}
public void Reset()
{
radius = _baseRadius;
power = _basePower;
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a99a52afbdc68cd4fbc1c477cf05bbba
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,116 @@
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Glow")]
public class DetonatorGlow : DetonatorComponent
{
private float _baseSize = 1f;
private float _baseDuration = 3f;
private Vector3 _baseVelocity = new Vector3(0f, 0f, 0f);
private Color _baseColor = Color.black;
private float _scaledDuration;
private GameObject _glow;
private DetonatorBurstEmitter _glowEmitter;
public Material glowMaterial;
override public void Init()
{
//make sure there are materials at all
FillMaterials(false);
BuildGlow();
}
//if materials are empty fill them with defaults
public void FillMaterials(bool wipe)
{
if (!glowMaterial || wipe)
{
glowMaterial = MyDetonator().glowMaterial;
}
}
//Build these to look correct at the stock Detonator size of 10m... then let the size parameter
//cascade through to the emitters and let them do the scaling work... keep these absolute.
public void BuildGlow()
{
_glow = new GameObject("Glow");
_glowEmitter = (DetonatorBurstEmitter)_glow.AddComponent("DetonatorBurstEmitter");
_glow.transform.parent = this.transform;
_glow.transform.localPosition = localPosition;
_glowEmitter.material = glowMaterial;
_glowEmitter.exponentialGrowth = false;
_glowEmitter.useExplicitColorAnimation = true;
_glowEmitter.useWorldSpace = MyDetonator().useWorldSpace;
}
public void UpdateGlow()
{
//this needs
_glow.transform.localPosition = Vector3.Scale(localPosition,(new Vector3(size, size, size)));
_glowEmitter.color = color;
_glowEmitter.duration = duration;
_glowEmitter.timeScale = timeScale;
_glowEmitter.count = 1;
_glowEmitter.particleSize = 65f;
_glowEmitter.sizeVariation = 0f;
_glowEmitter.velocity = new Vector3(0f, 0f, 0f);
_glowEmitter.startRadius = 0f;
_glowEmitter.sizeGrow = 0;
_glowEmitter.size = size;
_glowEmitter.explodeDelayMin = explodeDelayMin;
_glowEmitter.explodeDelayMax = explodeDelayMax;
Color stage1 = Color.Lerp(color, (new Color(.5f, .1f, .1f, 1f)),.5f);
stage1.a = .9f;
Color stage2 = Color.Lerp(color, (new Color(.6f, .3f, .3f, 1f)),.5f);
stage2.a = .8f;
Color stage3 = Color.Lerp(color, (new Color(.7f, .3f, .3f, 1f)),.5f);
stage3.a = .5f;
Color stage4 = Color.Lerp(color, (new Color(.4f, .3f, .4f, 1f)),.5f);
stage4.a = .2f;
Color stage5 = new Color(.1f, .1f, .4f, 0f);
_glowEmitter.colorAnimation[0] = stage1;
_glowEmitter.colorAnimation[1] = stage2;
_glowEmitter.colorAnimation[2] = stage3;
_glowEmitter.colorAnimation[3] = stage4;
_glowEmitter.colorAnimation[4] = stage5;
}
void Update ()
{
//others might be able to do this too... only update themselves before exploding?
}
public void Reset()
{
FillMaterials(true);
on = true;
size = _baseSize;
duration = _baseDuration;
explodeDelayMin = 0f;
explodeDelayMax = 0f;
color = _baseColor;
velocity = _baseVelocity;
}
override public void Explode()
{
if (detailThreshold > detail) return;
if (on)
{
UpdateGlow();
_glowEmitter.Explode();
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 18ccfc2137d7c684f966ad07b4dc0d4d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,2 @@
using UnityEngine; using System.Collections; [RequireComponent (typeof (Detonator))] [AddComponentMenu("Detonator/Heatwave (Pro Only)")] public class DetonatorHeatwave : DetonatorComponent { private GameObject _heatwave; private float s; private float _startSize; private float _maxSize; private float _baseDuration = .25f; private bool _delayedExplosionStarted = false; private float _explodeDelay; public float zOffset = .5f; public float distortion = 64; private float _elapsedTime = 0f; private float _normalizedTime; public Material heatwaveMaterial; private Material _material; //tmp material we alter at runtime; override public void Init() { //we don't want to do anything until we explode } void Update () { if (_delayedExplosionStarted) { _explodeDelay = (_explodeDelay - Time.deltaTime); if (_explodeDelay <= 0f) { Explode(); } } //_heatwave doesn't get defined unless SystemInfo.supportsImageEffects is true, checked in Explode() if (_heatwave) { // billboard it so it always faces the camera - can't use regular lookat because the built in Unity plane is lame _heatwave.transform.rotation = Quaternion.FromToRotation(Vector3.up, Camera.main.transform.position - _heatwave.transform.position); _heatwave.transform.localPosition = localPosition + (Vector3.forward * zOffset); _elapsedTime = _elapsedTime + Time.deltaTime; _normalizedTime = _elapsedTime/duration; //thought about this, and really, the wave would move linearly, fading in amplitude. s = Mathf.Lerp(_startSize,_maxSize,_normalizedTime); _heatwave.renderer.material.SetFloat("_BumpAmt", ((1-_normalizedTime) * distortion)); _heatwave.gameObject.transform.localScale = new Vector3(s,s,s); if (_elapsedTime > duration) Destroy(_heatwave.gameObject); } } override public void Explode() {
//try to early out if we can't draw this (not sure if this also gets us out of Unity Indie) if (SystemInfo.supportsImageEffects) { if ((detailThreshold > detail) || !on) return; if (!_delayedExplosionStarted) { _explodeDelay = explodeDelayMin + (Random.value * (explodeDelayMax - explodeDelayMin)); } if (_explodeDelay <= 0) { //incoming size is based on 1, so we multiply here _startSize = 0f; _maxSize = size * 10f; _material = new Material(Shader.Find("HeatDistort")); _heatwave = GameObject.CreatePrimitive(PrimitiveType.Plane); Destroy(_heatwave.GetComponent(typeof(MeshCollider))); if (!heatwaveMaterial) heatwaveMaterial = MyDetonator().heatwaveMaterial; _material.CopyPropertiesFromMaterial(heatwaveMaterial); _heatwave.renderer.material = _material; _heatwave.transform.parent = this.transform; _delayedExplosionStarted = false; _explodeDelay = 0f; } else { _delayedExplosionStarted = true; } } } public void Reset() { duration = _baseDuration; } }
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e0a30e21f576d054695cb3804fce8a9d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,63 @@
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Light")]
public class DetonatorLight : DetonatorComponent {
private float _baseIntensity = 1f;
private Color _baseColor = Color.white;
private float _scaledDuration = 0f;
private float _explodeTime = -1000f;
private GameObject _light;
private Light _lightComponent;
public float intensity;
override public void Init()
{
_light = new GameObject ("Light");
_light.transform.parent = this.transform;
_light.transform.localPosition = localPosition;
_lightComponent = (Light)_light.AddComponent ("Light");
_lightComponent.type = LightType.Point;
_lightComponent.enabled = false;
}
private float _reduceAmount = 0f;
void Update ()
{
if ((_explodeTime + _scaledDuration > Time.time) && _lightComponent.intensity > 0f)
{
_reduceAmount = intensity * (Time.deltaTime/_scaledDuration);
_lightComponent.intensity -= _reduceAmount;
}
else
{
if (_lightComponent)
{
_lightComponent.enabled = false;
}
}
}
override public void Explode()
{
if (detailThreshold > detail) return;
_lightComponent.color = color;
_lightComponent.range = size * 50f;
_scaledDuration = (duration * timeScale);
_lightComponent.enabled = true;
_lightComponent.intensity = intensity;
_explodeTime = Time.time;
}
public void Reset()
{
color = _baseColor;
intensity = _baseIntensity;
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8966b5c4c1545d741a2a90a4a01e7f83
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,89 @@
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Shockwave")]
public class DetonatorShockwave : DetonatorComponent
{
private float _baseSize = 1f;
private float _baseDuration = .25f;
private Vector3 _baseVelocity = new Vector3(0f, 0f, 0f);
private Color _baseColor = Color.white;
private GameObject _shockwave;
private DetonatorBurstEmitter _shockwaveEmitter;
public Material shockwaveMaterial;
public ParticleRenderMode renderMode;
override public void Init()
{
//make sure there are materials at all
FillMaterials(false);
BuildShockwave();
}
//if materials are empty fill them with defaults
public void FillMaterials(bool wipe)
{
if (!shockwaveMaterial || wipe)
{
shockwaveMaterial = MyDetonator().shockwaveMaterial;
}
}
//Build these to look correct at the stock Detonator size of 10m... then let the size parameter
//cascade through to the emitters and let them do the scaling work... keep these absolute.
public void BuildShockwave()
{
_shockwave = new GameObject("Shockwave");
_shockwaveEmitter = (DetonatorBurstEmitter)_shockwave.AddComponent("DetonatorBurstEmitter");
_shockwave.transform.parent = this.transform;
_shockwave.transform.localRotation = Quaternion.identity;
_shockwave.transform.localPosition = localPosition;
_shockwaveEmitter.material = shockwaveMaterial;
_shockwaveEmitter.exponentialGrowth = false;
_shockwaveEmitter.useWorldSpace = MyDetonator().useWorldSpace;
}
public void UpdateShockwave()
{
_shockwave.transform.localPosition = Vector3.Scale(localPosition,(new Vector3(size, size, size)));
_shockwaveEmitter.color = color;
_shockwaveEmitter.duration = duration;
_shockwaveEmitter.durationVariation = duration * 0.1f;
_shockwaveEmitter.count = 1;
_shockwaveEmitter.detail = 1;
_shockwaveEmitter.particleSize = 25f;
_shockwaveEmitter.sizeVariation = 0f;
_shockwaveEmitter.velocity = new Vector3(0f, 0f, 0f);
_shockwaveEmitter.startRadius = 0f;
_shockwaveEmitter.sizeGrow = 202f;
_shockwaveEmitter.size = size;
_shockwaveEmitter.explodeDelayMin = explodeDelayMin;
_shockwaveEmitter.explodeDelayMax = explodeDelayMax;
_shockwaveEmitter.renderMode = renderMode;
}
public void Reset()
{
FillMaterials(true);
on = true;
size = _baseSize;
duration = _baseDuration;
explodeDelayMin = 0f;
explodeDelayMax = 0f;
color = _baseColor;
velocity = _baseVelocity;
}
override public void Explode()
{
if (on)
{
UpdateShockwave();
_shockwaveEmitter.Explode();
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 745312967000e3c449713c45a6a516f2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 034345331e52f2b4e873add1691384e3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,76 @@
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Sound")]
public class DetonatorSound : DetonatorComponent {
public AudioClip[] nearSounds;
public AudioClip[] farSounds;
public float distanceThreshold = 50f; //threshold in m between playing nearSound and farSound
public float minVolume = .4f;
public float maxVolume = 1f;
public float rolloffFactor = 0.5f;
private AudioSource _soundComponent;
private bool _delayedExplosionStarted = false;
private float _explodeDelay;
override public void Init()
{
_soundComponent = (AudioSource)gameObject.AddComponent ("AudioSource");
}
void Update()
{
_soundComponent.pitch = Time.timeScale;
if (_delayedExplosionStarted)
{
_explodeDelay = (_explodeDelay - Time.deltaTime);
if (_explodeDelay <= 0f)
{
Explode();
}
}
}
private int _idx;
override public void Explode()
{
if (detailThreshold > detail) return;
if (!_delayedExplosionStarted)
{
_explodeDelay = explodeDelayMin + (Random.value * (explodeDelayMax - explodeDelayMin));
}
if (_explodeDelay <= 0)
{
// _soundComponent.minVolume = minVolume;
// _soundComponent.maxVolume = maxVolume;
// _soundComponent.rolloffFactor = rolloffFactor;
if (Vector3.Distance(Camera.main.transform.position, this.transform.position) < distanceThreshold)
{
_idx = (int)(Random.value * nearSounds.Length);
_soundComponent.PlayOneShot(nearSounds[_idx]);
}
else
{
_idx = (int)(Random.value * farSounds.Length);
_soundComponent.PlayOneShot(farSounds[_idx]);
}
_delayedExplosionStarted = false;
_explodeDelay = 0f;
}
else
{
_delayedExplosionStarted = true;
}
}
public void Reset()
{
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b2b0ca7171ed55c4eaaf9aba39d05e87
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,103 @@
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Sparks")]
public class DetonatorSparks : DetonatorComponent
{
private float _baseSize = 1f;
private float _baseDuration = 4f;
private Vector3 _baseVelocity = new Vector3(155f, 155f, 155f);
private Color _baseColor = Color.white;
// private float _baseDamping = 0.185f;
private Vector3 _baseForce = Physics.gravity;
private float _scaledDuration;
private GameObject _sparks;
private DetonatorBurstEmitter _sparksEmitter;
public Material sparksMaterial;
override public void Init()
{
//make sure there are materials at all
FillMaterials(false);
BuildSparks();
}
//if materials are empty fill them with defaults
public void FillMaterials(bool wipe)
{
if (!sparksMaterial || wipe)
{
sparksMaterial = MyDetonator().sparksMaterial;
}
}
//Build these to look correct at the stock Detonator size of 10m... then let the size parameter
//cascade through to the emitters and let them do the scaling work... keep these absolute.
public void BuildSparks()
{
_sparks = new GameObject("Sparks");
_sparksEmitter = (DetonatorBurstEmitter)_sparks.AddComponent("DetonatorBurstEmitter");
_sparks.transform.parent = this.transform;
_sparks.transform.localPosition = localPosition;
_sparks.transform.localRotation = Quaternion.identity;
_sparksEmitter.material = sparksMaterial;
_sparksEmitter.force = Physics.gravity / 3; //don't fall fast - these are sparks
_sparksEmitter.useExplicitColorAnimation = false;
_sparksEmitter.useWorldSpace = MyDetonator().useWorldSpace;
_sparksEmitter.upwardsBias = MyDetonator().upwardsBias;
}
public void UpdateSparks()
{
_scaledDuration = (duration * timeScale);
_sparksEmitter.color = color;
_sparksEmitter.duration = _scaledDuration/4;
_sparksEmitter.durationVariation = _scaledDuration;
_sparksEmitter.count = (int)(detail * 50f);
_sparksEmitter.particleSize = .5f;
_sparksEmitter.sizeVariation = .25f;
//get wider as upwardsBias goes up - counterintuitive, but right in this case?
if (_sparksEmitter.upwardsBias > 0f)
{
_sparksEmitter.velocity = new Vector3(
(velocity.x / Mathf.Log(_sparksEmitter.upwardsBias)),
(velocity.y * Mathf.Log(_sparksEmitter.upwardsBias)),
(velocity.z / Mathf.Log(_sparksEmitter.upwardsBias)));
}
else
{
_sparksEmitter.velocity = this.velocity;
}
_sparksEmitter.startRadius = 0f;
_sparksEmitter.size = size;
_sparksEmitter.explodeDelayMin = explodeDelayMin;
_sparksEmitter.explodeDelayMax = explodeDelayMax;
}
public void Reset()
{
FillMaterials(true);
on = true;
size = _baseSize;
duration = _baseDuration;
explodeDelayMin = 0f;
explodeDelayMax = 0f;
color = _baseColor;
velocity = _baseVelocity;
force = _baseForce;
}
override public void Explode()
{
if (on)
{
UpdateSparks();
_sparksEmitter.Explode();
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1154a16e40ae84e42b591529ea211201
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,84 @@
using UnityEngine;
using System.Collections;
/*
Todo - set duration and color properly (actually, i'm not sure this is possible)
calculate count based on detail
inherit velocity
*/
[RequireComponent (typeof (Detonator))]
[AddComponentMenu("Detonator/Object Spray")]
public class DetonatorSpray : DetonatorComponent {
public GameObject sprayObject;
public int count = 10;
public float startingRadius = 0f;
public float minScale = 1f;
public float maxScale = 1f;
private bool _delayedExplosionStarted = false;
private float _explodeDelay;
override public void Init()
{
//unused
}
void Update()
{
if (_delayedExplosionStarted)
{
_explodeDelay = (_explodeDelay - Time.deltaTime);
if (_explodeDelay <= 0f)
{
Explode();
}
}
}
private Vector3 _explosionPosition;
private float _tmpScale;
override public void Explode()
{
if (!_delayedExplosionStarted)
{
_explodeDelay = explodeDelayMin + (Random.value * (explodeDelayMax - explodeDelayMin));
}
if (_explodeDelay <= 0) //if the delayTime is zero
{
int detailCount = (int)(detail * count);
for (int i=0;i<detailCount;i++)
{
Vector3 randVec = Random.onUnitSphere * (startingRadius * size);
Vector3 velocityVec = new Vector3((velocity.x*size),(velocity.y*size),(velocity.z*size));
GameObject chunk = Instantiate(sprayObject, (this.transform.position + randVec), this.transform.rotation) as GameObject;
chunk.transform.parent = this.transform;
//calculate scale for this piece
_tmpScale = (minScale + (Random.value * (maxScale - minScale)));
_tmpScale = _tmpScale * size;
chunk.transform.localScale = new Vector3(_tmpScale,_tmpScale,_tmpScale);
chunk.rigidbody.velocity = Vector3.Scale(randVec.normalized,velocityVec);
Destroy(chunk, (duration * timeScale));
_delayedExplosionStarted = false;
_explodeDelay = 0f;
}
}
else
{
//tell update to start reducing the start delay and call explode again when it's zero
_delayedExplosionStarted = true;
}
}
public void Reset()
{
velocity = new Vector3(15f,15f,15f);
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f7134859da924a14b9de2f13721402b1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: