Initial Commit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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:
|
||||
@@ -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
|
||||
}
|
||||
@@ -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:
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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:
|
||||
Reference in New Issue
Block a user