You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
416 lines
17 KiB
416 lines
17 KiB
using UnityEngine; |
|
using System.Collections; |
|
using AX.TrackRecord; |
|
//Author: ZCG |
|
public class ParticleSystemControl : MonoBehaviour |
|
{ |
|
private void Start() |
|
{ |
|
switch (gameObject.name) |
|
{ |
|
case "WaterStraight(Clone)": |
|
waterStaight = FindChild(this.transform, "Water").GetComponent<ParticleEmitter>(); |
|
if (this.transform.parent.parent.name != "shuiqiang")//消防车初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 1.5f; |
|
waterStraightMinLength = 0.6f; |
|
} |
|
} |
|
else//消防员初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 1f; |
|
waterStraightMinLength = 0.4f; |
|
} |
|
} |
|
break; |
|
case "WaterFog(Clone)": |
|
waterParticle = FindChild(this.transform, "kuai (3)").GetComponent<ParticleSystem>(); |
|
fogParticle = FindChild(this.transform, "Particle System").GetComponent<ParticleSystem>(); |
|
waterLifetime = waterParticle.startLifetime;//初始化水的存活时间 |
|
fogLifetime = fogParticle.startLifetime;//初始化雾的存活时间 |
|
if (this.transform.parent.parent.name != "shuiqiang")//消防车初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 1.5f; |
|
waterFogMinLength = 0.6f; |
|
} |
|
} |
|
else//消防员初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 0.9f; |
|
waterFogMinLength = 0.9f; |
|
} |
|
} |
|
break; |
|
case "WaterFlower(Clone)": |
|
var flower = FindChild(this.transform, "ParticleChange");// 需要控制的粒子系统放在ParticleChange的物体下 |
|
waterFlower = new ParticleSystem[flower.childCount]; |
|
//获取所有粒子系统 |
|
for (int i = 0; i < waterFlower.Length; i++) |
|
waterFlower[i] = flower.GetChild(i).GetComponent<ParticleSystem>(); |
|
//获取初始声明周期 |
|
waterFlowerLifetimeInit = new float[waterFlower.Length]; |
|
for (int i = 0; i < waterFlower.Length; i++) |
|
waterFlowerLifetimeInit[i] = waterFlower[i].startLifetime; |
|
if (this.transform.parent.parent.name != "shuiqiang")//消防车初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 1.5f; |
|
waterFlowerMinLength = 0.6f; |
|
} |
|
} |
|
else//消防员初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 1f; |
|
waterFlowerMinLength = 0.4f; |
|
} |
|
} |
|
break; |
|
case "Froth(Clone)": |
|
frothWaterColumn = FindChild(this.transform, "frothWaterColumn"); //获取水柱物体 |
|
frothWaterColumnInit = frothWaterColumn.localScale;//记录水柱初始缩放 |
|
|
|
var paomo = FindChild(this.transform, "ParticleChange");// 需要控制的粒子系统放在ParticleChange的物体下 |
|
froth = new ParticleSystem[paomo.childCount]; |
|
//获取所有粒子系统 |
|
for (int i = 0; i < froth.Length; i++) |
|
froth[i] = paomo.GetChild(i).GetComponent<ParticleSystem>(); |
|
//记录初始生命周期 |
|
frothLifetimeInit = new float[froth.Length]; |
|
for (int i = 0; i < froth.Length; i++) |
|
frothLifetimeInit[i] = froth[i].startLifetime; |
|
//记录初始速度 |
|
frothSpeedInit = new float[froth.Length]; |
|
for (int i = 0; i < froth.Length; i++) |
|
frothSpeedInit[i] = froth[i].startSpeed; |
|
//记录初始大小 |
|
frothSizeInit = new float[froth.Length]; |
|
for (int i = 0; i < froth.Length; i++) |
|
frothSizeInit[i] = froth[i].startSize; |
|
//记录初始重力 |
|
frothGravityInit = new float[froth.Length]; |
|
for (int i = 0; i < froth.Length; i++) |
|
frothGravityInit[i] = froth[i].gravityModifier; |
|
//记录缩放比例scale |
|
FrothScaleInit = new Vector3[froth.Length]; |
|
for (int i = 0; i < froth.Length; i++) |
|
FrothScaleInit[i] = froth[i].gameObject.transform.localScale; |
|
if (this.transform.parent.parent.name != "shuiqiang")//消防车初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 3.5f; |
|
frothMixLength = 1f; |
|
} |
|
} |
|
else//消防员初始射程 |
|
{ |
|
if (!LoadManager.Instance.IsPlayBacking) |
|
{ |
|
particleScaleControl = 0.5f; |
|
frothMixLength = 0.3f; |
|
} |
|
} |
|
break; |
|
case "DryPowder(Clone)": |
|
var ganfen = FindChild(this.transform, "ParticleChange");// 需要控制的粒子系统放在ParticleChange的物体下 |
|
dryPowder = new ParticleSystem[ganfen.childCount]; |
|
//获取所有粒子系统 |
|
for (int i = 0; i < dryPowder.Length; i++) |
|
dryPowder[i] = ganfen.GetChild(i).GetComponent<ParticleSystem>(); |
|
//记录初始重力 |
|
dryPowerGravityInit = new float[dryPowder.Length]; |
|
for (int i = 0; i < dryPowder.Length; i++) |
|
dryPowerGravityInit[i] = dryPowder[i].gravityModifier; |
|
//记录初始缩放 |
|
dryPowerScaleInit = new Vector3[dryPowder.Length]; |
|
for (int i = 0; i < dryPowder.Length; i++) |
|
dryPowerScaleInit[i] = dryPowder[i].gameObject.transform.localScale; |
|
if (this.transform.parent.parent.name == "shuiqiang")//消防员初始射程 |
|
dryPowerMinlength = 1; |
|
break; |
|
} |
|
} |
|
//只控制一个字段即可 |
|
/// <summary>控制所有粒子系统大小/射程/缩放</summary> |
|
public float particleScaleControl = 1; |
|
private void Update() |
|
{ |
|
if (gameObject.activeSelf) |
|
{ |
|
#if UNITY_EDITOR |
|
if (Input.GetKey(KeyCode.X)) |
|
particleScaleControl += 0.01f; |
|
if (Input.GetKey(KeyCode.C)) |
|
particleScaleControl -= 0.01f; |
|
#endif |
|
switch (gameObject.name) |
|
{ |
|
case "WaterStraight(Clone)": |
|
waterStraightScale = particleScaleControl; |
|
WaterStaightControl(); |
|
break; |
|
case "WaterFog(Clone)": |
|
waterFogScale = particleScaleControl; |
|
WaterFog(); |
|
break; |
|
case "WaterFlower(Clone)": |
|
waterFlowerScale = particleScaleControl; |
|
WaterFlower(); |
|
break; |
|
case "Froth(Clone)": |
|
frothScale = particleScaleControl; |
|
Froth(); |
|
break; |
|
case "DryPowder(Clone)": |
|
dryPowerScale = particleScaleControl; |
|
DryPowder(); |
|
break; |
|
} |
|
} |
|
|
|
} |
|
|
|
#region 控制直流水大小 |
|
/// <summary>直流水粒子特效(Water)</summary> |
|
private ParticleEmitter waterStaight; |
|
/// <summary>控制直流水大小的参数</summary> |
|
public float waterStraightScale = 1; |
|
/// <summary>直流水射程</summary> |
|
public float waterStraightLength = 10; |
|
/// <summary>直流水初始射程</summary> |
|
public float waterStraightMinLength; |
|
private float minSize = 0.2f; |
|
private float maxSize = 0.4f; |
|
private Vector3 localVelocityZ = new Vector3(0f, 0f, 10f); |
|
private Vector3 rndVelocity = new Vector3(0.3f, 0.3f, 0.3f); |
|
private Vector3 localScale = new Vector3(1f, 1f, 1f); |
|
//private Vector3 vector3Temp = new Vector3(0.01f, 0.01f, 0.01f); |
|
/// <summary>控制直流水大小</summary> |
|
private void WaterStaightControl() |
|
{ |
|
//#if UNITY_EDITOR |
|
// if (Input.GetKey(KeyCode.X) && waterStraightScale < waterStraightLength) |
|
// waterStraightScale += 0.01f; |
|
// if (Input.GetKey(KeyCode.C) && waterStraightScale > 1) |
|
// waterStraightScale -= 0.01f; |
|
//#endif |
|
|
|
if (waterStraightScale >= waterStraightMinLength && waterStraightScale < waterStraightLength) |
|
{ |
|
waterStaight.minSize = minSize * waterStraightScale; |
|
waterStaight.maxSize = maxSize * waterStraightScale; |
|
waterStaight.localVelocity = localVelocityZ * waterStraightScale; |
|
waterStaight.rndVelocity = rndVelocity * waterStraightScale; |
|
waterStaight.transform.localScale = localScale * waterStraightScale; |
|
waterStaight.emit = true; |
|
} |
|
else |
|
{ |
|
if (particleScaleControl <= waterStraightMinLength) |
|
particleScaleControl = waterStraightMinLength; |
|
else |
|
particleScaleControl = waterStraightLength; |
|
} |
|
|
|
} |
|
#endregion |
|
#region 控制喷雾水大小 |
|
/// <summary>控制喷雾特效的大小</summary> |
|
public float waterFogScale = 0.8f; |
|
/// <summary>控制喷雾的射程</summary> |
|
public float waterFogLength =4f; |
|
/// <summary>喷雾初始射程</summary> |
|
public float waterFogMinLength; |
|
private ParticleSystem waterParticle;//水 |
|
private ParticleSystem fogParticle;//雾 |
|
private float waterLifetime/* = 0.28f*/;//水的存活时间 |
|
private float fogLifetime /*= 1.09f*/;//雾存活时间 |
|
/// <summary>控制喷雾大小</summary> |
|
private void WaterFog() |
|
{ |
|
//#if UNITY_EDITOR |
|
// if (Input.GetKey(KeyCode.X) && waterFogScale < waterFogLength) |
|
// waterFogScale += 0.01f; |
|
// if (Input.GetKey(KeyCode.C) && waterFogScale > 1) |
|
// waterFogScale -= 0.01f; |
|
//#endif |
|
if (waterFogScale >= waterFogMinLength && waterFogScale < waterFogLength) |
|
{ |
|
waterParticle.startLifetime = waterLifetime * waterFogScale; |
|
fogParticle.startLifetime = fogLifetime * waterFogScale; |
|
} |
|
else |
|
{ |
|
if (particleScaleControl <= waterFogMinLength) |
|
particleScaleControl = waterFogMinLength; |
|
else |
|
particleScaleControl = waterFogLength; |
|
} |
|
|
|
} |
|
#endregion |
|
#region 控制开花水大小 |
|
/// <summary>控制开花特效大小</summary> |
|
public float waterFlowerScale = 1; |
|
/// <summary>控制开花的射程</summary> |
|
public float waterFlowerLength = 4; |
|
/// <summary>开花水初始射程</summary> |
|
public float waterFlowerMinLength = 1; |
|
/// <summary>所有的开花水粒子系统</summary> |
|
private ParticleSystem[] waterFlower; |
|
/// <summary>记录初始生命周期</summary> |
|
private float[] waterFlowerLifetimeInit; |
|
/// <summary>控制开花水大小</summary> |
|
private void WaterFlower() |
|
{ |
|
//#if UNITY_EDITOR |
|
// if (Input.GetKey(KeyCode.X)) |
|
// waterFlowerScale += 0.01f; |
|
// if (Input.GetKey(KeyCode.C)) |
|
// waterFlowerScale -= 0.01f; |
|
//#endif |
|
if (waterFlowerScale >= waterFlowerMinLength && waterFlowerScale < waterFlowerLength) |
|
{ |
|
for (int i = 0; i < waterFlower.Length; i++) |
|
{ |
|
waterFlower[i].startLifetime = waterFlowerLifetimeInit[i] * waterFlowerScale; |
|
} |
|
} |
|
else |
|
{ |
|
if (particleScaleControl <= waterFlowerMinLength) |
|
particleScaleControl = waterFlowerMinLength; |
|
else |
|
particleScaleControl = waterFlowerLength; |
|
|
|
} |
|
} |
|
#endregion |
|
#region 控制泡沫大小 |
|
/// <summary>所有的泡沫粒子系统</summary> |
|
private ParticleSystem[] froth; |
|
/// <summary>记录泡沫初始scale比例 </summary> |
|
private Vector3[] FrothScaleInit; |
|
/// <summary>记录粒子初始生命周期系统</summary> |
|
private float[] frothLifetimeInit; |
|
/// <summary>记录粒子初始速度</summary> |
|
private float[] frothSpeedInit; |
|
/// <summary>记录粒子初始大小</summary> |
|
private float[] frothSizeInit; |
|
/// <summary>记录重力初始大小</summary> |
|
private float[] frothGravityInit; |
|
|
|
/// <summary>水柱粒子(单独控制)</summary> |
|
private Transform frothWaterColumn; |
|
/// <summary>记录水柱粒子系统的初始scale比例</summary> |
|
private Vector3 frothWaterColumnInit; |
|
|
|
/// <summary>控制泡沫大小</summary> |
|
public float frothScale = 1; |
|
/// <summary>泡沫射程</summary> |
|
public float frothLength = 10; |
|
/// <summary>泡沫初始射程</summary> |
|
public float frothMixLength; |
|
/// <summary>控制泡沫大小</summary> |
|
private void Froth() |
|
{ |
|
//#if UNITY_EDITOR |
|
// if (Input.GetKey(KeyCode.X)) |
|
// frothScale += 0.01f; |
|
// if (Input.GetKey(KeyCode.C)) |
|
// frothScale -= 0.01f; |
|
//#endif |
|
if (frothScale >= frothMixLength && frothScale < frothLength) |
|
{ |
|
//控制泡沫缩放比例 |
|
for (int i = 0; i < froth.Length; i++) |
|
{ |
|
// froth[i].startLifetime = frothLifetimeInit[i] * frothScale;//控制生命周期 |
|
//froth[i].startSpeed = frothSpeedInit[i] * frothScale;//控制速度 |
|
//froth[i].startSize = frothSizeInit[i] * frothScale;//控制大小 |
|
froth[i].gravityModifier = frothGravityInit[i] * frothScale * 2 * 2;//控制重力大小 |
|
froth[i].transform.localScale = FrothScaleInit[i] * frothScale * 2;//控制transform缩放 |
|
} |
|
frothWaterColumn.localScale = new Vector3(frothWaterColumnInit.x * frothScale, frothWaterColumnInit.y * frothScale, frothWaterColumnInit.z * frothScale * 2);//控制水柱缩放 |
|
} |
|
else |
|
{ |
|
if (particleScaleControl <= frothMixLength) |
|
particleScaleControl = frothMixLength; |
|
else |
|
particleScaleControl = frothLength; |
|
} |
|
|
|
} |
|
#endregion |
|
#region 控制干粉大小 |
|
/// <summary>所有的干粉粒子系统</summary> |
|
private ParticleSystem[] dryPowder; |
|
/// <summary>记录干粉初始scale比例</summary> |
|
private Vector3[] dryPowerScaleInit; |
|
/// <summary>记录干粉初始重力大小</summary> |
|
private float[] dryPowerGravityInit; |
|
/// <summary>控制干粉大小</summary> |
|
public float dryPowerScale = 1; |
|
/// <summary>干粉长度</summary> |
|
public float dryPowerLength = 5; |
|
/// <summary>干粉初始射程</summary> |
|
public float dryPowerMinlength; |
|
/// <summary>控制干粉大小</summary> |
|
private void DryPowder() |
|
{ |
|
//#if UNITY_EDITOR |
|
// if (Input.GetKey(KeyCode.X)) |
|
// dryPowerScale += 0.01f; |
|
// if (Input.GetKey(KeyCode.C)) |
|
// dryPowerScale -= 0.01f; |
|
//#endif |
|
if (dryPowerScale >= dryPowerMinlength && dryPowerScale < dryPowerLength) |
|
{ |
|
for (int i = 0; i < dryPowder.Length; i++) |
|
{ |
|
dryPowder[i].gravityModifier = dryPowerGravityInit[i] * dryPowerScale * 2;//控制重力大小 |
|
dryPowder[i].transform.localScale = dryPowerScaleInit[i] * dryPowerScale * 2;//控制transform缩放 |
|
} |
|
} |
|
else |
|
{ |
|
if (particleScaleControl <= dryPowerMinlength) |
|
particleScaleControl = dryPowerMinlength; |
|
else |
|
particleScaleControl = dryPowerLength; |
|
} |
|
} |
|
#endregion |
|
/// <summary> 查找子物体</summary> |
|
/// <param name="trans">开始查找的位置</param> |
|
/// <param name="goName">子物体名字</param> |
|
/// <returns></returns> |
|
private Transform FindChild(Transform trans, string goName) |
|
{ |
|
Transform child = trans.Find(goName); |
|
if (child != null) |
|
return child; |
|
|
|
Transform go = null; |
|
for (int i = 0; i < trans.childCount; i++) |
|
{ |
|
child = trans.GetChild(i); |
|
go = FindChild(child, goName); |
|
if (go != null) |
|
return go; |
|
} |
|
return null; |
|
} |
|
} |