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.
236 lines
9.7 KiB
236 lines
9.7 KiB
using AX.MessageSystem; |
|
using AX.NetworkSystem; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using System; |
|
using UnityEngine.AI; |
|
|
|
public class FireFightNormal : MonoBehaviour |
|
{ |
|
//记录打在普通火蔓延火上的直流水数量 |
|
public List<WaterFightFire> Straightwater = new List<WaterFightFire>(); |
|
//记录打在全液面火上的泡沫的数量 |
|
public List<WaterFightFire> FrothList = new List<WaterFightFire>(); |
|
//private CloneObjType FireType; |
|
//public float MaxLiftTimeLG1; |
|
//public float MinLiftTimeLG1; |
|
//public float MaxLiftTimeLG2; |
|
//public float MinLiftTimeLG2; |
|
private Transform fire1; |
|
private Transform fire2; |
|
private Transform Smoke; |
|
ParticleSystem ParticleSystem1; |
|
ParticleSystem.EmissionModule emissionModule1; |
|
ParticleSystem ParticleSystem2; |
|
ParticleSystem.EmissionModule emissionModule2; |
|
private BaseGameObjInfo baseinfo; |
|
|
|
public float rateovertime1; |
|
public float rateovertime2; |
|
//LG1初始搭设比率 |
|
public float originalrate1; |
|
//LG2初始搭设比率 |
|
public float originalrate2; |
|
void Awake() |
|
{ |
|
baseinfo = GetComponent<BaseGameObjInfo>(); |
|
fire1 = transform.Find("GroundFire_LG1"); |
|
fire2 = transform.Find("GroundFire_LG2"); |
|
Smoke = transform.Find("Fire_Smoke_LG"); |
|
|
|
//MaxLiftTimeLG1 = fire1.GetComponent<ParticleSystem>().main.startLifetime.constantMax; |
|
//MinLiftTimeLG1 = fire1.GetComponent<ParticleSystem>().main.startLifetime.constantMin; |
|
//MaxLiftTimeLG2 = fire2.GetComponent<ParticleSystem>().main.startLifetime.constantMax; |
|
//MinLiftTimeLG2 = fire2.GetComponent<ParticleSystem>().main.startLifetime.constantMin; |
|
ParticleSystem1 = fire1.GetComponent<ParticleSystem>(); |
|
emissionModule1 = ParticleSystem1.emission; |
|
ParticleSystem2 = fire2.GetComponent<ParticleSystem>(); |
|
emissionModule2 = ParticleSystem2.emission; |
|
originalrate1 = emissionModule1.rateOverTime.constant; |
|
originalrate2 = emissionModule2.rateOverTime.constant; |
|
rateovertime1 = emissionModule1.rateOverTime.constant; |
|
rateovertime2 = emissionModule2.rateOverTime.constant; |
|
// ParticleSystem.MainModule sm = Smoke.GetComponent<ParticleSystem>().main; |
|
//Debug.Log( sm.startLifetime.constantMax); |
|
// Debug.Log( sm.startLifetime) ; |
|
MessageDispatcher.AddListener("FIRE_LIQUID_LEVEL_SCALE_COMMAND", SetOriEss); |
|
} |
|
void Start() |
|
{ |
|
//将该火加入到对应的火堆字典中 |
|
//因为蔓延火是在演练开始后才开始蔓延,所以能加进去 |
|
//只加蔓延火 |
|
if (baseinfo.gameObjType==CloneObjType.SpreadedFire&& |
|
GetComponent<SpreadedFireCtrl>()) |
|
{ |
|
long mainFireId = GetComponent<SpreadedFireCtrl>().fireGameObjID; |
|
SpreadFireController.fireStruckContainDic[mainFireId].Add(this); |
|
} |
|
} |
|
private void OnEnable() |
|
{ |
|
if (GetComponent<NavMeshObstacle>()) |
|
GetComponent<NavMeshObstacle>().enabled = true; |
|
} |
|
void OnDisable() |
|
{ |
|
if (GameSettings.othersSettings.isStartDrill) |
|
{ |
|
//从字典中移除该普通火 |
|
if (baseinfo.gameObjType == CloneObjType.fireNormal) |
|
{ |
|
if (SpreadFireController.fireStruckContainDic.ContainsKey(baseinfo.gameObjID)) |
|
{ |
|
SpreadFireController.fireStruckContainDic[baseinfo.gameObjID].Remove(this); |
|
} |
|
|
|
} |
|
//主火(普通火)只隐藏不删除 |
|
Straightwater.Clear(); |
|
//清空泡沫数量 |
|
FrothList.Clear(); |
|
if (GetComponent<NavMeshObstacle>()) |
|
GetComponent<NavMeshObstacle>().enabled = false; |
|
} |
|
} |
|
private void OnDestroy() |
|
{//蔓延火熄灭直接删除 |
|
//从字典中移除该蔓延火 |
|
if (baseinfo.gameObjType == CloneObjType.SpreadedFire && |
|
GetComponent<SpreadedFireCtrl>()) |
|
{ |
|
long mainFireId = GetComponent<SpreadedFireCtrl>().fireGameObjID; |
|
if (SpreadFireController.fireStruckContainDic.ContainsKey(mainFireId)) |
|
{ |
|
if (SpreadFireController.fireStruckContainDic[mainFireId].Contains(this)) |
|
{ |
|
SpreadFireController.fireStruckContainDic[mainFireId].Remove(this); |
|
if (SpreadFireController.fireStruckContainDic[mainFireId].Count<1) |
|
{ |
|
EntitiesManager.Instance.DeleteObj(EntitiesManager.Instance.GetEntityByID(mainFireId)); |
|
if (GameSettings.othersSettings.mode != Mode.DisasterManagement) |
|
{ |
|
if (CurrentUserInfo.room!=null&& CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) |
|
{ |
|
BaseNetworkSyncDate arg = new BaseNetworkSyncDate(); |
|
arg.SendUserID = CurrentUserInfo.mySelf.Id; |
|
arg.gameObjID = mainFireId; |
|
NetworkManager.Default.SendAsync("OBJ_DELECT_SYNC", arg); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
} |
|
Straightwater.Clear(); |
|
FrothList.Clear(); |
|
MessageDispatcher.RemoveListener("FIRE_LIQUID_LEVEL_SCALE_COMMAND", SetOriEss); |
|
if (GetComponent<NavMeshObstacle>()) |
|
{ |
|
GetComponent<NavMeshObstacle>().enabled = false; |
|
} |
|
} |
|
private void SetOriEss(IMessage obj) |
|
{ |
|
if (baseinfo.gameObjType == CloneObjType.LiquidLevel) |
|
{ |
|
setRate(); |
|
} |
|
} |
|
public void setRate() |
|
{ |
|
originalrate1 = emissionModule1.rateOverTime.constant; |
|
originalrate2 = emissionModule2.rateOverTime.constant; |
|
rateovertime1 = originalrate1;//emissionModule1.rateOverTime.constant; |
|
rateovertime2 = originalrate2;//emissionModule2.rateOverTime.constant; |
|
} |
|
|
|
void OnParticleCollision(GameObject other) |
|
{ |
|
|
|
if (CurrentUserInfo.room!=null&&CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) |
|
{ |
|
if (baseinfo.gameObjType == CloneObjType.fireNormal) |
|
{ |
|
if (other.GetComponentInParent<ParticleControlOfType>()) |
|
{ |
|
if (other.GetComponentInParent<ParticleControlOfType>().particleType == SprayParticleType.WaterStraight) |
|
{ |
|
other.GetComponentInChildren<WaterFightFire>(true).Target = gameObject.GetComponent<Collider>(); |
|
} |
|
} |
|
|
|
} |
|
else if (baseinfo.gameObjType == CloneObjType.LiquidLevel) |
|
{ |
|
if (other.GetComponentInParent<ParticleControlOfType>()) |
|
{ |
|
if (other.GetComponentInParent<ParticleControlOfType>().particleType == SprayParticleType.Froth) |
|
{ |
|
other.GetComponentInParent<WaterFightFire>().Target = gameObject.GetComponent<Collider>(); |
|
} |
|
} |
|
} |
|
else if (baseinfo.gameObjType == CloneObjType.SpreadedFire) |
|
{ |
|
if (other.GetComponentInParent<ParticleControlOfType>()) |
|
{ |
|
if (other.GetComponentInParent<ParticleControlOfType>().particleType == SprayParticleType.WaterStraight) |
|
{ |
|
other.GetComponentInChildren<WaterFightFire>(true).Target = gameObject.GetComponent<Collider>(); |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
public void FireNormalSizeCalculate(float rate1, float rate2) |
|
{ |
|
//ParticleSystem.MinMaxCurve LG1max = fire1.GetComponent<ParticleSystem>().main.startLifetime; |
|
//LG1max = new ParticleSystem.MinMaxCurve(MaxLiftTimeLG1,MinLiftTimeLG1); |
|
rateovertime1 -= rate1; |
|
rateovertime2 -= rate2; |
|
|
|
|
|
emissionModule1.rateOverTime = new ParticleSystem.MinMaxCurve(rateovertime1); |
|
emissionModule2.rateOverTime = new ParticleSystem.MinMaxCurve(rateovertime2); |
|
|
|
if (rateovertime1 < 0 && rateovertime2 < 0) |
|
{ |
|
//蔓延火和全液面火 |
|
if (baseinfo.gameObjType == CloneObjType.SpreadedFire || |
|
baseinfo.gameObjType == CloneObjType.LiquidLevel) |
|
{ |
|
EntitiesManager.Instance.DeleteObj(gameObject); |
|
} |
|
//普通火(主火),隐藏其所有子物体,因为还有蔓延逻辑 |
|
if (baseinfo.gameObjType == CloneObjType.fireNormal) |
|
{ |
|
for (int i = 0; i < transform.childCount; i++) |
|
{ |
|
transform.GetChild(i).gameObject.SetActive(false); |
|
} |
|
GetComponent<Collider>().enabled = false; |
|
if (SpreadFireController.fireStruckContainDic.ContainsKey(baseinfo.gameObjID)) |
|
{ |
|
SpreadFireController.fireStruckContainDic[baseinfo.gameObjID].Remove(this); |
|
} |
|
if (GetComponent<NavMeshObstacle>()) |
|
{ |
|
GetComponent<NavMeshObstacle>().enabled = false; |
|
} |
|
} |
|
|
|
} |
|
|
|
var arg = new NormalFireFightSyncData(); |
|
arg.SendUserID = CurrentUserInfo.mySelf.Id; |
|
arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID; |
|
arg.Rateovertime1 = rateovertime1; |
|
arg.Rateovertime2 = rateovertime2; |
|
NetworkManager.Default.SendAsync("NORMAL_OR_LIQUID_FIRE_FIGHT_SYNC", arg); |
|
// Debug.Log(CurrentUserInfo.role.ToString() + rateovertime1+"//"+rate1); |
|
} |
|
}
|
|
|