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.
385 lines
15 KiB
385 lines
15 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class WaterFightFire : MonoBehaviour
|
||
|
{
|
||
|
public SprayParticleType Type;
|
||
|
public float SpeedUprate = 1;
|
||
|
private ParticleSystem PS;
|
||
|
private Collider target;
|
||
|
|
||
|
public Collider Target
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return target;
|
||
|
}
|
||
|
|
||
|
set
|
||
|
{
|
||
|
//仅处理直流(普通火、蔓延火,用于蔓延控制)
|
||
|
if (Type == SprayParticleType.WaterStraight)
|
||
|
{
|
||
|
if (target != value && target != null && target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (target.GetComponent<FireFightNormal>().Straightwater.Contains(this))
|
||
|
{
|
||
|
target.GetComponent<FireFightNormal>().Straightwater.Remove(this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (Type == SprayParticleType.Froth)
|
||
|
{
|
||
|
if (target != value && target != null && target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (target.GetComponent<FireFightNormal>().FrothList.Contains(this))
|
||
|
{
|
||
|
target.GetComponent<FireFightNormal>().FrothList.Remove(this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
target = value;
|
||
|
}
|
||
|
}
|
||
|
List<ParticleSystem.Particle> enter = new List<ParticleSystem.Particle>();
|
||
|
List<ParticleSystem.Particle> exit = new List<ParticleSystem.Particle>();
|
||
|
List<ParticleSystem.Particle> inside = new List<ParticleSystem.Particle>();
|
||
|
List<ParticleSystem.Particle> outside = new List<ParticleSystem.Particle>();
|
||
|
float timer = 1f;
|
||
|
void Start()
|
||
|
{
|
||
|
PS = GetComponent<ParticleSystem>();
|
||
|
// target = GetComponentInParent<BoxCollider>();
|
||
|
}
|
||
|
//public int TriggerThreshold
|
||
|
//{
|
||
|
// get { return _triggerThreshold; }
|
||
|
// set { _triggerThreshold = value; }
|
||
|
//}
|
||
|
|
||
|
//public void ToggleWater(bool isOpen)
|
||
|
//{
|
||
|
// IsSendPoint = false;
|
||
|
// gameObject.SetActive(isOpen);
|
||
|
//}
|
||
|
|
||
|
//public void Init()
|
||
|
//{
|
||
|
// transform.localPosition = Vector3.zero;
|
||
|
// transform.localEulerAngles = Vector3.zero;
|
||
|
// //****************核心代码
|
||
|
// PS = GetComponent<ParticleSystem>();
|
||
|
// //if (XFTarget != null)
|
||
|
// // PS.trigger.SetCollider(0, XFTarget.GetComponentInChildren<Collider>(true));
|
||
|
// ////*******************
|
||
|
// //var mainModule = PS.main;
|
||
|
// //{
|
||
|
// // mainModule.startSpeed = ShotSpeed;
|
||
|
// // mainModule.startLifetime = LifeTime;
|
||
|
// //}
|
||
|
|
||
|
//}
|
||
|
|
||
|
|
||
|
private int debugCount = 0;
|
||
|
|
||
|
|
||
|
|
||
|
void OnParticleTrigger()
|
||
|
{
|
||
|
if (Target != null)
|
||
|
{
|
||
|
PS.trigger.SetCollider(0, Target);
|
||
|
}
|
||
|
int enterNum = PS.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
|
||
|
int exitNum = PS.GetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit);
|
||
|
int insideNum = PS.GetTriggerParticles(ParticleSystemTriggerEventType.Inside, inside);
|
||
|
int outsideNum = PS.GetTriggerParticles(ParticleSystemTriggerEventType.Outside, outside);
|
||
|
|
||
|
if (enterNum > 0)
|
||
|
OnEnterCollider(enter);
|
||
|
if (exitNum > 0)
|
||
|
OnExitCollider(exit);
|
||
|
if (insideNum > 0)
|
||
|
OnInSideCollider(inside);
|
||
|
else
|
||
|
OnDontinCollider(inside);
|
||
|
if (outsideNum > 0)
|
||
|
OnOutSideCollider(outside);
|
||
|
|
||
|
#if UNITY_EDITOR
|
||
|
|
||
|
// if (debugCount <= 1)
|
||
|
// {
|
||
|
// Debug.Log("insideNum" + insideNum + " inside.Count" + inside.Count);
|
||
|
// Debug.Log("enterNum" + enterNum + " enter.Count" + enter.Count);
|
||
|
// Debug.Log("exitNum" + exitNum + " exit.Count" + exit.Count);
|
||
|
// Debug.Log("outsideNum" + outsideNum + " outside.Count" + outside.Count);
|
||
|
// debugCount++;
|
||
|
// }
|
||
|
#endif
|
||
|
PS.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
|
||
|
PS.SetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit);
|
||
|
PS.SetTriggerParticles(ParticleSystemTriggerEventType.Inside, inside);
|
||
|
PS.SetTriggerParticles(ParticleSystemTriggerEventType.Outside, outside);
|
||
|
}
|
||
|
|
||
|
private void OnDontinCollider(List<ParticleSystem.Particle> inside)
|
||
|
{
|
||
|
if (CurrentUserInfo.room!=null&&CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
|
||
|
{
|
||
|
//水枪移出火堆
|
||
|
timer -= Time.deltaTime;
|
||
|
if (timer < 0)
|
||
|
{
|
||
|
if (Target != null && Target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (Target.GetComponent<FireFightNormal>().Straightwater.Contains(this))
|
||
|
{
|
||
|
Target.GetComponent<FireFightNormal>().Straightwater.Remove(this);
|
||
|
}
|
||
|
//Debug.Log(Target.name + "/" + Target.GetComponent<FireFightNormal>().Straightwater.Count);
|
||
|
|
||
|
if (Target.GetComponent<FireFightNormal>().FrothList.Contains(this))
|
||
|
{
|
||
|
Target.GetComponent<FireFightNormal>().FrothList.Remove(this);
|
||
|
}
|
||
|
Target = null;
|
||
|
}
|
||
|
timer = 1f;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void FixedAction()
|
||
|
{
|
||
|
//if (IsSendPoint) return;
|
||
|
|
||
|
//_ffTimer += Time.deltaTime;
|
||
|
|
||
|
//if (_ffTimer >= Interval)
|
||
|
//{
|
||
|
// _ffTimer -= Interval;
|
||
|
// int id = RoleManager.Instance.currentRoleID;
|
||
|
// DataCommModule.Instance.SetPointValue(FireGunPoint, PointValue, id, 1);
|
||
|
|
||
|
// IsSendPoint = true;
|
||
|
// Debug.LogFormat("________发送了点..{0}值{1}", FireGunPoint, PointValue);
|
||
|
//}
|
||
|
}
|
||
|
void OnEnterCollider(List<ParticleSystem.Particle> enters)
|
||
|
{
|
||
|
Debug.Log("enter");
|
||
|
}
|
||
|
void OnExitCollider(List<ParticleSystem.Particle> exits)
|
||
|
{
|
||
|
Debug.Log("exit");
|
||
|
}
|
||
|
void OnInSideCollider(List<ParticleSystem.Particle> insides)
|
||
|
{
|
||
|
|
||
|
if (CurrentUserInfo.room!=null&&CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
|
||
|
{
|
||
|
timer -= Time.deltaTime;
|
||
|
if (timer < 0)
|
||
|
{
|
||
|
if (Target != null && Target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (Type == SprayParticleType.WaterStraight)
|
||
|
{
|
||
|
if (!Target.GetComponent<FireFightNormal>().Straightwater.Contains(this))
|
||
|
{
|
||
|
Target.GetComponent<FireFightNormal>().Straightwater.Add(this);
|
||
|
// Debug.Log(Target.name + "/" + Target.GetComponent<FireFightNormal>().Straightwater.Count);
|
||
|
}
|
||
|
}
|
||
|
if (Type == SprayParticleType.Froth)
|
||
|
{
|
||
|
if (!Target.GetComponent<FireFightNormal>().FrothList.Contains(this))
|
||
|
{
|
||
|
Target.GetComponent<FireFightNormal>().FrothList.Add(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
if(Target!=null)
|
||
|
{
|
||
|
MinuFireNormal();
|
||
|
}
|
||
|
timer = 1f;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
void OnOutSideCollider(List<ParticleSystem.Particle> outsides)
|
||
|
{
|
||
|
timer -= Time.deltaTime;
|
||
|
if (timer < 0)
|
||
|
{
|
||
|
if (Target != null)
|
||
|
{
|
||
|
if (Target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (Type == SprayParticleType.WaterStraight)
|
||
|
{
|
||
|
if (Target.GetComponent<FireFightNormal>().Straightwater.Contains(this))
|
||
|
{
|
||
|
Target.GetComponent<FireFightNormal>().Straightwater.Remove(this);
|
||
|
Debug.Log(Target.GetComponent<FireFightNormal>().Straightwater.Count);
|
||
|
}
|
||
|
}
|
||
|
if (Type==SprayParticleType.Froth)
|
||
|
{
|
||
|
if (Target.GetComponent<FireFightNormal>().FrothList.Contains(this))
|
||
|
{
|
||
|
Target.GetComponent<FireFightNormal>().FrothList.Remove(this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
Target = null;
|
||
|
timer = 1f;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MinuFireNormal()
|
||
|
{
|
||
|
//火的面积
|
||
|
float fireArea;
|
||
|
if (Type == SprayParticleType.WaterStraight)
|
||
|
{
|
||
|
if (Target.GetComponent<BaseGameObjInfo>())
|
||
|
{
|
||
|
//如果是普通火
|
||
|
if (Target.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.fireNormal ||
|
||
|
Target.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.SpreadedFire)
|
||
|
{
|
||
|
if (Target.GetComponent<FireInitialSizeSet>())
|
||
|
{
|
||
|
fireArea = Target.GetComponent<FireInitialSizeSet>().selectedFireScale;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
fireArea = 10f;
|
||
|
}
|
||
|
//这堆火的熄灭总时长(单位:秒),
|
||
|
float TotalDietime = (fireArea / 50.00000f) * 900 / SpeedUprate;
|
||
|
|
||
|
//单位灭火速率(每人、每秒多少平火),这里放大了100倍
|
||
|
//float DieSpeed = (1 / TotalDietime) * 100;
|
||
|
float minusrate1 = (1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate1;
|
||
|
float minusrate2 = (1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate2;
|
||
|
|
||
|
//LG1 rateovertime 减少速率;
|
||
|
// Target.GetComponent<FireFightNormal>().rateovertime1 -= (1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate1;
|
||
|
// Target.GetComponent<FireFightNormal>().rateovertime2 -= (1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate2;
|
||
|
|
||
|
Target.GetComponent<FireFightNormal>().FireNormalSizeCalculate(minusrate1, minusrate2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (Type == SprayParticleType.Froth)
|
||
|
{
|
||
|
if (Target.GetComponent<BaseGameObjInfo>())
|
||
|
{
|
||
|
if (Target.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.LiquidLevel)
|
||
|
{
|
||
|
//Debug.Log(111);
|
||
|
long oilId = Target.GetComponent<FireLiquidLevelCtrl>().TargetNormalID;
|
||
|
float direction = EntitiesManager.Instance.GetEntityByID(oilId).GetComponent<OilTankBase>().Tank_D;
|
||
|
fireArea = Mathf.PI * Mathf.Pow(direction / 2.00000f, 2);
|
||
|
//if (!JudeLequipBeFight(Target,fireArea))
|
||
|
//{
|
||
|
// return;
|
||
|
//}
|
||
|
//这堆火的熄灭总时长(单位:秒),
|
||
|
float TotalDietime = (fireArea / 50.00000f) * 900 / SpeedUprate;
|
||
|
|
||
|
//单位灭火速率(每人、每秒多少平火),这里放大了100倍
|
||
|
//float DieSpeed = (1 / TotalDietime) * 100;
|
||
|
float minusrate1 = (1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate1;
|
||
|
float minusrate2 = (1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate2;
|
||
|
//LG1 rateovertime 减少速率;
|
||
|
// Target.GetComponent<FireFightNormal>().rateovertime1 = Target.GetComponent<FireFightNormal>().rateovertime1-(1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate1;
|
||
|
// Target.GetComponent<FireFightNormal>().rateovertime2 = Target.GetComponent<FireFightNormal>().rateovertime2-(1 / TotalDietime) * Target.GetComponent<FireFightNormal>().originalrate2;
|
||
|
|
||
|
Target.GetComponent<FireFightNormal>().FireNormalSizeCalculate(minusrate1, minusrate2);
|
||
|
}
|
||
|
if (Target.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.Leak1)
|
||
|
{
|
||
|
fireArea = Target.GetComponent<BoxCollider>().size.x * Target.GetComponent<BoxCollider>().size.z;
|
||
|
float TotalDietime = (fireArea / 50.00000f) * 900 / SpeedUprate;
|
||
|
Target.GetComponent<FireFightLeak1>().fireBottomrate -= (1 / TotalDietime) * Target.GetComponent<FireFightLeak1>().OriFireBottomrate;
|
||
|
Target.GetComponent<FireFightLeak1>().Smokerate -= (1 / TotalDietime) * Target.GetComponent<FireFightLeak1>().OriSmokerate;
|
||
|
Target.GetComponent<FireFightLeak1>().firerate -= (1 / TotalDietime) * Target.GetComponent<FireFightLeak1>().OriFirerate;
|
||
|
Target.GetComponent<FireFightLeak1>().Leak1Calculate();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 判断全液面火能不能被熄灭
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
bool JudeLequipBeFight(Collider target,float Area)
|
||
|
{
|
||
|
bool can = true;
|
||
|
float concectarea = 0;
|
||
|
if (target!=null)
|
||
|
{
|
||
|
FireFightNormal ffn= target.GetComponent<FireFightNormal>();
|
||
|
|
||
|
for (int i = 0; i < ffn.FrothList.Count; i++)
|
||
|
{
|
||
|
if (ffn.GetComponentInParent<FireManControl>() ||
|
||
|
ffn.GetComponentInParent<FireRobotController>())
|
||
|
{
|
||
|
concectarea += 50;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
concectarea += 200;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (concectarea >= Area)
|
||
|
{
|
||
|
can = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
can = false;
|
||
|
}
|
||
|
return can;
|
||
|
}
|
||
|
|
||
|
public void OnDisable()
|
||
|
{
|
||
|
if (Target != null&&Target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (Target.GetComponent<FireFightNormal>().Straightwater.Contains(this))
|
||
|
Target.GetComponent<FireFightNormal>().Straightwater.Remove(this);
|
||
|
if (Target.GetComponent<FireFightNormal>().FrothList.Contains(this))
|
||
|
Target.GetComponent<FireFightNormal>().FrothList.Remove(this);
|
||
|
}
|
||
|
Target = null;
|
||
|
}
|
||
|
|
||
|
public void OnDestroy()
|
||
|
{
|
||
|
if (Target != null && Target.GetComponent<FireFightNormal>())
|
||
|
{
|
||
|
if (Target.GetComponent<FireFightNormal>().Straightwater.Contains(this))
|
||
|
Target.GetComponent<FireFightNormal>().Straightwater.Remove(this);
|
||
|
if (Target.GetComponent<FireFightNormal>().FrothList.Contains(this))
|
||
|
Target.GetComponent<FireFightNormal>().FrothList.Remove(this);
|
||
|
}
|
||
|
Target = null;
|
||
|
}
|
||
|
}
|
||
|
|