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.
233 lines
7.2 KiB
233 lines
7.2 KiB
using AX.MessageSystem; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using System; |
|
|
|
public enum ParticleType |
|
{ |
|
lg1Ps, |
|
lg2Ps, |
|
smokePs, |
|
sparksPs, |
|
glowPs |
|
} |
|
|
|
public class FireInitialSizeSet : MonoBehaviour { |
|
|
|
private ParticleSystem lg1PS; |
|
private ParticleSystem lg2PS; |
|
private ParticleSystem smokePS; |
|
private ParticleSystem Sparks;//飞溅的火星:Fire_Sparks_LG |
|
private ParticleSystem Glow;//Fire_Glow_LG |
|
private Light Firelight;//火光:Firelight |
|
private GameObject cube;//火子对象cube |
|
private BoxCollider boxCollider; |
|
private Vector3 pos_smoke; |
|
|
|
private float standardFireScale = 30.0f;//基准火大小为火预设大小30平 |
|
public float selectedFireScale = 0;//设置的火初始大小 |
|
|
|
//以下是普通火默认30平的属性 |
|
private Vector3 colliderStdSize; |
|
|
|
private float lg1PsConstant; |
|
private float lg1Radius; |
|
|
|
private float lg2PsConstant; |
|
private float lg2Radius; |
|
|
|
private float smokePSConstant; |
|
private float smokePSStartSizeCstMin; |
|
private float smokePSStartSizeCstMax; |
|
private Vector3 smokePsShapBox; |
|
private Vector3 smokePsLocalPos; |
|
|
|
private float sparksConstant; |
|
private float sparksRadius; |
|
|
|
private float glowConstant; |
|
private Vector3 glowShapBox; |
|
|
|
private float fireLightRange; |
|
|
|
private Vector3 cubeLocalscale; |
|
|
|
private void Awake() |
|
{ |
|
MessageDispatcher.AddListener("FIRE_INITIALSIZE_SET", SetFireInitialSize); |
|
|
|
lg1PS = transform.Find("GroundFire_LG1").GetComponent<ParticleSystem>(); |
|
lg2PS = transform.Find("GroundFire_LG2").GetComponent<ParticleSystem>(); |
|
smokePS = transform.Find("Fire_Smoke_LG").GetComponent<ParticleSystem>(); |
|
Sparks = transform.Find("Fire_Sparks_LG").GetComponent<ParticleSystem>(); |
|
Glow = transform.Find("Fire_Glow_LG").GetComponent<ParticleSystem>(); |
|
Firelight = transform.Find("Firelight").GetComponent<Light>(); |
|
cube = transform.Find("Cube").gameObject; |
|
|
|
boxCollider = GetComponent<BoxCollider>(); |
|
|
|
pos_smoke = smokePS.transform.localPosition; |
|
|
|
colliderStdSize = boxCollider.size; |
|
|
|
lg1PsConstant = lg1PS.emission.rateOverTime.constant; |
|
lg1Radius = lg1PS.shape.radius; |
|
|
|
lg2PsConstant = lg2PS.emission.rateOverTime.constant; |
|
lg2Radius = lg2PS.shape.radius; |
|
|
|
smokePSConstant = smokePS.emission.rateOverTime.constant; |
|
smokePSStartSizeCstMin = smokePS.main.startSize.constantMin; |
|
smokePSStartSizeCstMax = smokePS.main.startSize.constantMax; |
|
smokePsShapBox = smokePS.shape.scale; |
|
smokePsLocalPos = smokePS.transform.localPosition; |
|
|
|
sparksConstant = Sparks.emission.rateOverTime.constant; |
|
sparksRadius = Sparks.shape.radius; |
|
|
|
glowConstant = Glow.emission.rateOverTime.constant; |
|
glowShapBox = Glow.shape.scale; |
|
|
|
fireLightRange = Firelight.range; |
|
|
|
cubeLocalscale = cube.transform.localScale; |
|
|
|
selectedFireScale = standardFireScale; |
|
|
|
FireScaleValue.GetAllFireScales += addMyFireScale; |
|
BurnTimer.isBurning = true; |
|
} |
|
|
|
void Start() |
|
{ |
|
|
|
} |
|
|
|
private void Update() |
|
{ |
|
|
|
} |
|
private void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("FIRE_INITIALSIZE_SET", SetFireInitialSize); |
|
FireScaleValue.GetAllFireScales -= addMyFireScale; |
|
MessageDispatcher.SendMessage("BurnTimeSet"); //BurnTimer.BurnTimeSet() |
|
} |
|
|
|
/// <summary> |
|
/// 设置火的初始大小 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void SetFireInitialSize(IMessage obj) |
|
{ |
|
var sender = (long)obj.Sender; |
|
if (sender != this.GetComponent<BaseGameObjInfo>().gameObjID) |
|
{ |
|
return; |
|
} |
|
|
|
var data = (int)obj.Data; |
|
|
|
selectedFireScale = data; |
|
var factor = GetFactor(data); |
|
|
|
boxCollider.size = new Vector3(colliderStdSize.x * factor, boxCollider.size.y, colliderStdSize.z * factor); |
|
|
|
SetEmission(ParticleType.lg1Ps ,lg1PS, factor); |
|
var radius_lg1 = lg1PS.shape; |
|
radius_lg1.radius = lg1Radius * factor; |
|
|
|
SetEmission(ParticleType.lg2Ps ,lg2PS, factor); |
|
var radius_lg2 = lg2PS.shape; |
|
radius_lg2.radius = lg2Radius * factor; |
|
|
|
SetEmission(ParticleType.smokePs, smokePS, factor); |
|
SetStartSize(ParticleType.smokePs, smokePS, factor); |
|
var box_Smoke = smokePS.shape; |
|
box_Smoke.scale = new Vector3(smokePsShapBox.x * factor, smokePsShapBox.y * factor, smokePsShapBox.z * factor); |
|
smokePS.transform.localPosition = new Vector3(smokePsLocalPos.x, smokePsLocalPos.y * factor, smokePsLocalPos.z); |
|
|
|
SetEmission(ParticleType.sparksPs, Sparks, factor); |
|
var radius_spark = Sparks.shape; |
|
radius_spark.radius = sparksRadius * factor; |
|
|
|
SetEmission(ParticleType.glowPs, Glow, factor); |
|
var box_Glow = Glow.shape; |
|
box_Glow.scale = new Vector3(glowShapBox.x * factor, glowShapBox.y * factor, glowShapBox.z * factor); |
|
|
|
Firelight.range = fireLightRange * factor; |
|
|
|
cube.transform.localScale = new Vector3(cubeLocalscale.x * factor, |
|
cubeLocalscale.y * factor, |
|
cubeLocalscale.z * factor); |
|
} |
|
|
|
private float GetFactor(float selectedSize) |
|
{ |
|
int selectedSizeSideLength = Mathf.RoundToInt(Mathf.Sqrt(selectedSize)); |
|
int standardSizeSideLength = Mathf.RoundToInt(Mathf.Sqrt(standardFireScale)); |
|
|
|
return (float)selectedSizeSideLength / (float)standardSizeSideLength; |
|
} |
|
|
|
private void SetEmission(ParticleType type, ParticleSystem ps, float factor) |
|
{ |
|
var emission = ps.emission; |
|
var rate = emission.rateOverTime; |
|
|
|
switch (type) |
|
{ |
|
case ParticleType.lg1Ps: |
|
rate.constant = lg1PsConstant * factor; |
|
break; |
|
case ParticleType.lg2Ps: |
|
rate.constant = lg2PsConstant * factor; |
|
break; |
|
case ParticleType.smokePs: |
|
rate.constant = smokePSConstant * factor; |
|
break; |
|
case ParticleType.sparksPs: |
|
rate.constant = sparksConstant * factor; |
|
break; |
|
case ParticleType.glowPs: |
|
rate.constant = glowConstant * factor; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
emission.rateOverTime = rate; |
|
} |
|
|
|
private void SetStartSize(ParticleType type, ParticleSystem ps, float factor) |
|
{ |
|
var main = ps.main; |
|
var startSize = main.startSize; |
|
|
|
switch (type) |
|
{ |
|
case ParticleType.lg1Ps: |
|
break; |
|
case ParticleType.lg2Ps: |
|
break; |
|
case ParticleType.smokePs: |
|
startSize.constantMin = smokePSStartSizeCstMin * factor; |
|
startSize.constantMax = smokePSStartSizeCstMax * factor; |
|
break; |
|
case ParticleType.sparksPs: |
|
break; |
|
case ParticleType.glowPs: |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
main.startSize = startSize; |
|
} |
|
private FloatData addMyFireScale(FloatData area) |
|
{ |
|
area.value += selectedFireScale; |
|
return area; |
|
} |
|
}
|
|
|