Asset Dump
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bac83fd4d889274f98e91e8d584f9a1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+666
@@ -0,0 +1,666 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAP_ParticleSystemController{
|
||||
|
||||
[System.Serializable]
|
||||
public class ParticleSystemOriginalSettings
|
||||
{
|
||||
public SerializableMinMaxGradient _startColor;
|
||||
public SerializableMinMaxGradient _colorOverLifetimeC;
|
||||
public SerializableMinMaxCurve _startSize;
|
||||
public SerializableMinMaxCurve _startSizeX;
|
||||
public SerializableMinMaxCurve _startSizeY;
|
||||
public SerializableMinMaxCurve _startSizeZ;
|
||||
public SerializableMinMaxCurve _startSpeed;
|
||||
public SerializableMinMaxCurve _startDelay;
|
||||
public SerializableMinMaxCurve _startLifetime;
|
||||
public SerializableMinMaxCurve _velocityOverLifetimeX;
|
||||
public SerializableMinMaxCurve _velocityOverLifetimeY;
|
||||
public SerializableMinMaxCurve _velocityOverLifetimeZ;
|
||||
public SerializableVector3 _localPosition;
|
||||
public SerializableGradient _trailGradient;
|
||||
public float _duration;
|
||||
public float _shapeRadius;
|
||||
public float _trailWidthMultiplier;
|
||||
public float _trailTime;
|
||||
public bool _active;
|
||||
public bool _loop;
|
||||
public bool _prewarm;
|
||||
}
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class ParticleSystemController : MonoBehaviour {
|
||||
|
||||
public float size = 1;
|
||||
public float speed = 1;
|
||||
public float duration = 1;
|
||||
public bool loop;
|
||||
public bool prewarm;
|
||||
public bool lights;
|
||||
public bool trails;
|
||||
public bool changeColor;
|
||||
public Color newMaxColor = new Color (0,0,0,1);
|
||||
public Color newMinColor = new Color (0,0,0,1);
|
||||
public List<GameObject> ParticleSystems = new List<GameObject>();
|
||||
public List<bool> ActiveParticleSystems = new List<bool>();
|
||||
|
||||
private List<ParticleSystemOriginalSettings> psOriginalSettingsList = new List<ParticleSystemOriginalSettings> ();
|
||||
|
||||
public void UpdateParticleSystem(){
|
||||
//Enables or Disbales Particle Systems you choose in inspector
|
||||
for(int i = 0; i< ParticleSystems.Count; i++){
|
||||
if (ActiveParticleSystems.Count == ParticleSystems.Count) {
|
||||
if (ActiveParticleSystems [i] == true)
|
||||
ParticleSystems [i].SetActive (true);
|
||||
else
|
||||
ParticleSystems [i].SetActive (false);
|
||||
} else {
|
||||
Debug.Log ("Make sure the ActiveParticleSystems list has the same amount as the ParticleSystems list.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ParticleSystems.Count > 0) {
|
||||
for (int i = 0; i < ParticleSystems.Count; i ++) {
|
||||
var ps = ParticleSystems [i].GetComponent<ParticleSystem> ();
|
||||
if (ps != null) {
|
||||
var main = ps.main;
|
||||
var shape = ps.shape;
|
||||
var psLights = ps.lights;
|
||||
var psTrails = ps.trails;
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
var colorOverLifetimeC = colorOverLifetime.color;
|
||||
var startColor = main.startColor;
|
||||
var startSize = main.startSize;
|
||||
var startSizeX = main.startSizeX;
|
||||
var startSizeY = main.startSizeY;
|
||||
var startSizeZ = main.startSizeZ;
|
||||
var startSpeed = main.startSpeed;
|
||||
var startDelay = main.startDelay;
|
||||
var startLifetime = main.startLifetime;
|
||||
var velocityOverLifetime = ps.velocityOverLifetime;
|
||||
var velocityOverLifetimeX = velocityOverLifetime.x;
|
||||
var velocityOverLifetimeY = velocityOverLifetime.y;
|
||||
var velocityOverLifetimeZ = velocityOverLifetime.z;
|
||||
var localPos = ParticleSystems [i].transform.localPosition;
|
||||
|
||||
//KEEP ORIGINAL VALUES
|
||||
if (!SaveParticleSystemScript.CheckExistingFile (gameObject)) {
|
||||
ParticleSystemOriginalSettings psOriginalSettings = new ParticleSystemOriginalSettings () {
|
||||
_startColor = new SerializableMinMaxGradient (startColor),
|
||||
_colorOverLifetimeC = new SerializableMinMaxGradient (colorOverLifetimeC),
|
||||
_startSize = new SerializableMinMaxCurve (startSize),
|
||||
_startSizeX = new SerializableMinMaxCurve (startSizeX),
|
||||
_startSizeY = new SerializableMinMaxCurve (startSizeY),
|
||||
_startSizeZ = new SerializableMinMaxCurve (startSizeZ),
|
||||
_startSpeed = new SerializableMinMaxCurve (startSpeed),
|
||||
_startDelay = new SerializableMinMaxCurve (startDelay),
|
||||
_startLifetime = new SerializableMinMaxCurve (startLifetime),
|
||||
_velocityOverLifetimeX = new SerializableMinMaxCurve (velocityOverLifetimeX),
|
||||
_velocityOverLifetimeY = new SerializableMinMaxCurve (velocityOverLifetimeY),
|
||||
_velocityOverLifetimeZ = new SerializableMinMaxCurve (velocityOverLifetimeZ),
|
||||
_localPosition = new SerializableVector3 (ParticleSystems [i].transform.localPosition),
|
||||
_duration = main.duration,
|
||||
_shapeRadius = shape.radius,
|
||||
_active = ps.gameObject.activeSelf,
|
||||
_loop = main.loop,
|
||||
_prewarm = main.prewarm
|
||||
};
|
||||
psOriginalSettingsList.Add (psOriginalSettings);
|
||||
} else {
|
||||
List<ParticleSystemOriginalSettings> listOriginalSettings = new List<ParticleSystemOriginalSettings> ();
|
||||
listOriginalSettings = SaveParticleSystemScript.LoadVFX (gameObject);
|
||||
|
||||
startColor = listOriginalSettings [i]._startColor.GetMinMaxGradient();
|
||||
colorOverLifetimeC = listOriginalSettings [i]._colorOverLifetimeC.GetMinMaxGradient();
|
||||
startSize = listOriginalSettings [i]._startSize.GetMinMaxCurve();
|
||||
startSizeX = listOriginalSettings [i]._startSizeX.GetMinMaxCurve();
|
||||
startSizeY = listOriginalSettings [i]._startSizeY.GetMinMaxCurve();
|
||||
startSizeZ = listOriginalSettings [i]._startSizeZ.GetMinMaxCurve();
|
||||
startSpeed = listOriginalSettings [i]._startSpeed.GetMinMaxCurve();
|
||||
startDelay = listOriginalSettings [i]._startDelay.GetMinMaxCurve();
|
||||
startLifetime = listOriginalSettings [i]._startLifetime.GetMinMaxCurve();
|
||||
velocityOverLifetimeX = listOriginalSettings [i]._velocityOverLifetimeX.GetMinMaxCurve ();
|
||||
velocityOverLifetimeY = listOriginalSettings [i]._velocityOverLifetimeY.GetMinMaxCurve ();
|
||||
velocityOverLifetimeZ = listOriginalSettings [i]._velocityOverLifetimeZ.GetMinMaxCurve ();
|
||||
localPos = listOriginalSettings [i]._localPosition.GetVector3();
|
||||
main.duration = listOriginalSettings [i]._duration;
|
||||
shape.radius = listOriginalSettings [i]._shapeRadius;
|
||||
ps.gameObject.SetActive (listOriginalSettings [i]._active);
|
||||
loop = listOriginalSettings [i]._loop;
|
||||
prewarm = listOriginalSettings [i]._prewarm;
|
||||
}
|
||||
|
||||
//LOOP
|
||||
if(!main.loop)
|
||||
main.loop = loop;
|
||||
|
||||
//PREWARM
|
||||
main.prewarm = prewarm;
|
||||
|
||||
//LIGHTS
|
||||
if (!lights && psLights.enabled)
|
||||
psLights.enabled = false;
|
||||
|
||||
//TRAILS
|
||||
if (!trails && psTrails.enabled)
|
||||
psTrails.enabled = false;
|
||||
|
||||
//POSITION
|
||||
if (i > 0) {
|
||||
if (localPos.x != 0 || localPos.y != 0 || localPos.z != 0) {
|
||||
localPos.x *= size;
|
||||
localPos.y *= size;
|
||||
localPos.z *= size;
|
||||
ParticleSystems [i].transform.localPosition = localPos;
|
||||
}
|
||||
}
|
||||
|
||||
//DURATION
|
||||
if(duration != 1){
|
||||
main.duration *= duration;
|
||||
}
|
||||
|
||||
//SIZE
|
||||
if (main.startSize3D) {
|
||||
if (startSize.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSizeX.constantMax *= size;
|
||||
startSizeX.constantMin *= size;
|
||||
|
||||
startSizeY.constantMax *= size;
|
||||
startSizeY.constantMin *= size;
|
||||
|
||||
startSizeZ.constantMax *= size;
|
||||
startSizeZ.constantMin *= size;
|
||||
} else {
|
||||
startSizeX.constant *= size;
|
||||
startSizeY.constant *= size;
|
||||
startSizeZ.constant *= size;
|
||||
}
|
||||
main.startSizeX = startSizeX;
|
||||
main.startSizeY = startSizeY;
|
||||
main.startSizeZ = startSizeZ;
|
||||
} else {
|
||||
if (startSize.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSize.constantMax *= size;
|
||||
startSize.constantMin *= size;
|
||||
} else {
|
||||
startSize.constant *= size;
|
||||
}
|
||||
main.startSize = startSize;
|
||||
}
|
||||
|
||||
//START_SPEED (affected by size)
|
||||
if (startSpeed.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSpeed.constantMax *= size;
|
||||
startSpeed.constantMin *= size;
|
||||
main.startSpeed = startSpeed;
|
||||
} else {
|
||||
startSpeed.constant *= size;
|
||||
main.startSpeed = startSpeed;
|
||||
}
|
||||
|
||||
//START_SPEED (affected by speed)
|
||||
if (startSpeed.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSpeed.constantMax *= speed;
|
||||
startSpeed.constantMin *= speed;
|
||||
main.startSpeed = startSpeed;
|
||||
} else {
|
||||
startSpeed.constant *= speed;
|
||||
main.startSpeed = startSpeed;
|
||||
}
|
||||
|
||||
//LIFETIME
|
||||
if (main.startLifetime.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startLifetime.constantMax *= 1 / speed;
|
||||
startLifetime.constantMin *= 1 / speed;
|
||||
main.startLifetime = startLifetime;
|
||||
} else {
|
||||
startLifetime.constant *= 1 / speed;
|
||||
main.startLifetime = startLifetime;
|
||||
}
|
||||
|
||||
//START_DELAY
|
||||
if (startDelay.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startDelay.constantMax *= 1 / speed;
|
||||
startDelay.constantMin *= 1 / speed;
|
||||
main.startDelay = startDelay;
|
||||
} else {
|
||||
startDelay.constant *= 1 / speed;
|
||||
main.startDelay = startDelay;
|
||||
}
|
||||
|
||||
//VELOCITY OVERLIFETIME
|
||||
if(velocityOverLifetime.enabled){
|
||||
float amount = 1;
|
||||
if(size != 1)
|
||||
amount = size;
|
||||
if(speed != 1)
|
||||
amount = speed;
|
||||
if(size != 1 && speed != 1)
|
||||
amount = (size + speed)/2;
|
||||
|
||||
if (velocityOverLifetime.x.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
velocityOverLifetimeX.constantMax *= amount;
|
||||
velocityOverLifetimeX.constantMin *= amount;
|
||||
|
||||
velocityOverLifetimeY.constantMax *= amount;
|
||||
velocityOverLifetimeY.constantMin *= amount;
|
||||
|
||||
velocityOverLifetimeZ.constantMax *= amount;
|
||||
velocityOverLifetimeZ.constantMin *= amount;
|
||||
} else {
|
||||
velocityOverLifetimeX.constant *= amount;
|
||||
velocityOverLifetimeY.constant *= amount;
|
||||
velocityOverLifetimeZ.constant *= amount;
|
||||
}
|
||||
velocityOverLifetime.x = velocityOverLifetimeX;
|
||||
velocityOverLifetime.y = velocityOverLifetimeY;
|
||||
velocityOverLifetime.z = velocityOverLifetimeZ;
|
||||
}
|
||||
|
||||
//RADIUS
|
||||
if (shape.enabled) {
|
||||
shape.radius *= size;
|
||||
}
|
||||
|
||||
//COLOR
|
||||
if (changeColor) {
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.Color) {
|
||||
startColor.color = ChangeHUE (startColor.color, newMaxColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.TwoColors) {
|
||||
startColor.colorMax = ChangeHUE (startColor.colorMax, newMaxColor);
|
||||
startColor.colorMin = ChangeHUE (startColor.colorMin, newMinColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.Gradient) {
|
||||
startColor.gradient = ChangeGradientColor (startColor.gradient, newMaxColor, newMinColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.TwoGradients) {
|
||||
startColor.gradientMax = ChangeGradientColor (startColor.gradientMax, newMaxColor, newMinColor);
|
||||
startColor.gradientMin = ChangeGradientColor (startColor.gradientMin, newMinColor, newMaxColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
|
||||
//COLOR OVERLIFETIME
|
||||
if (colorOverLifetime.enabled) {
|
||||
if (colorOverLifetime.color.mode == ParticleSystemGradientMode.Gradient) {
|
||||
colorOverLifetimeC.gradient = ChangeGradientColor (colorOverLifetimeC.gradient, newMaxColor, newMinColor);
|
||||
}
|
||||
if (colorOverLifetime.color.mode == ParticleSystemGradientMode.TwoGradients) {
|
||||
colorOverLifetimeC.gradientMax = ChangeGradientColor (colorOverLifetimeC.gradientMax, newMaxColor, newMinColor);
|
||||
colorOverLifetimeC.gradientMin = ChangeGradientColor (colorOverLifetimeC.gradientMin, newMinColor, newMaxColor);
|
||||
}
|
||||
colorOverLifetime.color = colorOverLifetimeC;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//TRAIL RENDERER
|
||||
var trail = ParticleSystems [i].GetComponent<TrailRenderer> ();
|
||||
if (trail != null) {
|
||||
if (!SaveParticleSystemScript.CheckExistingFile (gameObject)) {
|
||||
ParticleSystemOriginalSettings psOriginalSettings = new ParticleSystemOriginalSettings {
|
||||
_trailGradient = new SerializableGradient (trail.colorGradient),
|
||||
_localPosition = new SerializableVector3 (trail.transform.localPosition),
|
||||
_trailWidthMultiplier = trail.widthMultiplier,
|
||||
_trailTime = trail.time
|
||||
};
|
||||
psOriginalSettingsList.Add (psOriginalSettings);
|
||||
} else {
|
||||
List<ParticleSystemOriginalSettings> listOriginalSettings = new List<ParticleSystemOriginalSettings> ();
|
||||
listOriginalSettings = SaveParticleSystemScript.LoadVFX (gameObject);
|
||||
|
||||
trail.colorGradient = listOriginalSettings [i]._trailGradient.GetGradient();
|
||||
trail.transform.localPosition = listOriginalSettings [i]._localPosition.GetVector3 ();
|
||||
trail.widthMultiplier = listOriginalSettings [i]._trailWidthMultiplier;
|
||||
trail.time = listOriginalSettings [i]._trailTime;
|
||||
}
|
||||
trail.colorGradient = ChangeGradientColor (trail.colorGradient, newMaxColor, newMinColor);
|
||||
trail.widthMultiplier *= size;
|
||||
|
||||
float amount = 1;
|
||||
if(size != 1)
|
||||
amount = size;
|
||||
if(speed != 1)
|
||||
amount = speed;
|
||||
if(size != 1 && speed != 1)
|
||||
amount = (size + speed)/2;
|
||||
if(amount > 1)
|
||||
trail.time *= 1 / amount;
|
||||
else
|
||||
trail.time *= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!SaveParticleSystemScript.CheckExistingFile (gameObject)) {
|
||||
SaveParticleSystemScript.SaveVFX (gameObject, psOriginalSettingsList);
|
||||
}
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
else
|
||||
{
|
||||
SaveParticleSystemScript.SaveNestedPrefab(gameObject);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
Debug.Log("No Particle Systems added to the Particle Systems list");
|
||||
}
|
||||
|
||||
public void ChangeColorOnly () {
|
||||
if (ParticleSystems.Count == 0) {
|
||||
FillLists ();
|
||||
}
|
||||
|
||||
if (ParticleSystems.Count > 0) {
|
||||
for (int i = 0; i < ParticleSystems.Count; i++) {
|
||||
var ps = ParticleSystems [i].GetComponent<ParticleSystem> ();
|
||||
if (ps != null) {
|
||||
var main = ps.main;
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
var colorOverLifetimeC = colorOverLifetime.color;
|
||||
var startColor = main.startColor;
|
||||
//COLOR
|
||||
if (changeColor) {
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.Color) {
|
||||
startColor.color = ChangeHUE (startColor.color, newMaxColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.TwoColors) {
|
||||
startColor.colorMax = ChangeHUE (startColor.colorMax, newMaxColor);
|
||||
startColor.colorMin = ChangeHUE (startColor.colorMin, newMinColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.Gradient) {
|
||||
startColor.gradient = ChangeGradientColor (startColor.gradient, newMaxColor, newMinColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
if (main.startColor.mode == ParticleSystemGradientMode.TwoGradients) {
|
||||
startColor.gradientMax = ChangeGradientColor (startColor.gradientMax, newMaxColor, newMinColor);
|
||||
startColor.gradientMin = ChangeGradientColor (startColor.gradientMin, newMinColor, newMaxColor);
|
||||
main.startColor = startColor;
|
||||
}
|
||||
|
||||
//COLOR OVERLIFETIME
|
||||
if (colorOverLifetime.enabled) {
|
||||
if (colorOverLifetime.color.mode == ParticleSystemGradientMode.Gradient) {
|
||||
colorOverLifetimeC.gradient = ChangeGradientColor (colorOverLifetimeC.gradient, newMaxColor, newMinColor);
|
||||
}
|
||||
if (colorOverLifetime.color.mode == ParticleSystemGradientMode.TwoGradients) {
|
||||
colorOverLifetimeC.gradientMax = ChangeGradientColor (colorOverLifetimeC.gradientMax, newMaxColor, newMinColor);
|
||||
colorOverLifetimeC.gradientMin = ChangeGradientColor (colorOverLifetimeC.gradientMin, newMinColor, newMaxColor);
|
||||
}
|
||||
colorOverLifetime.color = colorOverLifetimeC;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//TRAIL RENDERER
|
||||
var trail = ParticleSystems [i].GetComponent<TrailRenderer> ();
|
||||
if (trail != null) {
|
||||
if (!SaveParticleSystemScript.CheckExistingFile (gameObject)) {
|
||||
ParticleSystemOriginalSettings psOriginalSettings = new ParticleSystemOriginalSettings {
|
||||
_trailGradient = new SerializableGradient (trail.colorGradient),
|
||||
_localPosition = new SerializableVector3 (trail.transform.localPosition),
|
||||
_trailWidthMultiplier = trail.widthMultiplier,
|
||||
_trailTime = trail.time
|
||||
};
|
||||
psOriginalSettingsList.Add (psOriginalSettings);
|
||||
} else {
|
||||
List<ParticleSystemOriginalSettings> listOriginalSettings = new List<ParticleSystemOriginalSettings> ();
|
||||
listOriginalSettings = SaveParticleSystemScript.LoadVFX (gameObject);
|
||||
|
||||
trail.colorGradient = listOriginalSettings [i]._trailGradient.GetGradient ();
|
||||
trail.transform.localPosition = listOriginalSettings [i]._localPosition.GetVector3 ();
|
||||
trail.widthMultiplier = listOriginalSettings [i]._trailWidthMultiplier;
|
||||
trail.time = listOriginalSettings [i]._trailTime;
|
||||
}
|
||||
trail.colorGradient = ChangeGradientColor (trail.colorGradient, newMaxColor, newMinColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ResizeOnly () {
|
||||
if (ParticleSystems.Count == 0) {
|
||||
FillLists ();
|
||||
}
|
||||
|
||||
if (ParticleSystems.Count > 0) {
|
||||
for (int i = 0; i < ParticleSystems.Count; i ++) {
|
||||
var ps = ParticleSystems [i].GetComponent<ParticleSystem> ();
|
||||
if (ps != null) {
|
||||
var main = ps.main;
|
||||
var shape = ps.shape;
|
||||
var startSize = main.startSize;
|
||||
var startSizeX = main.startSizeX;
|
||||
var startSizeY = main.startSizeY;
|
||||
var startSizeZ = main.startSizeZ;
|
||||
var startSpeed = main.startSpeed;
|
||||
var velocityOverLifetime = ps.velocityOverLifetime;
|
||||
var velocityOverLifetimeX = velocityOverLifetime.x;
|
||||
var velocityOverLifetimeY = velocityOverLifetime.y;
|
||||
var velocityOverLifetimeZ = velocityOverLifetime.z;
|
||||
var localPos = ParticleSystems [i].transform.localPosition;
|
||||
|
||||
//POSITION
|
||||
if (i > 0) {
|
||||
if (localPos.x != 0 || localPos.y != 0 || localPos.z != 0) {
|
||||
localPos.x *= size;
|
||||
localPos.y *= size;
|
||||
localPos.z *= size;
|
||||
ParticleSystems [i].transform.localPosition = localPos;
|
||||
}
|
||||
}
|
||||
|
||||
//SIZE
|
||||
if (main.startSize3D) {
|
||||
if (startSize.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSizeX.constantMax *= size;
|
||||
startSizeX.constantMin *= size;
|
||||
|
||||
startSizeY.constantMax *= size;
|
||||
startSizeY.constantMin *= size;
|
||||
|
||||
startSizeZ.constantMax *= size;
|
||||
startSizeZ.constantMin *= size;
|
||||
} else {
|
||||
startSizeX.constant *= size;
|
||||
startSizeY.constant *= size;
|
||||
startSizeZ.constant *= size;
|
||||
}
|
||||
main.startSizeX = startSizeX;
|
||||
main.startSizeY = startSizeY;
|
||||
main.startSizeZ = startSizeZ;
|
||||
} else {
|
||||
if (startSize.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSize.constantMax *= size;
|
||||
startSize.constantMin *= size;
|
||||
} else {
|
||||
startSize.constant *= size;
|
||||
}
|
||||
main.startSize = startSize;
|
||||
}
|
||||
|
||||
//START_SPEED (affected by size)
|
||||
if (startSpeed.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
startSpeed.constantMax *= size;
|
||||
startSpeed.constantMin *= size;
|
||||
main.startSpeed = startSpeed;
|
||||
} else {
|
||||
startSpeed.constant *= size;
|
||||
main.startSpeed = startSpeed;
|
||||
}
|
||||
|
||||
//VELOCITY OVERLIFETIME
|
||||
if(velocityOverLifetime.enabled){
|
||||
float amount = 1;
|
||||
if(size != 1)
|
||||
amount = size;
|
||||
if(speed != 1)
|
||||
amount = speed;
|
||||
if(size != 1 && speed != 1)
|
||||
amount = (size + speed)/2;
|
||||
|
||||
if (velocityOverLifetime.x.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
velocityOverLifetimeX.constantMax *= amount;
|
||||
velocityOverLifetimeX.constantMin *= amount;
|
||||
|
||||
velocityOverLifetimeY.constantMax *= amount;
|
||||
velocityOverLifetimeY.constantMin *= amount;
|
||||
|
||||
velocityOverLifetimeZ.constantMax *= amount;
|
||||
velocityOverLifetimeZ.constantMin *= amount;
|
||||
} else {
|
||||
velocityOverLifetimeX.constant *= amount;
|
||||
velocityOverLifetimeY.constant *= amount;
|
||||
velocityOverLifetimeZ.constant *= amount;
|
||||
}
|
||||
velocityOverLifetime.x = velocityOverLifetimeX;
|
||||
velocityOverLifetime.y = velocityOverLifetimeY;
|
||||
velocityOverLifetime.z = velocityOverLifetimeZ;
|
||||
}
|
||||
|
||||
//RADIUS
|
||||
if (shape.enabled) {
|
||||
shape.radius *= size;
|
||||
}
|
||||
}
|
||||
else{
|
||||
//TRAIL RENDERER
|
||||
var trail = ParticleSystems [i].GetComponent<TrailRenderer> ();
|
||||
if (trail != null) {
|
||||
trail.widthMultiplier *= size;
|
||||
|
||||
float amount = 1;
|
||||
if(size != 1)
|
||||
amount = size;
|
||||
if(speed != 1)
|
||||
amount = speed;
|
||||
if(size != 1 && speed != 1)
|
||||
amount = (size + speed)/2;
|
||||
if(amount > 1)
|
||||
trail.time *= 1 / amount;
|
||||
else
|
||||
trail.time *= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetParticleSystem (){
|
||||
|
||||
List<ParticleSystemOriginalSettings> listOriginalSettings = new List<ParticleSystemOriginalSettings> ();
|
||||
listOriginalSettings = SaveParticleSystemScript.LoadVFX (gameObject);
|
||||
|
||||
if (listOriginalSettings != null) {
|
||||
for (int i = 0; i < ParticleSystems.Count; i++) {
|
||||
var ps = ParticleSystems [i].GetComponent<ParticleSystem> ();
|
||||
if (ps != null) {
|
||||
var main = ps.main;
|
||||
var shape = ps.shape;
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
var velocityOverLifetime = ps.velocityOverLifetime;
|
||||
main.startColor = listOriginalSettings [i]._startColor.GetMinMaxGradient ();
|
||||
colorOverLifetime.color = listOriginalSettings [i]._colorOverLifetimeC.GetMinMaxGradient ();
|
||||
main.startSize = listOriginalSettings [i]._startSize.GetMinMaxCurve ();
|
||||
main.startSizeX = listOriginalSettings [i]._startSizeX.GetMinMaxCurve ();
|
||||
main.startSizeY = listOriginalSettings [i]._startSizeY.GetMinMaxCurve ();
|
||||
main.startSizeZ = listOriginalSettings [i]._startSizeZ.GetMinMaxCurve ();
|
||||
main.startSpeed = listOriginalSettings [i]._startSpeed.GetMinMaxCurve ();
|
||||
main.startDelay = listOriginalSettings [i]._startDelay.GetMinMaxCurve ();
|
||||
main.startLifetime = listOriginalSettings [i]._startLifetime.GetMinMaxCurve ();
|
||||
velocityOverLifetime.x = listOriginalSettings [i]._velocityOverLifetimeX.GetMinMaxCurve ();
|
||||
velocityOverLifetime.y = listOriginalSettings [i]._velocityOverLifetimeY.GetMinMaxCurve ();
|
||||
velocityOverLifetime.z = listOriginalSettings [i]._velocityOverLifetimeZ.GetMinMaxCurve ();
|
||||
ParticleSystems [i].transform.localPosition = listOriginalSettings [i]._localPosition.GetVector3 ();
|
||||
main.duration = listOriginalSettings [i]._duration;
|
||||
shape.radius = listOriginalSettings [i]._shapeRadius;
|
||||
ps.gameObject.SetActive (listOriginalSettings [i]._active);
|
||||
main.loop = listOriginalSettings [i]._loop;
|
||||
main.prewarm = listOriginalSettings [i]._prewarm;
|
||||
} else {
|
||||
var trail = ParticleSystems [i].GetComponent<TrailRenderer> ();
|
||||
if (trail != null) {
|
||||
trail.colorGradient = listOriginalSettings [i]._trailGradient.GetGradient ();
|
||||
trail.widthMultiplier = listOriginalSettings [i]._trailWidthMultiplier;
|
||||
trail.time = listOriginalSettings [i]._trailTime;
|
||||
ParticleSystems [i].transform.localPosition = listOriginalSettings [i]._localPosition.GetVector3 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
SaveParticleSystemScript.SaveNestedPrefab(gameObject);
|
||||
#endif
|
||||
Debug.Log ( gameObject.name + " reseted to default.");
|
||||
}
|
||||
}
|
||||
|
||||
public Color ChangeHUE (Color oldColor, Color newColor){
|
||||
float newHue;
|
||||
float newSaturation;
|
||||
float newValue;
|
||||
float oldHue;
|
||||
float oldSaturation;
|
||||
float oldValue;
|
||||
float originalAlpha = oldColor.a;
|
||||
Color.RGBToHSV (newColor, out newHue, out newSaturation, out newValue);
|
||||
Color.RGBToHSV (oldColor, out oldHue, out oldSaturation, out oldValue);
|
||||
var updatedColor = Color.HSVToRGB (newHue, oldSaturation, oldValue);
|
||||
updatedColor.a = originalAlpha;
|
||||
return updatedColor;
|
||||
}
|
||||
|
||||
public Gradient ChangeGradientColor (Gradient oldGradient, Color newMaxColor, Color newMinColor){
|
||||
GradientColorKey[] colorKeys = new GradientColorKey[oldGradient.colorKeys.Length];
|
||||
for(int j = 0; j < oldGradient.colorKeys.Length; j++){
|
||||
colorKeys [j].time = oldGradient.colorKeys [j].time;
|
||||
if(j%2 == 0)
|
||||
colorKeys [j].color = ChangeHUE (oldGradient.colorKeys[j].color, newMaxColor);
|
||||
if(j%2 == 1)
|
||||
colorKeys [j].color = ChangeHUE (oldGradient.colorKeys[j].color, newMinColor);
|
||||
}
|
||||
oldGradient.SetKeys (colorKeys, oldGradient.alphaKeys);
|
||||
return oldGradient;
|
||||
}
|
||||
|
||||
public void FillLists (){
|
||||
if (ParticleSystems.Count == 0) {
|
||||
var ps = GetComponent<ParticleSystem> ();
|
||||
var trail = GetComponent<TrailRenderer> ();
|
||||
if (ps != null || trail != null)
|
||||
ParticleSystems.Add (gameObject);
|
||||
|
||||
AddChildRecurvsively (transform);
|
||||
|
||||
for (int i = 0; i < ParticleSystems.Count; i++) {
|
||||
ActiveParticleSystems.Add (true);
|
||||
}
|
||||
} else {
|
||||
Debug.Log ("Lists already have GameObjects. For automatic filling consider emptying the lists and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
public void EmptyLists (){
|
||||
ParticleSystems.Clear();
|
||||
ActiveParticleSystems.Clear();
|
||||
}
|
||||
|
||||
void AddChildRecurvsively (Transform transf){
|
||||
foreach (Transform t in transf) {
|
||||
var child = t.gameObject;
|
||||
var psChild = child.GetComponent<ParticleSystem> ();
|
||||
var trailChild = child.GetComponent<TrailRenderer> ();
|
||||
if (psChild != null || trailChild != null)
|
||||
ParticleSystems.Add (child);
|
||||
if (child.transform.childCount > 0)
|
||||
AddChildRecurvsively (child.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9e272d634f40434b85fbf756732714d
|
||||
timeCreated: 1519590398
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
namespace GAP_ParticleSystemController{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(ParticleSystemController))]
|
||||
public class ParticleSystemControllerEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
ParticleSystemController psCtrl = (ParticleSystemController)target;
|
||||
|
||||
if (GUILayout.Button ("Fill Lists"))
|
||||
{
|
||||
psCtrl.FillLists ();
|
||||
}
|
||||
if (GUILayout.Button ("Empty Lists"))
|
||||
{
|
||||
psCtrl.EmptyLists ();
|
||||
}
|
||||
if(GUILayout.Button("Apply"))
|
||||
{
|
||||
psCtrl.UpdateParticleSystem();
|
||||
}
|
||||
if(GUILayout.Button("Reset"))
|
||||
{
|
||||
psCtrl.ResetParticleSystem();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45d4e8a998e88754d8ce3fc6827b2912
|
||||
timeCreated: 1523291927
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Reflection;
|
||||
|
||||
namespace GAP_ParticleSystemController
|
||||
{
|
||||
|
||||
public static class SaveParticleSystemScript{
|
||||
|
||||
public static void SaveVFX (GameObject prefabVFX, List<ParticleSystemOriginalSettings> psOriginalSettingsList) {
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
var prefabFolderPath = GetPrefabFolder2018_3 (prefabVFX);
|
||||
#else
|
||||
var prefabFolderPath = GetPrefabFolder (prefabVFX);
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Directory.Exists (prefabFolderPath + "/OriginalSettings")) {
|
||||
UnityEditor.AssetDatabase.CreateFolder (prefabFolderPath, "OriginalSettings");
|
||||
Debug.Log ("Created folder: " + prefabFolderPath + "/OriginalSettings");
|
||||
}
|
||||
#endif
|
||||
BinaryFormatter bf = new BinaryFormatter ();
|
||||
FileStream stream = new FileStream (prefabFolderPath + "/OriginalSettings/" + prefabVFX.name + ".dat", FileMode.Create);
|
||||
|
||||
bf.Serialize (stream, psOriginalSettingsList);
|
||||
stream.Close ();
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
SaveNestedPrefab(prefabVFX);
|
||||
#endif
|
||||
|
||||
Debug.Log ("Original Settings of '" + prefabVFX.name + "' saved to: " + prefabFolderPath + "/OriginalSettings");
|
||||
}
|
||||
|
||||
public static List<ParticleSystemOriginalSettings> LoadVFX (GameObject prefabVFX) {
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
var prefabFolderPath = GetPrefabFolder2018_3 (prefabVFX);
|
||||
#else
|
||||
var prefabFolderPath = GetPrefabFolder(prefabVFX);
|
||||
#endif
|
||||
|
||||
if (File.Exists (prefabFolderPath + "/OriginalSettings/" + prefabVFX.name + ".dat")) {
|
||||
BinaryFormatter bf = new BinaryFormatter ();
|
||||
FileStream stream = new FileStream (prefabFolderPath + "/OriginalSettings/" + prefabVFX.name + ".dat", FileMode.Open);
|
||||
|
||||
List<ParticleSystemOriginalSettings> originalSettingsList = new List<ParticleSystemOriginalSettings> ();
|
||||
originalSettingsList = bf.Deserialize (stream) as List<ParticleSystemOriginalSettings>;
|
||||
|
||||
stream.Close ();
|
||||
return originalSettingsList;
|
||||
|
||||
} else {
|
||||
Debug.Log ("No saved VFX data found");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckExistingFile (GameObject prefabVFX){
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
var prefabFolderPath = GetPrefabFolder2018_3 (prefabVFX);
|
||||
#else
|
||||
var prefabFolderPath = GetPrefabFolder(prefabVFX);
|
||||
#endif
|
||||
if (prefabFolderPath != null) {
|
||||
if (File.Exists (prefabFolderPath + "/OriginalSettings/" + prefabVFX.name + ".dat"))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
static string GetPrefabFolder (GameObject prefabVFX){
|
||||
#if UNITY_EDITOR
|
||||
string prefabPath = UnityEditor.AssetDatabase.GetAssetPath (prefabVFX);
|
||||
string prefabFolderPath = Path.GetDirectoryName (prefabPath);
|
||||
return prefabFolderPath;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
static string GetPrefabFolder2018_3 (GameObject prefabVFX)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string prefabPath = UnityEditor.SceneManagement.PrefabStageUtility.GetPrefabStage(prefabVFX).prefabAssetPath;
|
||||
string prefabFolderPath = Path.GetDirectoryName (prefabPath);
|
||||
return prefabFolderPath;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
public static void SaveNestedPrefab(GameObject prefab)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetPrefabStage(prefab);
|
||||
UnityEditor.PrefabUtility.SaveAsPrefabAsset(prefabStage.prefabContentsRoot, prefabStage.prefabAssetPath);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebcd90b1eae99d848ad993f40990f336
|
||||
timeCreated: 1532255172
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,484 @@
|
||||
|
||||
|
||||
#pragma warning disable 0162 // unreachable code detected.
|
||||
#pragma warning disable 0168 // variable declared but not used.
|
||||
#pragma warning disable 0219 // variable assigned but not used.
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
#pragma warning disable 0472 // comparing color with null is always null.
|
||||
#pragma warning disable 0618 // tangent mode obsolete warning.
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace GAP_ParticleSystemController{
|
||||
|
||||
[Serializable]
|
||||
public class SerializableMinMaxGradient{
|
||||
public SerializableColor color;
|
||||
public SerializableColor colorMax;
|
||||
public SerializableColor colorMin;
|
||||
public SerializableAlphaKeys gradientAlphaKeys;
|
||||
public SerializableColorKeys gradientColorKeys;
|
||||
public SerializableAlphaKeys gradientMaxAlphaKeys;
|
||||
public SerializableColorKeys gradientMaxColorKeys;
|
||||
public SerializableAlphaKeys gradientMinAlphaKeys;
|
||||
public SerializableColorKeys gradientMinColorKeys;
|
||||
public SerializablePSGradientMode gradientMode;
|
||||
|
||||
public SerializableMinMaxGradient (ParticleSystem.MinMaxGradient minMaxGradient){
|
||||
|
||||
gradientMode = new SerializablePSGradientMode (minMaxGradient.mode);
|
||||
|
||||
if (minMaxGradient.mode == ParticleSystemGradientMode.Color)
|
||||
color = new SerializableColor (minMaxGradient.color);
|
||||
|
||||
if (minMaxGradient.mode == ParticleSystemGradientMode.TwoColors) {
|
||||
colorMax = new SerializableColor (minMaxGradient.colorMax);
|
||||
colorMin = new SerializableColor (minMaxGradient.colorMin);
|
||||
}
|
||||
|
||||
if (minMaxGradient.mode == ParticleSystemGradientMode.Gradient) {
|
||||
gradientAlphaKeys = new SerializableAlphaKeys (minMaxGradient.gradient.alphaKeys);
|
||||
gradientColorKeys = new SerializableColorKeys (minMaxGradient.gradient.colorKeys);
|
||||
}
|
||||
|
||||
if (minMaxGradient.mode == ParticleSystemGradientMode.TwoGradients) {
|
||||
gradientMaxAlphaKeys = new SerializableAlphaKeys (minMaxGradient.gradientMax.alphaKeys);
|
||||
gradientMaxColorKeys = new SerializableColorKeys (minMaxGradient.gradientMax.colorKeys);
|
||||
gradientMinAlphaKeys = new SerializableAlphaKeys (minMaxGradient.gradientMin.alphaKeys);
|
||||
gradientMinColorKeys = new SerializableColorKeys (minMaxGradient.gradientMin.colorKeys);
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleSystem.MinMaxGradient GetMinMaxGradient (){
|
||||
ParticleSystem.MinMaxGradient minMaxGradient = new ParticleSystem.MinMaxGradient ();
|
||||
if (gradientMode.GetGradientMode () == ParticleSystemGradientMode.Color) {
|
||||
if (minMaxGradient.color == null)
|
||||
minMaxGradient.color = new Color ();
|
||||
minMaxGradient.color = color.GetColor ();
|
||||
}
|
||||
|
||||
if (gradientMode.GetGradientMode() == ParticleSystemGradientMode.TwoColors) {
|
||||
if (minMaxGradient.colorMax == null)
|
||||
minMaxGradient.colorMax = new Color ();
|
||||
minMaxGradient.colorMax = colorMax.GetColor ();
|
||||
|
||||
if (minMaxGradient.colorMin == null)
|
||||
minMaxGradient.colorMin = new Color ();
|
||||
minMaxGradient.colorMin = colorMin.GetColor ();
|
||||
}
|
||||
|
||||
if (gradientMode.GetGradientMode() == ParticleSystemGradientMode.Gradient) {
|
||||
if (minMaxGradient.gradient == null)
|
||||
minMaxGradient.gradient = new Gradient ();
|
||||
minMaxGradient.gradient.alphaKeys = gradientAlphaKeys.GetAlphaKeys ();
|
||||
minMaxGradient.gradient.colorKeys = gradientColorKeys.GetColorKeys ();
|
||||
}
|
||||
|
||||
if (gradientMode.GetGradientMode() == ParticleSystemGradientMode.TwoGradients) {
|
||||
if (minMaxGradient.gradientMax == null)
|
||||
minMaxGradient.gradientMax = new Gradient ();
|
||||
minMaxGradient.gradientMax.alphaKeys = gradientMaxAlphaKeys.GetAlphaKeys ();
|
||||
minMaxGradient.gradientMax.colorKeys = gradientMaxColorKeys.GetColorKeys ();
|
||||
|
||||
if (minMaxGradient.gradientMin == null)
|
||||
minMaxGradient.gradientMin = new Gradient ();
|
||||
minMaxGradient.gradientMin.alphaKeys = gradientMinAlphaKeys.GetAlphaKeys ();
|
||||
minMaxGradient.gradientMin.colorKeys = gradientMinColorKeys.GetColorKeys ();
|
||||
}
|
||||
|
||||
minMaxGradient.mode = gradientMode.GetGradientMode ();
|
||||
|
||||
return minMaxGradient;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableMinMaxCurve{
|
||||
public float constant;
|
||||
public float constantMax;
|
||||
public float constantMin;
|
||||
public SerializableAnimationCurve curve;
|
||||
public SerializableAnimationCurve curveMax;
|
||||
public SerializableAnimationCurve curveMin;
|
||||
public float curveMultiplier;
|
||||
public SerializablePSCurveMode curveMode;
|
||||
|
||||
public SerializableMinMaxCurve (ParticleSystem.MinMaxCurve minMaxCurve){
|
||||
|
||||
curveMode = new SerializablePSCurveMode (minMaxCurve.mode);
|
||||
|
||||
if (minMaxCurve.mode == ParticleSystemCurveMode.Constant)
|
||||
constant = minMaxCurve.constant;
|
||||
|
||||
if (minMaxCurve.mode == ParticleSystemCurveMode.Curve)
|
||||
curve = new SerializableAnimationCurve (minMaxCurve.curve);
|
||||
|
||||
if (minMaxCurve.mode == ParticleSystemCurveMode.TwoConstants) {
|
||||
constantMax = minMaxCurve.constantMax;
|
||||
constantMin = minMaxCurve.constantMin;
|
||||
}
|
||||
|
||||
if (minMaxCurve.mode == ParticleSystemCurveMode.TwoCurves) {
|
||||
curveMax = new SerializableAnimationCurve (minMaxCurve.curveMax);
|
||||
curveMin = new SerializableAnimationCurve (minMaxCurve.curve);
|
||||
}
|
||||
|
||||
curveMultiplier = minMaxCurve.curveMultiplier;
|
||||
}
|
||||
|
||||
public ParticleSystem.MinMaxCurve GetMinMaxCurve (){
|
||||
ParticleSystem.MinMaxCurve minMaxCurve = new ParticleSystem.MinMaxCurve ();
|
||||
|
||||
if (curveMode.GetCurveMode() == ParticleSystemCurveMode.Constant)
|
||||
minMaxCurve.constant = constant;
|
||||
|
||||
if (curveMode.GetCurveMode() == ParticleSystemCurveMode.TwoConstants) {
|
||||
minMaxCurve.constantMax = constantMax;
|
||||
minMaxCurve.constantMin = constantMin;
|
||||
}
|
||||
|
||||
if (curveMode.GetCurveMode () == ParticleSystemCurveMode.Curve) {
|
||||
if (minMaxCurve.curve == null)
|
||||
minMaxCurve.curve = new AnimationCurve ();
|
||||
minMaxCurve.curve = curve.GetAnimationCurve ();
|
||||
}
|
||||
|
||||
if (curveMode.GetCurveMode() == ParticleSystemCurveMode.TwoCurves) {
|
||||
if (minMaxCurve.curveMax == null)
|
||||
minMaxCurve.curveMax = new AnimationCurve ();
|
||||
minMaxCurve.curveMax = curveMax.GetAnimationCurve();
|
||||
|
||||
if (minMaxCurve.curveMin == null)
|
||||
minMaxCurve.curveMin = new AnimationCurve ();
|
||||
minMaxCurve.curveMin = curveMin.GetAnimationCurve();
|
||||
}
|
||||
|
||||
minMaxCurve.curveMultiplier = curveMultiplier;
|
||||
minMaxCurve.mode = curveMode.GetCurveMode ();
|
||||
|
||||
return minMaxCurve;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableAnimationCurve {
|
||||
public SerializableKeyFrames[] keys;
|
||||
public SerializableWrapMode postWrapMode;
|
||||
public SerializableWrapMode preWrapMode;
|
||||
|
||||
public SerializableAnimationCurve (AnimationCurve animCurve){
|
||||
SerializableKeyFrames[] keys_ = new SerializableKeyFrames[animCurve.keys.Length];
|
||||
for (int i = 0; i < animCurve.length; i++) {
|
||||
keys_[i] = new SerializableKeyFrames (animCurve.keys[i]);
|
||||
}
|
||||
keys = keys_;
|
||||
postWrapMode = new SerializableWrapMode(animCurve.postWrapMode);
|
||||
preWrapMode = new SerializableWrapMode(animCurve.preWrapMode);
|
||||
}
|
||||
|
||||
public AnimationCurve GetAnimationCurve (){
|
||||
AnimationCurve animCurv = new AnimationCurve ();
|
||||
animCurv.keys = new Keyframe[keys.Length];
|
||||
for(int i = 0; i < keys.Length; i++){
|
||||
animCurv.keys[i] = keys[i].GetKeyFrames();
|
||||
}
|
||||
animCurv.postWrapMode = postWrapMode.GetWrapMode();
|
||||
animCurv.preWrapMode = preWrapMode.GetWrapMode();
|
||||
|
||||
return animCurv;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableKeyFrames{
|
||||
public float inTangent;
|
||||
public float outTangent;
|
||||
public int tangentMode;
|
||||
public float time;
|
||||
public float value;
|
||||
|
||||
public SerializableKeyFrames (Keyframe keyFrame){
|
||||
|
||||
inTangent = keyFrame.inTangent;
|
||||
outTangent = keyFrame.outTangent;
|
||||
tangentMode = keyFrame.tangentMode;
|
||||
|
||||
time = keyFrame.time;
|
||||
value = keyFrame.value;
|
||||
}
|
||||
|
||||
public Keyframe GetKeyFrames (){
|
||||
Keyframe kf = new Keyframe();
|
||||
|
||||
kf.inTangent = inTangent;
|
||||
kf.outTangent = outTangent;
|
||||
kf.tangentMode = tangentMode;
|
||||
kf.time = time;
|
||||
kf.value = value;
|
||||
|
||||
return kf;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableAlphaKeys{
|
||||
public float[] alpha;
|
||||
public float[] time;
|
||||
|
||||
public SerializableAlphaKeys (GradientAlphaKey[] gradAlphaKeys){
|
||||
float[] alpha_ = new float[gradAlphaKeys.Length];
|
||||
float[] time_ = new float[gradAlphaKeys.Length];
|
||||
for (int i = 0; i < gradAlphaKeys.Length; i++) {
|
||||
alpha_[i] = gradAlphaKeys[i].alpha;
|
||||
time_[i] = gradAlphaKeys[i].time;
|
||||
}
|
||||
alpha = alpha_;
|
||||
time = time_;
|
||||
}
|
||||
|
||||
public GradientAlphaKey[] GetAlphaKeys (){
|
||||
GradientAlphaKey[] gak = new GradientAlphaKey[alpha.Length];
|
||||
for (int i = 0; i < alpha.Length; i++) {
|
||||
gak [i].alpha = alpha [i];
|
||||
gak [i].time = time [i];
|
||||
}
|
||||
return gak;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableColorKeys{
|
||||
public SerializableColor[] color;
|
||||
public float[] time;
|
||||
|
||||
public SerializableColorKeys (GradientColorKey[] gradColorKeys){
|
||||
SerializableColor[] color_ = new SerializableColor[gradColorKeys.Length];
|
||||
float[] time_ = new float[gradColorKeys.Length];
|
||||
for (int i = 0; i < gradColorKeys.Length; i++) {
|
||||
color_[i] = new SerializableColor (gradColorKeys[i].color);
|
||||
time_[i] = gradColorKeys[i].time;
|
||||
}
|
||||
color = color_;
|
||||
time = time_;
|
||||
}
|
||||
|
||||
public GradientColorKey[] GetColorKeys (){
|
||||
GradientColorKey[] gck = new GradientColorKey[color.Length];
|
||||
for (int i = 0; i < color.Length; i++) {
|
||||
gck [i].color = color [i].GetColor();
|
||||
gck [i].time = time [i];
|
||||
}
|
||||
return gck;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableColor {
|
||||
public float R;
|
||||
public float G;
|
||||
public float B;
|
||||
public float A;
|
||||
|
||||
public SerializableColor (Color color){
|
||||
R = color.r;
|
||||
G = color.g;
|
||||
B = color.b;
|
||||
A = color.a;
|
||||
}
|
||||
|
||||
public Color GetColor (){
|
||||
return new Color (R,G,B,A);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableVector3 {
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public SerializableVector3 (Vector3 v3){
|
||||
x = v3.x;
|
||||
y = v3.y;
|
||||
z = v3.z;
|
||||
}
|
||||
|
||||
public Vector3 GetVector3 (){
|
||||
return new Vector3 (x,y,z);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableGradient{
|
||||
public SerializableAlphaKeys gradientAlphaKeys;
|
||||
public SerializableColorKeys gradientColorKeys;
|
||||
public SerializableGradientMode gradientMode;
|
||||
|
||||
public SerializableGradient (Gradient gradient){
|
||||
gradientMode = new SerializableGradientMode (gradient.mode);
|
||||
gradientAlphaKeys = new SerializableAlphaKeys (gradient.alphaKeys);
|
||||
gradientColorKeys = new SerializableColorKeys (gradient.colorKeys);
|
||||
}
|
||||
|
||||
public Gradient GetGradient (){
|
||||
Gradient gradient = new Gradient ();
|
||||
gradient.alphaKeys = gradientAlphaKeys.GetAlphaKeys ();
|
||||
gradient.colorKeys = gradientColorKeys.GetColorKeys ();
|
||||
gradient.mode = gradientMode.GetGradientMode ();
|
||||
|
||||
return gradient;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializablePSGradientMode{
|
||||
public string mode;
|
||||
|
||||
public SerializablePSGradientMode (ParticleSystemGradientMode psGradientMode){
|
||||
mode = psGradientMode.ToString();
|
||||
}
|
||||
|
||||
public ParticleSystemGradientMode GetGradientMode (){
|
||||
ParticleSystemGradientMode psGradientMode = new ParticleSystemGradientMode ();
|
||||
switch (mode) {
|
||||
case "Color":
|
||||
{
|
||||
psGradientMode = ParticleSystemGradientMode.Color;
|
||||
break;
|
||||
}
|
||||
case "Gradient":
|
||||
{
|
||||
psGradientMode = ParticleSystemGradientMode.Gradient;
|
||||
break;
|
||||
}
|
||||
case "RandomColor":
|
||||
{
|
||||
psGradientMode = ParticleSystemGradientMode.RandomColor;
|
||||
break;
|
||||
}
|
||||
case "TwoColors":
|
||||
{
|
||||
psGradientMode = ParticleSystemGradientMode.TwoColors;
|
||||
break;
|
||||
}
|
||||
case "TwoGradients":
|
||||
{
|
||||
psGradientMode = ParticleSystemGradientMode.TwoGradients;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return psGradientMode;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableGradientMode{
|
||||
public string mode;
|
||||
|
||||
public SerializableGradientMode (GradientMode gradientMode){
|
||||
mode = gradientMode.ToString();
|
||||
}
|
||||
|
||||
public GradientMode GetGradientMode (){
|
||||
GradientMode gradientMode = new GradientMode ();
|
||||
switch (mode) {
|
||||
case "Blend":
|
||||
{
|
||||
gradientMode = GradientMode.Blend;
|
||||
break;
|
||||
}
|
||||
case "Fixed":
|
||||
{
|
||||
gradientMode = GradientMode.Fixed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return gradientMode;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializablePSCurveMode{
|
||||
public string mode;
|
||||
|
||||
public SerializablePSCurveMode (ParticleSystemCurveMode psCurveMode){
|
||||
mode = psCurveMode.ToString();
|
||||
}
|
||||
|
||||
public ParticleSystemCurveMode GetCurveMode (){
|
||||
ParticleSystemCurveMode psCurveMode = new ParticleSystemCurveMode ();
|
||||
switch (mode) {
|
||||
case "Constant":
|
||||
{
|
||||
psCurveMode = ParticleSystemCurveMode.Constant;
|
||||
break;
|
||||
}
|
||||
case "Curve":
|
||||
{
|
||||
psCurveMode = ParticleSystemCurveMode.Curve;
|
||||
break;
|
||||
}
|
||||
case "TwoConstants":
|
||||
{
|
||||
psCurveMode = ParticleSystemCurveMode.TwoConstants;
|
||||
break;
|
||||
}
|
||||
case "TwoCurves":
|
||||
{
|
||||
psCurveMode = ParticleSystemCurveMode.TwoCurves;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return psCurveMode;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableWrapMode {
|
||||
public string mode;
|
||||
|
||||
public SerializableWrapMode (WrapMode wrapMode){
|
||||
mode = wrapMode.ToString();
|
||||
}
|
||||
|
||||
public WrapMode GetWrapMode (){
|
||||
WrapMode wrapMode = new WrapMode ();
|
||||
switch (mode) {
|
||||
case "Clamp":
|
||||
{
|
||||
wrapMode = WrapMode.Clamp;
|
||||
break;
|
||||
}
|
||||
case "ClampForever":
|
||||
{
|
||||
wrapMode = WrapMode.ClampForever;
|
||||
break;
|
||||
}
|
||||
case "Default":
|
||||
{
|
||||
wrapMode = WrapMode.Default;
|
||||
break;
|
||||
}
|
||||
case "Loop":
|
||||
{
|
||||
wrapMode = WrapMode.Loop;
|
||||
break;
|
||||
}
|
||||
case "Once":
|
||||
{
|
||||
wrapMode = WrapMode.Once;
|
||||
break;
|
||||
}
|
||||
case "PingPong":
|
||||
{
|
||||
wrapMode = WrapMode.PingPong;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return wrapMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06137310f20d06f4eb859f958f491cc1
|
||||
timeCreated: 1532254155
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3926dad8756c5774b8ff97116ff9a960
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using GAP_LaserSystem;
|
||||
|
||||
public class CycleLasersScript : MonoBehaviour {
|
||||
|
||||
public GameObject playerFirePoint;
|
||||
public List<GameObject> targetPoints;
|
||||
public List<GameObject> Lasers = new List<GameObject> ();
|
||||
|
||||
private int count = 0;
|
||||
private GameObject newLaser;
|
||||
private LaserScript laserScript;
|
||||
private WaitForSeconds shortWait = new WaitForSeconds (0.5f);
|
||||
private WaitForSeconds longWait = new WaitForSeconds (4);
|
||||
|
||||
void Start () {
|
||||
StartCoroutine (CycleLasers());
|
||||
}
|
||||
|
||||
IEnumerator CycleLasers (){
|
||||
for(int i = 0; i<Lasers.Count; i++){
|
||||
|
||||
newLaser = Instantiate (Lasers [i]);
|
||||
laserScript = newLaser.GetComponent<LaserScript> ();
|
||||
//laserScript.bounces = 1; add bounces to the Laser
|
||||
laserScript.useTrail = false;
|
||||
laserScript.firePoint = playerFirePoint;
|
||||
laserScript.endPoint = targetPoints [Random.Range (0, targetPoints.Count)].gameObject;
|
||||
newLaser.SetActive (true);
|
||||
laserScript.ShootLaser (3);
|
||||
|
||||
yield return longWait;
|
||||
|
||||
Destroy (newLaser);
|
||||
}
|
||||
|
||||
StartCoroutine (CycleLasers());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74bcebd964ae7584b826ba375d318c5a
|
||||
timeCreated: 1530098275
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FirstPersonControllerScript : MonoBehaviour {
|
||||
|
||||
public float speed = 6.0F;
|
||||
public float jumpSpeed = 8.0F;
|
||||
public float gravity = 20.0F;
|
||||
private Vector3 moveDirection = Vector3.zero;
|
||||
|
||||
float yRotation;
|
||||
float xRotation;
|
||||
float lookSensitivity = 2;
|
||||
float currentXRotation;
|
||||
float currentYRotation;
|
||||
float yRotationV;
|
||||
float xRotationV;
|
||||
float lookSmoothnes = 0.1f;
|
||||
|
||||
void Start(){
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
CharacterController controller = GetComponent<CharacterController>();
|
||||
if (controller.isGrounded) {
|
||||
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
||||
moveDirection = transform.TransformDirection(moveDirection);
|
||||
moveDirection *= speed;
|
||||
if (Input.GetButton("Jump"))
|
||||
moveDirection.y = jumpSpeed;
|
||||
|
||||
}
|
||||
moveDirection.y -= gravity * Time.deltaTime;
|
||||
controller.Move(moveDirection * Time.deltaTime);
|
||||
|
||||
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
|
||||
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
|
||||
xRotation = Mathf.Clamp(xRotation, -80, 100);
|
||||
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothnes);
|
||||
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothnes);
|
||||
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3c0a8c57d7efa240aa50919a5b1e0a6
|
||||
timeCreated: 1530138917
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LaserGunScript : MonoBehaviour {
|
||||
|
||||
private Animator anim;
|
||||
|
||||
void Start(){
|
||||
anim = GetComponent<Animator> ();
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if (Input.GetMouseButtonDown (0)) {
|
||||
anim.SetTrigger ("isFiring");
|
||||
}
|
||||
|
||||
if(Input.GetMouseButtonUp (0)){
|
||||
anim.SetTrigger ("isIdle");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 588e1181360642a498965706f7033505
|
||||
timeCreated: 1528988636
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,983 @@
|
||||
#pragma warning disable 0162 // unreachable code detected.
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using GAP_ParticleSystemController;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace GAP_LaserSystem{
|
||||
|
||||
public class PSList {
|
||||
|
||||
public enum PSLIST_TYPE {start, middle, end};
|
||||
public GameObject _parent;
|
||||
public List<ParticleSystem> _listPS = new List<ParticleSystem>();
|
||||
public PSLIST_TYPE _psType;
|
||||
|
||||
private bool _disable;
|
||||
|
||||
//auxiliary function to add particle systems to a given list from a gameobject
|
||||
public void AddPSToList (GameObject obj, bool addFromObj) {
|
||||
if (addFromObj) {
|
||||
var psObj = obj.GetComponent<ParticleSystem> ();
|
||||
if (psObj != null)
|
||||
_listPS.Add (psObj);
|
||||
}
|
||||
|
||||
if(obj.transform.childCount>0){
|
||||
for (int i = 0; i < obj.transform.childCount; i++) {
|
||||
var ps = obj.transform.GetChild (i).GetComponent<ParticleSystem> ();
|
||||
if(ps != null)
|
||||
_listPS.Add (ps);
|
||||
}
|
||||
}
|
||||
else
|
||||
Debug.Log ("The GameObject " + obj.name + " contains no childs.");
|
||||
}
|
||||
|
||||
//auxiliary function to enable a list of particle systems
|
||||
public void EnablePS (){
|
||||
for (int i = 0; i < _listPS.Count; i++) {
|
||||
if (_listPS [i].isEmitting == false){
|
||||
_disable = false;
|
||||
_listPS [i].Play ();
|
||||
var emission = _listPS [i].emission;
|
||||
emission.enabled = true;
|
||||
_listPS [i].gameObject.SetActive (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//auxiliary function to stop and disable emission of a list of particle systems
|
||||
public void DisablePS (bool disableImmediately){
|
||||
for (int i = 0; i < _listPS.Count; i++) {
|
||||
if(_listPS[i].isEmitting == true) {
|
||||
_disable = true;
|
||||
_listPS [i].Stop ();
|
||||
var emission = _listPS [i].emission;
|
||||
emission.enabled = false;
|
||||
if (disableImmediately == false)
|
||||
DelayedDisable (_listPS [i].gameObject, _listPS [i].main.duration + _listPS [i].main.startLifetime.constantMax);
|
||||
else
|
||||
_listPS [i].gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LayerOrder (int amount) {
|
||||
for (int i = 0; i < _listPS.Count; i++) {
|
||||
_listPS [i].GetComponent<Renderer> ().sortingOrder += amount;
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetEnabled (){
|
||||
return _disable;
|
||||
}
|
||||
|
||||
void DelayedDisable (GameObject obj, float delay){
|
||||
float timer = 0;
|
||||
|
||||
while (timer <= delay && !_disable) {
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= delay && _disable) {
|
||||
obj.SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Trail {
|
||||
|
||||
public ParticleSystem _ps;
|
||||
public Vector3 _trailPosition;
|
||||
public Vector3 _trailEulerAngles;
|
||||
public float _trailInterval;
|
||||
public bool _emittingTrail;
|
||||
|
||||
private ParticleSystem.EmitParams emitParams;
|
||||
|
||||
//emits the trail at a certain rate/interval
|
||||
public IEnumerator EmitTrail (){
|
||||
if (_emittingTrail == false) {
|
||||
_emittingTrail = true;
|
||||
emitParams.position = _trailPosition;
|
||||
emitParams.rotation3D = -_trailEulerAngles;
|
||||
_ps.Emit (emitParams, 1);
|
||||
}
|
||||
yield return new WaitForSeconds (_trailInterval);
|
||||
_emittingTrail = false;
|
||||
}
|
||||
}
|
||||
|
||||
public class LaserScript : MonoBehaviour {
|
||||
|
||||
[Tooltip("Layers where the Lasers will collide")]
|
||||
public LayerMask layersToCollide;
|
||||
[Tooltip("If this is On, it will apply the colors in New Max Color and New Min Color.")]
|
||||
public bool changeColor;
|
||||
[Tooltip("The new Max Color. Useful to create range between colors. Leave the same as New Min Color if you want the same color.")]
|
||||
public Color newMaxColor = new Color (0,0,0,1);
|
||||
[Tooltip("The new Min Color. Useful to create range between colors. Leave the same as New Max Color if you want the same color.")]
|
||||
public Color newMinColor = new Color (0,0,0,1);
|
||||
[Tooltip("The Line Renderers that are child of this gameobject, in other words the lasers.")]
|
||||
public List<LineRenderer> lineRenderers;
|
||||
[Tooltip("The starting position of the Laser.")]
|
||||
public GameObject firePoint;
|
||||
[Tooltip("The end position of the Laser. If using an input to control the endpoint, like the mouse for example, then assign the camera.")]
|
||||
[FormerlySerializedAs("cam")]
|
||||
public GameObject endPoint;
|
||||
[Tooltip("How many times the Laser bounces when it collides.")]
|
||||
public int bounces;
|
||||
[Tooltip("Multiplies the original size of the Laser (eg: 0.5 - half the size / 2 - double the size)")]
|
||||
public float size = 1;
|
||||
[Tooltip("The maximum length the Laser will have.")]
|
||||
public float maximumLength;
|
||||
[Tooltip("How much it overgrows when the Laser is shot.")]
|
||||
[FormerlySerializedAs("growWidth")]
|
||||
public float overgrow;
|
||||
[Tooltip("The speed which the overgrow grows.")]
|
||||
[FormerlySerializedAs("growSpeed")]
|
||||
public float overgrowSpeed;
|
||||
[Tooltip("How fast it shrinks when we stop shooting.")]
|
||||
public float shrinkSpeed;
|
||||
[Tooltip("How many seconds before the Laser is disabled.")]
|
||||
public float disableDelay;
|
||||
[Tooltip("Parent of all the particles systems at the start of the Laser.")]
|
||||
public GameObject startVFX;
|
||||
[Tooltip("Enable/Disable Start VFX")]
|
||||
public bool useStart = true;
|
||||
[Tooltip("When using bounces, you can choose if you want to duplicate the Start VFX.")]
|
||||
public bool reflectStart;
|
||||
[Tooltip("Parent of all the particles systems at the middle of the Laser.")]
|
||||
[FormerlySerializedAs("psVFX")]
|
||||
public GameObject middleVFX;
|
||||
[Tooltip("Enable/Disable Middle VFX")]
|
||||
public bool useMiddle = true;
|
||||
[Tooltip("When using bounces, you can choose if you want to duplicate the Middle VFX.")]
|
||||
public bool reflectMiddle;
|
||||
[Tooltip("Parent of all the particle systems at the end of the Laser.")]
|
||||
public GameObject endVFX;
|
||||
[Tooltip("Enable/Disable End VFX")]
|
||||
public bool useEnd = true;
|
||||
[Tooltip("Enable/Disable End VFX when not colliding.")]
|
||||
public bool useEndAlways;
|
||||
[Tooltip("When using bounces, you can choose if you want to duplicate the End VFX.")]
|
||||
public bool reflectEnd;
|
||||
[Tooltip("The particle system that leaves a trail.")]
|
||||
public GameObject trailVFX;
|
||||
[Tooltip("Enable or disable trail.")]
|
||||
[FormerlySerializedAs("trail")]
|
||||
public bool useTrail;
|
||||
[Tooltip("When using bounces, you can choose if you want to duplicate the Trail.")]
|
||||
public bool reflectTrail;
|
||||
[Tooltip("The interval between each trail - 0 means a continuous trail.")]
|
||||
public float trailInterval;
|
||||
[Tooltip("Generates colliders at the end of every bounce.")]
|
||||
public bool generateColliders;
|
||||
[Tooltip("Are the colliders trigger?")]
|
||||
public bool isColliderTrigger;
|
||||
[Tooltip("The colliders radius.")]
|
||||
public float collidersRadius = 1;
|
||||
[Tooltip("Name of the Layer where the Laser is going to be.")]
|
||||
public string layerName = "Default";
|
||||
[Tooltip("Moves the Layer Order of the Line Renderers and Particle Systems to a respective value.")]
|
||||
public int layerOrderTo = 0;
|
||||
|
||||
private Camera cam;
|
||||
private Ray rayMouse;
|
||||
private List<Trail> trails = new List<Trail> ();
|
||||
private List<PSList> psList = new List<PSList> ();
|
||||
private List<float> lrWidth = new List<float> ();
|
||||
private Vector3 mouseCurrentPosition;
|
||||
private ParticleSystemController psCtrl;
|
||||
private ParticleSystem psTrailVFX;
|
||||
private bool psListFilled;
|
||||
private bool isShooting;
|
||||
private bool isColliding;
|
||||
private WaitForSeconds growWait = new WaitForSeconds (0.025f);
|
||||
private WaitForSeconds updateWait = new WaitForSeconds (0.01f);
|
||||
private PSList startPSList = new PSList();
|
||||
private PSList middlePSList = new PSList();
|
||||
private PSList endPSList = new PSList();
|
||||
private List<BoxCollider> collidersList = new List<BoxCollider>();
|
||||
|
||||
void Start () {
|
||||
|
||||
//Changes color
|
||||
psCtrl = GetComponent<ParticleSystemController>();
|
||||
if (psCtrl == null && size != 1 || changeColor) {
|
||||
gameObject.AddComponent <ParticleSystemController> ();
|
||||
psCtrl = GetComponent<ParticleSystemController>();
|
||||
}
|
||||
|
||||
if (changeColor) {
|
||||
psCtrl.changeColor = changeColor;
|
||||
psCtrl.newMaxColor = newMaxColor;
|
||||
psCtrl.newMinColor = newMinColor;
|
||||
psCtrl.ChangeColorOnly ();
|
||||
for(int i = 0; i< lineRenderers.Count; i++){
|
||||
lineRenderers [i].colorGradient = psCtrl.ChangeGradientColor (lineRenderers [i].colorGradient, psCtrl.newMaxColor, psCtrl.newMinColor);
|
||||
}
|
||||
|
||||
}
|
||||
if (size != 1) {
|
||||
Resize (false);
|
||||
}
|
||||
|
||||
//if the end point is a camera than get the componenet
|
||||
if(endPoint != null)
|
||||
cam = endPoint.GetComponent<Camera> ();
|
||||
|
||||
if (layerName != "Default") {
|
||||
var layerID = LayerMask.NameToLayer (layerName);
|
||||
if (layerID != -1) {
|
||||
gameObject.layer = layerID;
|
||||
ChangeLayerRecursively (gameObject);
|
||||
} else {
|
||||
Debug.Log ("That Layer Name doesn't exist. Watchout for a typo!");
|
||||
}
|
||||
}
|
||||
|
||||
FillLists ();
|
||||
}
|
||||
|
||||
//use this function to shoot a laser that isn't in FPS or TPS.
|
||||
public void ShootLaser (float duration){
|
||||
StartCoroutine (ShootLaserCoroutine(duration));
|
||||
}
|
||||
|
||||
IEnumerator ShootLaserCoroutine (float duration){
|
||||
yield return new WaitForSeconds (0.02f);//safe wait
|
||||
|
||||
EnableLaser ();
|
||||
|
||||
UpdateLaserContinuously ();
|
||||
|
||||
yield return new WaitForSeconds (duration);
|
||||
|
||||
DisableLaserCaller (disableDelay);
|
||||
}
|
||||
|
||||
//enables line renderers and respective particle systems of a Laser. Also adds extra width (growWidth) to each line renderer.
|
||||
public void EnableLaser (){
|
||||
|
||||
if (psList.Count > 0) {
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers [i].enabled = true;
|
||||
|
||||
for(int i = 0; i<psList.Count; i++){
|
||||
psList [i].EnablePS ();
|
||||
}
|
||||
|
||||
GrowLaserCaller ();
|
||||
RotateToMouse (middleVFX, endVFX.transform.position);
|
||||
} else {
|
||||
FillLists ();
|
||||
EnableLaser ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//after 'EnableLaser', 'UpdateLaser' is used to keep the position, normals and trail updated, according to an input or to a gameobject position.
|
||||
public void UpdateLaser () {
|
||||
if (firePoint != null) {
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers [i].SetPosition (0, firePoint.transform.position);
|
||||
|
||||
if (startVFX != null) {
|
||||
if (useStart)
|
||||
startVFX.transform.position = firePoint.transform.position;
|
||||
else
|
||||
startPSList.DisablePS (true);
|
||||
}
|
||||
|
||||
if (middleVFX != null) {
|
||||
if (useMiddle)
|
||||
middleVFX.transform.position = firePoint.transform.position;
|
||||
else
|
||||
middlePSList.DisablePS (true);
|
||||
}
|
||||
|
||||
if (endVFX != null) {
|
||||
if (!useEnd)
|
||||
endPSList.DisablePS (true);
|
||||
}
|
||||
} else {
|
||||
Debug.Log ("There is no fire point in the inspector.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (cam != null) {
|
||||
RaycastHit hit;
|
||||
var mousePos = Input.mousePosition;
|
||||
rayMouse = cam.ScreenPointToRay (mousePos);
|
||||
|
||||
if (Physics.Raycast (rayMouse, out hit, maximumLength, layersToCollide)) {
|
||||
isColliding = true;
|
||||
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers [i].SetPosition (1, hit.point);
|
||||
|
||||
if (startVFX != null && useStart)
|
||||
RotateToMouse (startVFX, hit.point);
|
||||
|
||||
if (middleVFX != null && useMiddle)
|
||||
RotateToMouse (middleVFX, hit.point);
|
||||
|
||||
if (endVFX != null) {
|
||||
endVFX.transform.position = hit.point;
|
||||
endVFX.transform.forward = -hit.normal;
|
||||
|
||||
if (generateColliders) {
|
||||
if(collidersList.Count == 0)
|
||||
GenerateCollider (endVFX);
|
||||
}
|
||||
}
|
||||
|
||||
if (trailVFX != null && useTrail) {
|
||||
if (trails [0]._emittingTrail == false) {
|
||||
trails [0]._trailPosition = hit.point;
|
||||
trails [0]._trailEulerAngles = Quaternion.LookRotation (-hit.normal).eulerAngles;
|
||||
StartCoroutine (trails [0].EmitTrail ());
|
||||
}
|
||||
}
|
||||
|
||||
if (bounces > 0)
|
||||
{
|
||||
for(int i = 0; i<lineRenderers.Count; i++)
|
||||
RecursiveBounces (lineRenderers[i], hit.point, Vector3.Reflect(rayMouse.direction, hit.normal), bounces, maximumLength - Vector3.Distance(lineRenderers[i].GetPosition(0), lineRenderers[i].GetPosition(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lineRenderers[0].positionCount > 2) {
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers[i].positionCount = 2;
|
||||
}
|
||||
|
||||
if (psList.Count > 3) {
|
||||
PSListToOriginalSize ();
|
||||
}
|
||||
}
|
||||
|
||||
//when it's not colliding against anything
|
||||
} else
|
||||
{
|
||||
isColliding = false;
|
||||
var pos = rayMouse.GetPoint (maximumLength);
|
||||
|
||||
if(startVFX!= null && useStart)
|
||||
RotateToMouse (startVFX, pos);
|
||||
|
||||
if(middleVFX!= null && useMiddle)
|
||||
RotateToMouse (middleVFX, pos);
|
||||
|
||||
if (lineRenderers[0].positionCount > 2) {
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers[i].positionCount = 2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers [i].SetPosition (1, pos);
|
||||
|
||||
if (psList.Count > 3) {
|
||||
PSListToOriginalSize ();
|
||||
}
|
||||
|
||||
if (endVFX != null) {
|
||||
if (useEnd) {
|
||||
if (useEndAlways) {
|
||||
endVFX.transform.position = pos;
|
||||
RotateToMouse (endVFX, middleVFX.transform.position);
|
||||
}else {
|
||||
endPSList.DisablePS (true);
|
||||
}
|
||||
}else {
|
||||
endPSList.DisablePS (true);
|
||||
}
|
||||
|
||||
if (generateColliders) {
|
||||
if(collidersList.Count == 0)
|
||||
GenerateCollider (endVFX);
|
||||
}
|
||||
}
|
||||
|
||||
if (trailVFX != null && useTrail) {
|
||||
for(int i = 0; i<trails.Count; i++){
|
||||
trails [i]._emittingTrail = false;
|
||||
trails [i]._ps.Stop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Used when it's not a camera
|
||||
} else
|
||||
{
|
||||
var endPointPos = endPoint.transform.position;
|
||||
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers [i].SetPosition (1, endPointPos);
|
||||
|
||||
if (startVFX != null && useStart)
|
||||
RotateToMouse (startVFX, endPointPos);
|
||||
|
||||
if (middleVFX != null && useMiddle)
|
||||
RotateToMouse (middleVFX, endPointPos);
|
||||
|
||||
if (endVFX != null) {
|
||||
endVFX.transform.position = endPointPos;
|
||||
|
||||
if (generateColliders) {
|
||||
if(collidersList.Count == 0)
|
||||
GenerateCollider (endVFX);
|
||||
}
|
||||
}
|
||||
|
||||
if (trailVFX != null && useTrail) {
|
||||
if (trails [0]._emittingTrail == false) {
|
||||
trails [0]._trailPosition = endPointPos;
|
||||
trails [0]._trailEulerAngles = endVFX.transform.eulerAngles;
|
||||
StartCoroutine (trails [0].EmitTrail ());
|
||||
}
|
||||
}
|
||||
|
||||
if (bounces > 0)
|
||||
{
|
||||
RaycastHit hit;
|
||||
var direction = endPointPos - firePoint.transform.position;
|
||||
Ray ray = new Ray (firePoint.transform.position, direction);
|
||||
if(Physics.Raycast (ray, out hit)){
|
||||
for(int i = 0; i<lineRenderers.Count; i++)
|
||||
RecursiveBounces (lineRenderers[i], endPointPos, Vector3.Reflect(ray.direction, hit.normal), bounces, maximumLength - Vector3.Distance(lineRenderers[i].GetPosition(0), lineRenderers[i].GetPosition(1)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lineRenderers[0].positionCount > 2) {
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers[i].positionCount = 2;
|
||||
}
|
||||
|
||||
if (psList.Count > 3) {
|
||||
PSListToOriginalSize ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RecursiveBounces (LineRenderer lr, Vector3 position, Vector3 direction, int bouncesRemaining, float lengthRemaining){
|
||||
if (bouncesRemaining == 0)
|
||||
return;
|
||||
if (lengthRemaining <= 0.1f)
|
||||
return;
|
||||
|
||||
int index = bounces - bouncesRemaining;
|
||||
|
||||
if (lr.positionCount == index+2){
|
||||
lr.positionCount ++;
|
||||
}
|
||||
|
||||
Ray ray = new Ray (position, direction);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast (ray, out hit, lengthRemaining)) {
|
||||
direction = Vector3.Reflect (direction, hit.normal);
|
||||
lr.SetPosition(index+2, hit.point);
|
||||
|
||||
if (startVFX != null && useStart && reflectStart) {
|
||||
if (GetByType (PSList.PSLIST_TYPE.start).Count == index + 1)
|
||||
CreateNewPSList (PSList.PSLIST_TYPE.start);
|
||||
|
||||
List<PSList> startListPS = GetByType(PSList.PSLIST_TYPE.start);
|
||||
if (startListPS.Count > index) {
|
||||
startListPS[index + 1]._parent.transform.position = position;
|
||||
RotateToMouse (startListPS[index + 1]._parent, hit.point);
|
||||
}
|
||||
}
|
||||
|
||||
if (middleVFX != null && useMiddle && reflectMiddle) {
|
||||
if (GetByType(PSList.PSLIST_TYPE.middle).Count == index + 1)
|
||||
CreateNewPSList (PSList.PSLIST_TYPE.middle);
|
||||
|
||||
List<PSList> middleListPS = GetByType(PSList.PSLIST_TYPE.middle);
|
||||
if (middleListPS.Count > index) {
|
||||
middleListPS[index + 1]._parent.transform.position = position;
|
||||
RotateToMouse (middleListPS[index + 1]._parent, hit.point);
|
||||
}
|
||||
}
|
||||
|
||||
if (endVFX != null && useEnd) {
|
||||
if (reflectEnd) {
|
||||
if (GetByType (PSList.PSLIST_TYPE.end).Count == index + 1)
|
||||
CreateNewPSList (PSList.PSLIST_TYPE.end);
|
||||
|
||||
List<PSList> endListPS = GetByType (PSList.PSLIST_TYPE.end);
|
||||
if (endListPS.Count > index) {
|
||||
endListPS [index + 1]._parent.transform.position = hit.point;
|
||||
endListPS [index + 1]._parent.transform.forward = -hit.normal;
|
||||
}
|
||||
} else {
|
||||
endVFX.transform.position = hit.point;
|
||||
endVFX.transform.forward = -hit.normal;
|
||||
}
|
||||
}
|
||||
|
||||
if (trailVFX != null && useTrail && reflectTrail) {
|
||||
if (trails.Count == index + 1) {
|
||||
Trail newTrail = new Trail (){_ps = psTrailVFX, _trailInterval = trailInterval};
|
||||
trails.Add (newTrail);
|
||||
}
|
||||
|
||||
if (trails [index+1]._emittingTrail == false) {
|
||||
trails [index+1]._trailPosition = hit.point;
|
||||
trails [index+1]._trailEulerAngles = Quaternion.LookRotation (-hit.normal).eulerAngles;
|
||||
StartCoroutine (trails [index+1].EmitTrail ());
|
||||
}
|
||||
}
|
||||
|
||||
if(!useEnd || !reflectEnd && generateColliders){
|
||||
if(collidersList.Count == index + 1){
|
||||
Debug.Log ("NewColliderAdded");
|
||||
GameObject gObj = new GameObject ("NewCollider");
|
||||
gObj.transform.SetParent (transform);
|
||||
gObj.transform.position = hit.point;
|
||||
gObj.transform.forward = -hit.normal;
|
||||
GenerateCollider (gObj);
|
||||
}
|
||||
|
||||
if (collidersList.Count > index) {
|
||||
var coObj = collidersList [index + 1].gameObject;
|
||||
coObj.transform.position = hit.point;
|
||||
coObj.transform.forward = -hit.normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (lr.positionCount > index+3) {
|
||||
lr.positionCount--;
|
||||
}
|
||||
if (lengthRemaining > 0.1f) {
|
||||
var pos = ray.GetPoint (lengthRemaining);
|
||||
|
||||
lr.SetPosition (index + 2, pos);
|
||||
|
||||
if (startVFX != null && useStart && reflectStart) {
|
||||
if (GetByType (PSList.PSLIST_TYPE.start).Count == index + 1)
|
||||
CreateNewPSList (PSList.PSLIST_TYPE.start);
|
||||
|
||||
List<PSList> startListPS = GetByType(PSList.PSLIST_TYPE.start);
|
||||
if (startListPS.Count > index) {
|
||||
startListPS[index + 1]._parent.transform.position = position;
|
||||
RotateToMouse (startListPS[index + 1]._parent, pos);
|
||||
}
|
||||
|
||||
if (startListPS.Count > index + 2) {
|
||||
RemoveLastByType (PSList.PSLIST_TYPE.start);
|
||||
}
|
||||
}
|
||||
|
||||
if (middleVFX != null && useMiddle && reflectMiddle) {
|
||||
if (GetByType(PSList.PSLIST_TYPE.middle).Count == index + 1)
|
||||
CreateNewPSList (PSList.PSLIST_TYPE.middle);
|
||||
|
||||
List<PSList> middleListPS = GetByType(PSList.PSLIST_TYPE.middle);
|
||||
if (middleListPS.Count > index) {
|
||||
middleListPS[index + 1]._parent.transform.position = position;
|
||||
RotateToMouse (middleListPS[index + 1]._parent, pos);
|
||||
}
|
||||
|
||||
if (middleListPS.Count > index + 2) {
|
||||
RemoveLastByType (PSList.PSLIST_TYPE.middle);
|
||||
}
|
||||
}
|
||||
|
||||
if (endVFX != null && useEnd) {
|
||||
if (reflectEnd){
|
||||
if (useEndAlways) {
|
||||
if (GetByType (PSList.PSLIST_TYPE.end).Count == index + 1)
|
||||
CreateNewPSList (PSList.PSLIST_TYPE.end);
|
||||
|
||||
List<PSList> endListPS = GetByType (PSList.PSLIST_TYPE.end);
|
||||
if (endListPS.Count > index) {
|
||||
endListPS [index + 1]._parent.transform.position = pos;
|
||||
RotateToMouse (endListPS [index + 1]._parent, ray.origin);
|
||||
}
|
||||
|
||||
if (endListPS.Count > index + 2) {
|
||||
RemoveLastByType (PSList.PSLIST_TYPE.end);
|
||||
}
|
||||
} else {
|
||||
List<PSList> endListPS = GetByType (PSList.PSLIST_TYPE.end);
|
||||
if (endListPS.Count > index + 1) {
|
||||
endListPS [index + 1].DisablePS (false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
endVFX.transform.position = pos;
|
||||
RotateToMouse (endVFX, ray.origin);
|
||||
}
|
||||
}
|
||||
|
||||
if (trailVFX != null && useTrail) {
|
||||
for(int i = index+1; i<trails.Count; i++){
|
||||
trails [i]._emittingTrail = false;
|
||||
trails [i]._ps.Stop ();
|
||||
}
|
||||
}
|
||||
|
||||
if(!useEnd || !reflectEnd && generateColliders){
|
||||
if(collidersList.Count == index + 1){
|
||||
Debug.Log ("NewColliderAdded");
|
||||
GameObject gObj = new GameObject ("NewCollider");
|
||||
gObj.transform.SetParent (transform);
|
||||
gObj.transform.position = pos;
|
||||
RotateToMouse (gObj, ray.origin);
|
||||
GenerateCollider (gObj);
|
||||
}
|
||||
|
||||
if (collidersList.Count > index) {
|
||||
var coObj = collidersList [index + 1].gameObject;
|
||||
coObj.transform.position = pos;
|
||||
RotateToMouse (coObj, ray.origin);
|
||||
}
|
||||
|
||||
if (collidersList.Count > index + 2) {
|
||||
Debug.Log ("Removing Collider from List. Left: " + collidersList.Count);
|
||||
RemoveLastCollider (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bouncesRemaining--;
|
||||
lengthRemaining -= Vector3.Distance (lr.GetPosition(index+1), lr.GetPosition(index+2));
|
||||
RecursiveBounces (lr, hit.point, Vector3.Reflect(ray.direction, hit.normal), bouncesRemaining, lengthRemaining);
|
||||
}
|
||||
|
||||
//useful for when not using any input to trigger the Laser (See AutomatedTargets_Scene)
|
||||
void UpdateLaserContinuously (){
|
||||
StartCoroutine (UpdateLaserCoroutine());
|
||||
}
|
||||
|
||||
IEnumerator UpdateLaserCoroutine (){
|
||||
while (isShooting) {
|
||||
UpdateLaser ();
|
||||
yield return updateWait;
|
||||
}
|
||||
}
|
||||
|
||||
//function to iterate trhough the line renderers and make them grow in the begging
|
||||
void GrowLaserCaller () {
|
||||
isShooting = true;
|
||||
if (gameObject.activeSelf) {
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
StartCoroutine (GrowLaser (lineRenderers [i], lrWidth [i]));
|
||||
} else {
|
||||
gameObject.SetActive (true);
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
StartCoroutine (GrowLaser (lineRenderers [i], lrWidth [i]));
|
||||
}
|
||||
}
|
||||
|
||||
//coroutine used to give some extra width in the beginning
|
||||
IEnumerator GrowLaser (LineRenderer lr, float originalWidth){
|
||||
while (isShooting && lr.widthMultiplier < (originalWidth + overgrow)-0.001f) {
|
||||
if (lr.widthMultiplier + overgrowSpeed > originalWidth + overgrow) {
|
||||
lr.widthMultiplier = originalWidth + overgrow;
|
||||
lr.widthMultiplier = (float)System.Math.Round (lr.widthMultiplier, 2);
|
||||
} else {
|
||||
lr.widthMultiplier += overgrowSpeed;
|
||||
lr.widthMultiplier = (float)System.Math.Round (lr.widthMultiplier, 2);
|
||||
}
|
||||
yield return growWait;
|
||||
}
|
||||
yield return growWait;
|
||||
while (isShooting && lr.widthMultiplier > originalWidth) {
|
||||
if (lr.widthMultiplier - overgrowSpeed < originalWidth)
|
||||
lr.widthMultiplier = originalWidth;
|
||||
else
|
||||
lr.widthMultiplier -= overgrowSpeed/2;
|
||||
yield return growWait;
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableLaserCaller (float timer){
|
||||
if(gameObject.activeSelf)
|
||||
StartCoroutine (DisableLaser(timer));
|
||||
}
|
||||
|
||||
IEnumerator DisableLaser (float timer){
|
||||
isShooting = false;
|
||||
isColliding = false;
|
||||
ShrinkLaserCaller ();
|
||||
HoldLaserCaller ();
|
||||
|
||||
for(int i = 0; i<psList.Count; i++){
|
||||
psList [i].DisablePS (false);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds (timer);
|
||||
if (isShooting == false) {
|
||||
isShooting = true;
|
||||
for (int i = 0; i < lineRenderers.Count; i++)
|
||||
lineRenderers[i].enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//shrink each line renderer
|
||||
void ShrinkLaserCaller () {
|
||||
for(int i = 0; i< lineRenderers.Count; i++)
|
||||
StartCoroutine (ShrinkLaser(lineRenderers[i]));
|
||||
}
|
||||
|
||||
IEnumerator ShrinkLaser (LineRenderer lr){
|
||||
while (!isShooting && lr.widthMultiplier > 0) {
|
||||
var amount = lr.widthMultiplier -= shrinkSpeed;
|
||||
if(amount < 0)
|
||||
lr.widthMultiplier = 0;
|
||||
else
|
||||
lr.widthMultiplier = amount;
|
||||
yield return growWait;
|
||||
}
|
||||
}
|
||||
|
||||
//update the laser while shrinking
|
||||
void HoldLaserCaller (){
|
||||
StartCoroutine (HoldLaser ());
|
||||
}
|
||||
|
||||
IEnumerator HoldLaser () {
|
||||
while (!isShooting){
|
||||
UpdateLaser ();
|
||||
yield return updateWait;
|
||||
}
|
||||
}
|
||||
|
||||
//auxiliary function to rotate a gameobject to a destination
|
||||
void RotateToMouse (GameObject obj, Vector3 destination ) {
|
||||
var direction = destination - obj.transform.position;
|
||||
Quaternion rotation = Quaternion.LookRotation (direction);
|
||||
obj.transform.rotation = Quaternion.Lerp (obj.transform.rotation, rotation, 1);
|
||||
}
|
||||
|
||||
//one time function that fills the line renderers width list; the start particle system list and adds to the psList;
|
||||
//the middle particle system list and adds to the psList; the end particle system list and adds to the psList; creates 1st trail and adds to the trails list
|
||||
void FillLists () {
|
||||
if (!psListFilled) {
|
||||
psListFilled = true;
|
||||
|
||||
//adds the width of the lasers to a list and sets the width to 0
|
||||
if(lineRenderers.Count > 0){
|
||||
if(lrWidth.Count == 0){
|
||||
for (int i = 0; i < lineRenderers.Count; i++) {
|
||||
lrWidth.Add(lineRenderers[i].widthMultiplier*size);
|
||||
lineRenderers [i].widthMultiplier = 0;
|
||||
lineRenderers [i].enabled = false;
|
||||
if(layerOrderTo != 0)
|
||||
lineRenderers [i].sortingOrder += layerOrderTo;
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
Debug.Log("Line Renderers list is empty.");
|
||||
}
|
||||
|
||||
if (startVFX != null) {
|
||||
startPSList._parent = startVFX;
|
||||
startPSList._psType = PSList.PSLIST_TYPE.start;
|
||||
startPSList.AddPSToList (startVFX, true);
|
||||
startPSList.DisablePS (true);
|
||||
if(layerOrderTo != 0)
|
||||
startPSList.LayerOrder (layerOrderTo);
|
||||
psList.Add (startPSList);
|
||||
}
|
||||
|
||||
if (middleVFX != null) {
|
||||
middlePSList._parent = middleVFX;
|
||||
middlePSList._psType = PSList.PSLIST_TYPE.middle;
|
||||
middlePSList.AddPSToList (middleVFX, true);
|
||||
middlePSList.DisablePS (true);
|
||||
if(layerOrderTo != 0)
|
||||
middlePSList.LayerOrder (layerOrderTo);
|
||||
psList.Add (middlePSList);
|
||||
}
|
||||
|
||||
if (endVFX != null) {
|
||||
endPSList._parent = endVFX;
|
||||
endPSList._psType = PSList.PSLIST_TYPE.end;
|
||||
endPSList.AddPSToList (endVFX, true);
|
||||
endPSList.DisablePS (true);
|
||||
if(layerOrderTo != 0)
|
||||
endPSList.LayerOrder (layerOrderTo);
|
||||
psList.Add (endPSList);
|
||||
}
|
||||
|
||||
if (trailVFX != null && useTrail) {
|
||||
psTrailVFX = trailVFX.GetComponent<ParticleSystem> ();
|
||||
if(layerName != "Default" || layerOrderTo != 0){
|
||||
var trailRenderer = psTrailVFX.GetComponent<Renderer>();
|
||||
trailRenderer.sortingOrder += layerOrderTo;
|
||||
}
|
||||
Trail newTrail = new Trail (){_ps = psTrailVFX, _trailInterval = trailInterval};
|
||||
trails.Add (newTrail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//duplicate a list of particle systems. Useful for when bounces is higher then 0
|
||||
void CreateNewPSList (PSList.PSLIST_TYPE psListType){
|
||||
string[] psListTypeNames = System.Enum.GetNames (typeof(PSList.PSLIST_TYPE));
|
||||
for (int i = 0; i < psListTypeNames.Length; i++) {
|
||||
if (psListTypeNames[i] == psListType.ToString()) {
|
||||
for(int j = 0; j < psList.Count; j++){
|
||||
if(psList[j]._psType == psListType){
|
||||
GameObject newParent = Instantiate (psList[j]._parent) as GameObject;
|
||||
newParent.transform.SetParent (psList[j]._parent.transform.parent);
|
||||
PSList newPSList = new PSList () {_parent = newParent };
|
||||
newPSList._psType = psListType;
|
||||
newPSList.AddPSToList (newPSList._parent, true);
|
||||
newPSList.EnablePS ();
|
||||
psList.Add (newPSList);
|
||||
if (newParent.transform.Find ("Collider") == true) {
|
||||
var boxCo = newParent.transform.Find ("Collider").GetComponent<BoxCollider> ();
|
||||
collidersList.Add (boxCo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<PSList> GetByType (PSList.PSLIST_TYPE type){
|
||||
List<PSList> types = new List<PSList> ();
|
||||
for (int i = 0; i < psList.Count; i++) {
|
||||
if (psList [i]._psType == type) {
|
||||
types.Add (psList [i]);
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
public void PSListToOriginalSize (){
|
||||
for (int i = 3; i < psList.Count; i++) {
|
||||
psList [i].DisablePS (false);
|
||||
GameObject newObj = psList[i]._parent;
|
||||
if (psList [i]._psType == PSList.PSLIST_TYPE.end) {
|
||||
if (newObj.transform.Find ("Collider") == true)
|
||||
RemoveLastCollider (false);
|
||||
}
|
||||
psList.RemoveAt (i);
|
||||
Destroy (newObj);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveLastByType (PSList.PSLIST_TYPE type){
|
||||
for (int i = psList.Count-1; i > 0; i--) {
|
||||
if (psList [i]._psType == type) {
|
||||
psList [i].DisablePS (false);
|
||||
GameObject newObj = psList[i]._parent;
|
||||
psList.RemoveAt (i);
|
||||
if (type == PSList.PSLIST_TYPE.end) {
|
||||
if (newObj.transform.Find ("Collider") == true)
|
||||
RemoveLastCollider (false);
|
||||
}
|
||||
Destroy (newObj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveLastPositionLRs (){
|
||||
for (int i = 0; i < lineRenderers.Count; i++) {
|
||||
lineRenderers [i].positionCount--;
|
||||
}
|
||||
}
|
||||
|
||||
public void StopLastTrail (){
|
||||
if (trailVFX != null && useTrail) {
|
||||
for(int i = trails.Count-1; i > 0; i--){
|
||||
trails [i]._emittingTrail = false;
|
||||
trails [i]._ps.Stop ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize (bool live){
|
||||
|
||||
if (psCtrl == null) {
|
||||
gameObject.AddComponent <ParticleSystemController> ();
|
||||
psCtrl = GetComponent<ParticleSystemController>();
|
||||
}
|
||||
|
||||
if(live){
|
||||
if(lineRenderers.Count > 0){
|
||||
for (int i = 0; i < lineRenderers.Count; i++) {
|
||||
lrWidth[i] *= size;
|
||||
lrWidth [i] = (float)System.Math.Round (lrWidth [i], 2);
|
||||
}
|
||||
}
|
||||
overgrow *= size;
|
||||
overgrow = (float)System.Math.Round (overgrow, 2);
|
||||
}
|
||||
|
||||
size = (float)System.Math.Round (size,2);
|
||||
psCtrl.size = size;
|
||||
psCtrl.ResizeOnly ();
|
||||
}
|
||||
|
||||
public bool GetCollisionStatus (){
|
||||
return isColliding;
|
||||
}
|
||||
|
||||
public List<BoxCollider> GetCollidersList (){
|
||||
return collidersList;
|
||||
}
|
||||
|
||||
public List<Vector3> GetCollidersPosition (bool localPosition){
|
||||
List<Vector3> collidersPos = new List<Vector3> ();
|
||||
|
||||
for(int i = 0; i<collidersList.Count; i++){
|
||||
if (localPosition)
|
||||
collidersPos.Add (collidersList [i].gameObject.transform.localPosition);
|
||||
else
|
||||
collidersPos.Add (collidersList [i].gameObject.transform.position);
|
||||
}
|
||||
|
||||
return collidersPos;
|
||||
}
|
||||
|
||||
void GenerateCollider (GameObject obj){
|
||||
if (obj.transform.Find ("Collider") == null) {
|
||||
var colliderObj = new GameObject ("Collider");
|
||||
colliderObj.transform.SetParent (obj.transform);
|
||||
colliderObj.transform.localPosition = Vector3.zero;
|
||||
colliderObj.layer = 2; //ignore raycast layer
|
||||
var boxCo = colliderObj.gameObject.AddComponent<BoxCollider> ();
|
||||
boxCo.isTrigger = isColliderTrigger;
|
||||
boxCo.size = new Vector3 (collidersRadius,collidersRadius,collidersRadius);
|
||||
collidersList.Add (boxCo);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveLastCollider ( bool removeObject){
|
||||
for (int i = collidersList.Count-1; i > 0; i--) {
|
||||
if (removeObject) {
|
||||
GameObject newObj = collidersList [i].transform.parent.gameObject;
|
||||
Destroy (newObj);
|
||||
}
|
||||
collidersList.RemoveAt (i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeLayerRecursively (GameObject obj) {
|
||||
foreach (Transform t in obj.transform){
|
||||
t.gameObject.layer = LayerMask.NameToLayer (layerName);
|
||||
if (t.childCount > 0)
|
||||
ChangeLayerRecursively (t.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a4618906ae6ee94e864023d169209d3
|
||||
timeCreated: 1519129049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,177 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using GAP_LaserSystem;
|
||||
|
||||
public class SwitchLasersScript : MonoBehaviour {
|
||||
|
||||
public Text effectName;
|
||||
public Text bouncesText;
|
||||
public Text sizeText;
|
||||
public GameObject fixedCamera;
|
||||
public GameObject fpsCamera;
|
||||
public List<GameObject> Lasers = new List<GameObject> ();
|
||||
|
||||
private int count = 0;
|
||||
private float newSize = 1;
|
||||
private float originalSize;
|
||||
private GameObject activeLaser;
|
||||
private LaserScript laserScript;
|
||||
|
||||
void Start () {
|
||||
activeLaser = Lasers [0];
|
||||
laserScript = activeLaser.GetComponent<LaserScript> ();
|
||||
|
||||
if (effectName != null) effectName.text = activeLaser.name;
|
||||
if (bouncesText != null) bouncesText.text = "Bounces: " + laserScript.bounces;
|
||||
if (sizeText != null) sizeText.text = "Size: " + newSize;
|
||||
originalSize = laserScript.size;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
|
||||
//enable the laser once we press mouse 1
|
||||
if (Input.GetMouseButtonDown (0)) {
|
||||
laserScript.EnableLaser ();
|
||||
activeLaser.SetActive (true);
|
||||
|
||||
//hides and locks the mouse to the center, if its a FPS Camera
|
||||
if (fpsCamera != null) {
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
//holding Mouse 1 to keep the laser firing
|
||||
if (Input.GetMouseButton (0)) {
|
||||
laserScript.UpdateLaser ();
|
||||
}
|
||||
|
||||
//once we stop shooting we disable laser. With or without a delay
|
||||
if(Input.GetMouseButtonUp (0)){
|
||||
laserScript.DisableLaserCaller (laserScript.disableDelay);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.E))
|
||||
Next ();
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.Q))
|
||||
Previous ();
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.C) && fixedCamera != null && fpsCamera != null) {
|
||||
ChangeCamera ();
|
||||
RefreshLaser ();
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown (KeyCode.R)){
|
||||
laserScript.bounces++;
|
||||
if (bouncesText != null) bouncesText.text = "Bounces: " + laserScript.bounces;
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown (KeyCode.F)){
|
||||
if (laserScript.bounces > 0) {
|
||||
laserScript.bounces--;
|
||||
laserScript.RemoveLastByType (PSList.PSLIST_TYPE.start);
|
||||
laserScript.RemoveLastByType (PSList.PSLIST_TYPE.middle);
|
||||
laserScript.RemoveLastByType (PSList.PSLIST_TYPE.end);
|
||||
laserScript.RemoveLastPositionLRs ();
|
||||
laserScript.StopLastTrail ();
|
||||
}
|
||||
if (bouncesText != null) bouncesText.text = "Bounces: " + laserScript.bounces;
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown (KeyCode.X)){
|
||||
OriginalSize ();
|
||||
newSize += 0.1f;
|
||||
newSize = (float)System.Math.Round (newSize,2);
|
||||
laserScript.size = newSize;
|
||||
laserScript.Resize (true);
|
||||
if (sizeText != null) sizeText.text = "Size: " + newSize;
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown (KeyCode.Z)){
|
||||
if (newSize > 0.1f) {
|
||||
OriginalSize ();
|
||||
newSize -= 0.1f;
|
||||
newSize = (float)System.Math.Round (newSize,2);
|
||||
laserScript.size = newSize;
|
||||
laserScript.Resize (true);
|
||||
}
|
||||
if (sizeText != null) sizeText.text = "Size: " + newSize;
|
||||
}
|
||||
}
|
||||
|
||||
void OriginalSize (){
|
||||
laserScript.size = 1 / newSize;
|
||||
laserScript.Resize (true);
|
||||
}
|
||||
|
||||
public void Next () {
|
||||
count++;
|
||||
|
||||
if (count > Lasers.Count)
|
||||
count = 0;
|
||||
|
||||
for(int i = 0; i < Lasers.Count; i++){
|
||||
if (count == i) {
|
||||
laserScript.DisableLaserCaller (0);
|
||||
activeLaser = Lasers [i];
|
||||
activeLaser.SetActive (false);
|
||||
laserScript = activeLaser.GetComponent<LaserScript> ();
|
||||
newSize = 1;
|
||||
}
|
||||
if (effectName != null) effectName.text = activeLaser.name;
|
||||
if (bouncesText != null) bouncesText.text = "Bounces: " + laserScript.bounces;
|
||||
if (sizeText != null) sizeText.text = "Size: " + laserScript.size;
|
||||
}
|
||||
}
|
||||
|
||||
public void Previous () {
|
||||
count--;
|
||||
|
||||
if (count < 0)
|
||||
count = Lasers.Count;
|
||||
|
||||
for(int i = 0; i < Lasers.Count; i++){
|
||||
if (count == i) {
|
||||
laserScript.DisableLaserCaller (0);
|
||||
activeLaser = Lasers [i];
|
||||
activeLaser.SetActive (false);
|
||||
laserScript = activeLaser.GetComponent<LaserScript> ();
|
||||
newSize = 1;
|
||||
}
|
||||
if (effectName != null) effectName.text = activeLaser.name;
|
||||
if (bouncesText != null) bouncesText.text = "Bounces: " + laserScript.bounces;
|
||||
if (sizeText != null) sizeText.text = "Size: " + laserScript.size;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeCamera () {
|
||||
if (!fixedCamera.activeSelf) {
|
||||
fixedCamera.SetActive (true);
|
||||
fpsCamera.SetActive (false);
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
} else {
|
||||
fixedCamera.SetActive (false);
|
||||
fpsCamera.SetActive (true);
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshLaser (){
|
||||
for(int i = 0; i < Lasers.Count; i++){
|
||||
laserScript = Lasers[i].GetComponent<LaserScript> ();
|
||||
if (fixedCamera.gameObject.activeSelf) {
|
||||
laserScript.firePoint = Lasers [i];
|
||||
laserScript.endPoint = fixedCamera;
|
||||
}
|
||||
else{
|
||||
laserScript.firePoint = fpsCamera.transform.FindDeepChild("FirePoint").gameObject;
|
||||
laserScript.endPoint = fpsCamera;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e7aacca4ca2783439d3a8285035dcd3
|
||||
timeCreated: 1526652285
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
|
||||
public static class TransformDeepChildExtension
|
||||
{
|
||||
//Breadth-first search
|
||||
public static Transform FindDeepChild(this Transform aParent, string aName)
|
||||
{
|
||||
var result = aParent.Find(aName);
|
||||
if (result != null)
|
||||
return result;
|
||||
foreach(Transform child in aParent)
|
||||
{
|
||||
result = child.FindDeepChild(aName);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
//Depth-first search
|
||||
public static Transform FindDeepChild(this Transform aParent, string aName)
|
||||
{
|
||||
foreach(Transform child in aParent)
|
||||
{
|
||||
if(child.name == aName )
|
||||
return child;
|
||||
var result = child.FindDeepChild(aName);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae5eff85a164fc2458fccfe69c228a63
|
||||
timeCreated: 1528990289
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe5555de2540e1840b5776644d15ca75
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpawnCometsScript : MonoBehaviour {
|
||||
|
||||
public GameObject comet;
|
||||
public GameObject startPoint;
|
||||
public GameObject endPoint;
|
||||
public float delay;
|
||||
public float rateOfFire;
|
||||
public float radius;
|
||||
public float quantity;
|
||||
public float waves;
|
||||
|
||||
void Start () {
|
||||
StartCoroutine (SpawnVFX(comet, delay, rateOfFire));
|
||||
}
|
||||
|
||||
IEnumerator SpawnVFX (GameObject vfx, float delay, float rateDelay){
|
||||
for (int j = 0; j < waves; j++) {
|
||||
yield return new WaitForSeconds (delay);
|
||||
for (int i = 0; i < quantity; i++) {
|
||||
var startPos = startPoint.transform.position;
|
||||
if(radius != 0)
|
||||
startPos = new Vector3 (startPoint.transform.position.x + Random.Range (-radius, radius), startPoint.transform.position.y + Random.Range (-radius, radius), startPoint.transform.position.z + Random.Range (-radius, radius));
|
||||
GameObject objVFX = Instantiate (vfx, startPos, Quaternion.identity) as GameObject;
|
||||
|
||||
var endPos = endPoint.transform.position;
|
||||
if(radius != 0)
|
||||
endPos = new Vector3 (endPoint.transform.position.x + Random.Range (-radius, radius), endPoint.transform.position.y + Random.Range (-radius, radius), endPoint.transform.position.z + Random.Range (-radius, radius));
|
||||
RotateTo (objVFX, endPos);
|
||||
|
||||
yield return new WaitForSeconds (rateDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RotateTo (GameObject obj, Vector3 destination ) {
|
||||
var direction = destination - obj.transform.position;
|
||||
var rotation = Quaternion.LookRotation (direction);
|
||||
obj.transform.localRotation = Quaternion.Lerp (obj.transform.rotation, rotation, 1);
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cccff02035c20b44fb86ac5d9d7a74ea
|
||||
timeCreated: 1540304110
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpawnMagicAbilityScript : MonoBehaviour {
|
||||
|
||||
[System.Serializable]
|
||||
public class ShakeParameters {
|
||||
public bool shake;
|
||||
public List<float> delays = new List<float>();
|
||||
}
|
||||
|
||||
public Text effectName;
|
||||
public GameObject cameras;
|
||||
public List<GameObject> VFXs = new List<GameObject> ();
|
||||
public List<ShakeParameters> VFXsShakeParameters = new List<ShakeParameters> ();
|
||||
|
||||
private int count = 0;
|
||||
private GameObject effectToSpawn;
|
||||
private ShakeParameters effectShakeParameters;
|
||||
private List<Camera> camerasList = new List<Camera> ();
|
||||
private Camera singleCamera;
|
||||
private List<GameObject> spawnedVFX = new List<GameObject>();
|
||||
|
||||
void Start () {
|
||||
|
||||
if (cameras.transform.childCount > 0) {
|
||||
for (int i = 0; i < cameras.transform.childCount; i++) {
|
||||
camerasList.Add (cameras.transform.GetChild (i).gameObject.GetComponent<Camera> ());
|
||||
}
|
||||
if(camerasList.Count == 0){
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
}
|
||||
} else {
|
||||
singleCamera = cameras.GetComponent<Camera> ();
|
||||
if (singleCamera != null)
|
||||
camerasList.Add (singleCamera);
|
||||
else
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
}
|
||||
|
||||
if (VFXs.Count > 0)
|
||||
effectToSpawn = VFXs [0];
|
||||
else
|
||||
Debug.Log ("No Effects added to the VFXs List");
|
||||
|
||||
if(VFXsShakeParameters.Count > 0)
|
||||
effectShakeParameters = VFXsShakeParameters [0];
|
||||
else
|
||||
Debug.Log ("No Delays added to the ShakeDelays List");
|
||||
|
||||
if (effectName != null)
|
||||
effectName.text = effectToSpawn.name;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0) )
|
||||
SpawnVFX ();
|
||||
if (Input.GetKeyDown (KeyCode.D))
|
||||
Next ();
|
||||
if (Input.GetKeyDown (KeyCode.A))
|
||||
Previous ();
|
||||
if (Input.GetKeyDown (KeyCode.C))
|
||||
SwitchCamera ();
|
||||
if (Input.GetKeyDown (KeyCode.X))
|
||||
ZoomIn ();
|
||||
if (Input.GetKeyDown (KeyCode.Z))
|
||||
ZoomOut ();
|
||||
}
|
||||
|
||||
public void SpawnVFX () {
|
||||
if (effectShakeParameters.shake && cameras != null)
|
||||
StartCoroutine (ShakeDelay (effectShakeParameters.delays));
|
||||
|
||||
GameObject vfxSpawned = Instantiate(effectToSpawn);
|
||||
spawnedVFX.Add(vfxSpawned);
|
||||
|
||||
var ps = GetFirstPS (vfxSpawned);
|
||||
}
|
||||
|
||||
public void Next () {
|
||||
count++;
|
||||
|
||||
CleanSpawnedVFXList();
|
||||
|
||||
if (count >= VFXs.Count)
|
||||
count = 0;
|
||||
|
||||
for (int i = 0; i < VFXs.Count; i++){
|
||||
if (count == i) {
|
||||
effectToSpawn = VFXs [i];
|
||||
effectShakeParameters = VFXsShakeParameters [i];
|
||||
}
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void Previous () {
|
||||
count--;
|
||||
|
||||
CleanSpawnedVFXList();
|
||||
|
||||
if (count < 0)
|
||||
count = VFXs.Count-1;
|
||||
|
||||
for (int i = 0; i < VFXs.Count; i++) {
|
||||
if (count == i) {
|
||||
effectToSpawn = VFXs [i];
|
||||
effectShakeParameters = VFXsShakeParameters [i];
|
||||
}
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void ZoomIn () {
|
||||
if (camerasList.Count > 0) {
|
||||
if (!camerasList [0].orthographic) {
|
||||
if (camerasList [0].fieldOfView < 101) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].fieldOfView += 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (camerasList [0].orthographicSize < 10) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].orthographicSize += 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ZoomOut () {
|
||||
if (camerasList.Count > 0) {
|
||||
if (!camerasList [0].orthographic) {
|
||||
if (camerasList [0].fieldOfView > 20) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].fieldOfView -= 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (camerasList [0].orthographicSize > 4) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].orthographicSize -= 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchCamera () {
|
||||
if (camerasList.Count > 0) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
if (camerasList [i].gameObject.activeSelf) {
|
||||
camerasList [i].gameObject.SetActive (false);
|
||||
if ((i + 1) == camerasList.Count) {
|
||||
camerasList [0].gameObject.SetActive (true);
|
||||
break;
|
||||
} else {
|
||||
camerasList [i + 1].gameObject.SetActive (true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleSystem GetFirstPS (GameObject vfx){
|
||||
var ps = vfx.GetComponent<ParticleSystem> ();
|
||||
if (ps == null && vfx.transform.childCount > 0) {
|
||||
foreach (Transform t in vfx.transform) {
|
||||
ps = t.GetComponent<ParticleSystem> ();
|
||||
if(ps != null)
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
return ps;
|
||||
}
|
||||
|
||||
IEnumerator ShakeDelay (List<float> delay){
|
||||
for (int i = 0; i < delay.Count; i++) {
|
||||
yield return new WaitForSeconds (delay[i]);
|
||||
cameras.GetComponent<CameraShakeSimpleScript> ().ShakeCamera ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CleanSpawnedVFXList()
|
||||
{
|
||||
for (int i = 0; i < spawnedVFX.Count; i++)
|
||||
{
|
||||
Destroy(spawnedVFX[i]);
|
||||
}
|
||||
|
||||
spawnedVFX.Clear();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3042ba99f833e4942b7c9fab4deeb028
|
||||
timeCreated: 1541952525
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e7923019f7f3564fafb70ac0468df70
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
//NOTES:
|
||||
//This script is used for DEMONSTRATION porpuses of the Projectiles. I recommend everyone to create their own code for their own projects.
|
||||
//This is just a basic example.
|
||||
//
|
||||
|
||||
#pragma warning disable 0168 // variable declared but not used.
|
||||
#pragma warning disable 0219 // variable assigned but not used.
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraShakeSimpleScript : MonoBehaviour {
|
||||
|
||||
private bool isRunning = false;
|
||||
private Animation anim;
|
||||
|
||||
void Start () {
|
||||
anim = GetComponent<Animation> ();
|
||||
}
|
||||
|
||||
public void ShakeCamera() {
|
||||
if (anim != null)
|
||||
anim.Play (anim.clip.name);
|
||||
else
|
||||
ShakeCaller (0.25f, 0.1f);
|
||||
}
|
||||
|
||||
//other shake option
|
||||
public void ShakeCaller (float amount, float duration){
|
||||
StartCoroutine (Shake(amount, duration));
|
||||
}
|
||||
|
||||
IEnumerator Shake (float amount, float duration){
|
||||
isRunning = true;
|
||||
|
||||
Vector3 originalPos = transform.localPosition;
|
||||
int counter = 0;
|
||||
|
||||
while (duration > 0.01f) {
|
||||
counter++;
|
||||
|
||||
var x = Random.Range (-1f, 1f) * (amount/counter);
|
||||
var y = Random.Range (-1f, 1f) * (amount/counter);
|
||||
|
||||
transform.localPosition = Vector3.Lerp (transform.localPosition, new Vector3 (originalPos.x + x, originalPos.y + y, originalPos.z), 0.5f);
|
||||
|
||||
duration -= Time.deltaTime;
|
||||
|
||||
yield return new WaitForSeconds (0.1f);
|
||||
}
|
||||
|
||||
transform.localPosition = originalPos;
|
||||
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de7cf7a6258c3634283fde9ddda2db91
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,172 @@
|
||||
//
|
||||
//
|
||||
//NOTES:
|
||||
//
|
||||
//This script is used for DEMONSTRATION porpuses of the Projectiles. I recommend everyone to create their own code for their own projects.
|
||||
//THIS IS JUST A BASIC EXAMPLE PUT TOGETHER TO DEMONSTRATE VFX ASSETS.
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma warning disable 0168 // variable declared but not used.
|
||||
#pragma warning disable 0219 // variable assigned but not used.
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProjectileMoveScript : MonoBehaviour {
|
||||
|
||||
public bool rotate = false;
|
||||
public float rotateAmount = 45;
|
||||
public bool bounce = false;
|
||||
public float bounceForce = 10;
|
||||
public float speed;
|
||||
[Tooltip("From 0% to 100%")]
|
||||
public float accuracy;
|
||||
public float fireRate;
|
||||
public GameObject muzzlePrefab;
|
||||
public GameObject hitPrefab;
|
||||
public List<GameObject> trails;
|
||||
|
||||
private Vector3 startPos;
|
||||
private float speedRandomness;
|
||||
private Vector3 offset;
|
||||
private bool collided;
|
||||
private Rigidbody rb;
|
||||
private RotateToMouseScript rotateToMouse;
|
||||
private GameObject target;
|
||||
|
||||
void Start () {
|
||||
startPos = transform.position;
|
||||
rb = GetComponent <Rigidbody> ();
|
||||
|
||||
//used to create a radius for the accuracy and have a very unique randomness
|
||||
if (accuracy != 100) {
|
||||
accuracy = 1 - (accuracy / 100);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
var val = 1 * Random.Range (-accuracy, accuracy);
|
||||
var index = Random.Range (0, 2);
|
||||
if (i == 0) {
|
||||
if (index == 0)
|
||||
offset = new Vector3 (0, -val, 0);
|
||||
else
|
||||
offset = new Vector3 (0, val, 0);
|
||||
} else {
|
||||
if (index == 0)
|
||||
offset = new Vector3 (0, offset.y, -val);
|
||||
else
|
||||
offset = new Vector3 (0, offset.y, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (muzzlePrefab != null) {
|
||||
var muzzleVFX = Instantiate (muzzlePrefab, transform.position, Quaternion.identity);
|
||||
muzzleVFX.transform.forward = gameObject.transform.forward + offset;
|
||||
var ps = muzzleVFX.GetComponent<ParticleSystem>();
|
||||
if (ps != null)
|
||||
Destroy (muzzleVFX, ps.main.duration);
|
||||
else {
|
||||
var psChild = muzzleVFX.transform.GetChild(0).GetComponent<ParticleSystem>();
|
||||
Destroy (muzzleVFX, psChild.main.duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate () {
|
||||
if (target != null)
|
||||
rotateToMouse.RotateToMouse (gameObject, target.transform.position);
|
||||
if (rotate)
|
||||
transform.Rotate(0, 0, rotateAmount, Space.Self);
|
||||
if (speed != 0 && rb != null)
|
||||
rb.position += (transform.forward + offset) * (speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
void OnCollisionEnter (Collision co) {
|
||||
if (!bounce)
|
||||
{
|
||||
if (co.gameObject.tag != "Bullet" && !collided)
|
||||
{
|
||||
collided = true;
|
||||
|
||||
if (trails.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < trails.Count; i++)
|
||||
{
|
||||
trails[i].transform.parent = null;
|
||||
var ps = trails[i].GetComponent<ParticleSystem>();
|
||||
if (ps != null)
|
||||
{
|
||||
ps.Stop();
|
||||
Destroy(ps.gameObject, ps.main.duration + ps.main.startLifetime.constantMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
speed = 0;
|
||||
GetComponent<Rigidbody>().isKinematic = true;
|
||||
|
||||
ContactPoint contact = co.contacts[0];
|
||||
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
|
||||
Vector3 pos = contact.point;
|
||||
|
||||
if (hitPrefab != null)
|
||||
{
|
||||
var hitVFX = Instantiate(hitPrefab, pos, rot) as GameObject;
|
||||
|
||||
var ps = hitVFX.GetComponent<ParticleSystem>();
|
||||
if (ps == null)
|
||||
{
|
||||
var psChild = hitVFX.transform.GetChild(0).GetComponent<ParticleSystem>();
|
||||
Destroy(hitVFX, psChild.main.duration);
|
||||
}
|
||||
else
|
||||
Destroy(hitVFX, ps.main.duration);
|
||||
}
|
||||
|
||||
StartCoroutine(DestroyParticle(0f));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.useGravity = true;
|
||||
rb.linearDamping = 0.5f;
|
||||
ContactPoint contact = co.contacts[0];
|
||||
rb.AddForce (Vector3.Reflect((contact.point - startPos).normalized, contact.normal) * bounceForce, ForceMode.Impulse);
|
||||
Destroy ( this );
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator DestroyParticle (float waitTime) {
|
||||
|
||||
if (transform.childCount > 0 && waitTime != 0) {
|
||||
List<Transform> tList = new List<Transform> ();
|
||||
|
||||
foreach (Transform t in transform.GetChild(0).transform) {
|
||||
tList.Add (t);
|
||||
}
|
||||
|
||||
while (transform.GetChild(0).localScale.x > 0) {
|
||||
yield return new WaitForSeconds (0.01f);
|
||||
transform.GetChild(0).localScale -= new Vector3 (0.1f, 0.1f, 0.1f);
|
||||
for (int i = 0; i < tList.Count; i++) {
|
||||
tList[i].localScale -= new Vector3 (0.1f, 0.1f, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds (waitTime);
|
||||
Destroy (gameObject);
|
||||
}
|
||||
|
||||
public void SetTarget (GameObject trg, RotateToMouseScript rotateTo)
|
||||
{
|
||||
target = trg;
|
||||
rotateToMouse = rotateTo;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12ba759cd568c0e47a7018ab70867a0d
|
||||
timeCreated: 1498482809
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
//
|
||||
//NOTES:
|
||||
//This script is used for DEMONSTRATION porpuses of the Projectiles. I recommend everyone to create their own code for their own projects.
|
||||
//This is just a basic example.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RotateToMouseScript : MonoBehaviour {
|
||||
|
||||
public float maximumLenght;
|
||||
|
||||
private bool use2D;
|
||||
private Ray rayMouse;
|
||||
private Vector3 pos;
|
||||
private Vector3 direction;
|
||||
private Quaternion rotation;
|
||||
private Camera cam;
|
||||
private WaitForSeconds updateTime = new WaitForSeconds (0.01f);
|
||||
|
||||
|
||||
public void StartUpdateRay (){
|
||||
StartCoroutine (UpdateRay());
|
||||
}
|
||||
|
||||
IEnumerator UpdateRay (){
|
||||
if (cam != null) {
|
||||
if (use2D) {
|
||||
Vector2 direction = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
|
||||
float angle = Mathf.Atan2 (direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
if (angle > 180) angle -= 360;
|
||||
rotation.eulerAngles = new Vector3 (-angle, 90, 0); // use different values to lock on different axis
|
||||
transform.rotation = rotation;
|
||||
} else {
|
||||
RaycastHit hit;
|
||||
var mousePos = Input.mousePosition;
|
||||
rayMouse = cam.ScreenPointToRay (mousePos);
|
||||
if (Physics.Raycast (rayMouse.origin, rayMouse.direction, out hit, maximumLenght)) {
|
||||
RotateToMouse (gameObject, hit.point);
|
||||
} else {
|
||||
var pos = rayMouse.GetPoint (maximumLenght);
|
||||
RotateToMouse (gameObject, pos);
|
||||
}
|
||||
}
|
||||
yield return updateTime;
|
||||
StartCoroutine (UpdateRay ());
|
||||
} else
|
||||
Debug.Log ("Camera not set");
|
||||
}
|
||||
|
||||
public void RotateToMouse (GameObject obj, Vector3 destination ) {
|
||||
direction = destination - obj.transform.position;
|
||||
rotation = Quaternion.LookRotation (direction);
|
||||
obj.transform.localRotation = Quaternion.Lerp (obj.transform.rotation, rotation, 1);
|
||||
}
|
||||
|
||||
public void Set2D (bool state){
|
||||
use2D = state;
|
||||
}
|
||||
|
||||
public void SetCamera (Camera camera){
|
||||
cam = camera;
|
||||
}
|
||||
|
||||
public Vector3 GetDirection () {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public Quaternion GetRotation () {
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b471b1df235ed774e9063eb5be974d7b
|
||||
timeCreated: 1529269730
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,211 @@
|
||||
//
|
||||
//NOTES:
|
||||
//This script is used for DEMONSTRATION porpuses of the Projectiles. I recommend everyone to create their own code for their own projects.
|
||||
//This is just a basic example.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpawnProjectilesScript : MonoBehaviour {
|
||||
|
||||
public bool useTarget;
|
||||
public bool use2D;
|
||||
public bool cameraShake;
|
||||
public Text effectName;
|
||||
public RotateToMouseScript rotateToMouse;
|
||||
public GameObject firePoint;
|
||||
public GameObject cameras;
|
||||
public GameObject target;
|
||||
public List<GameObject> VFXs = new List<GameObject> ();
|
||||
|
||||
private int count = 0;
|
||||
private float timeToFire = 0f;
|
||||
private GameObject effectToSpawn;
|
||||
private List<Camera> camerasList = new List<Camera> ();
|
||||
private Camera singleCamera;
|
||||
|
||||
void Start () {
|
||||
|
||||
if (cameras.transform.childCount > 0) {
|
||||
for (int i = 0; i < cameras.transform.childCount; i++) {
|
||||
camerasList.Add (cameras.transform.GetChild (i).gameObject.GetComponent<Camera> ());
|
||||
}
|
||||
if(camerasList.Count == 0){
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
}
|
||||
} else {
|
||||
singleCamera = cameras.GetComponent<Camera> ();
|
||||
if (singleCamera != null)
|
||||
camerasList.Add (singleCamera);
|
||||
else
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
}
|
||||
|
||||
if(VFXs.Count>0)
|
||||
effectToSpawn = VFXs[0];
|
||||
else
|
||||
Debug.Log ("Please assign one or more VFXs in inspector");
|
||||
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
|
||||
if (camerasList.Count > 0) {
|
||||
rotateToMouse.SetCamera (camerasList [camerasList.Count - 1]);
|
||||
if(use2D)
|
||||
rotateToMouse.Set2D (true);
|
||||
rotateToMouse.StartUpdateRay ();
|
||||
}
|
||||
else
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
|
||||
if (useTarget && target != null)
|
||||
{
|
||||
var collider = target.GetComponent<BoxCollider>();
|
||||
if (!collider)
|
||||
{
|
||||
target.AddComponent<BoxCollider>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if (Input.GetKey (KeyCode.Space) && Time.time >= timeToFire || Input.GetMouseButton (0) && Time.time >= timeToFire) {
|
||||
timeToFire = Time.time + 1f / effectToSpawn.GetComponent<ProjectileMoveScript>().fireRate;
|
||||
SpawnVFX ();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.D))
|
||||
Next ();
|
||||
if (Input.GetKeyDown (KeyCode.A))
|
||||
Previous ();
|
||||
if (Input.GetKeyDown (KeyCode.C))
|
||||
SwitchCamera ();
|
||||
if (Input.GetKeyDown (KeyCode.Alpha1))
|
||||
CameraShake ();
|
||||
if (Input.GetKeyDown (KeyCode.X))
|
||||
ZoomIn ();
|
||||
if (Input.GetKeyDown (KeyCode.Z))
|
||||
ZoomOut ();
|
||||
}
|
||||
|
||||
public void SpawnVFX () {
|
||||
GameObject vfx;
|
||||
|
||||
var cameraShakeScript = cameras.GetComponent<CameraShakeSimpleScript> ();
|
||||
|
||||
if (cameraShake && cameraShakeScript != null)
|
||||
cameraShakeScript.ShakeCamera ();
|
||||
|
||||
if (firePoint != null) {
|
||||
vfx = Instantiate (effectToSpawn, firePoint.transform.position, Quaternion.identity);
|
||||
if (!useTarget)
|
||||
{
|
||||
if (rotateToMouse != null)
|
||||
{
|
||||
vfx.transform.localRotation = rotateToMouse.GetRotation();
|
||||
}
|
||||
else Debug.Log("No RotateToMouseScript found on firePoint.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
vfx.GetComponent<ProjectileMoveScript>().SetTarget(target, rotateToMouse);
|
||||
rotateToMouse.RotateToMouse(vfx, target.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(vfx);
|
||||
Debug.Log("No target assigned.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
vfx = Instantiate (effectToSpawn);
|
||||
}
|
||||
|
||||
public void Next () {
|
||||
count++;
|
||||
|
||||
if (count > VFXs.Count)
|
||||
count = 0;
|
||||
|
||||
for(int i = 0; i < VFXs.Count; i++){
|
||||
if (count == i) effectToSpawn = VFXs [i];
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void Previous () {
|
||||
count--;
|
||||
|
||||
if (count < 0)
|
||||
count = VFXs.Count;
|
||||
|
||||
for (int i = 0; i < VFXs.Count; i++) {
|
||||
if (count == i) effectToSpawn = VFXs [i];
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void CameraShake () {
|
||||
cameraShake = !cameraShake;
|
||||
}
|
||||
|
||||
public void ZoomIn () {
|
||||
if (camerasList.Count > 0) {
|
||||
if (!camerasList [0].orthographic) {
|
||||
if (camerasList [0].fieldOfView < 101) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].fieldOfView += 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (camerasList [0].orthographicSize < 10) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].orthographicSize += 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ZoomOut () {
|
||||
if (camerasList.Count > 0) {
|
||||
if (!camerasList [0].orthographic) {
|
||||
if (camerasList [0].fieldOfView > 20) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].fieldOfView -= 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (camerasList [0].orthographicSize > 4) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].orthographicSize -= 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchCamera () {
|
||||
if (camerasList.Count > 0) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
if (camerasList [i].gameObject.activeSelf) {
|
||||
camerasList [i].gameObject.SetActive (false);
|
||||
if ((i + 1) == camerasList.Count) {
|
||||
camerasList [0].gameObject.SetActive (true);
|
||||
rotateToMouse.SetCamera (camerasList [0]);
|
||||
break;
|
||||
} else {
|
||||
camerasList [i + 1].gameObject.SetActive (true);
|
||||
rotateToMouse.SetCamera (camerasList [i + 1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2eb83ec655d71b498b43c9ebccd8066
|
||||
timeCreated: 1515515037
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user