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.
87 lines
2.4 KiB
87 lines
2.4 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
|
||
|
public class SmokeControl : MonoBehaviour {
|
||
|
private int cengID = 0;
|
||
|
private bool SmokeFlag = false;
|
||
|
private int maxSize = 300;
|
||
|
private int seconds = 10;//10秒钟烟雾排净
|
||
|
private float curSize = 300;
|
||
|
public bool ShouldShowSmoke = false;
|
||
|
// Use this for initialization
|
||
|
void Start () {
|
||
|
var strs = name.Split('_');
|
||
|
var str = strs[0];
|
||
|
var str_cengID = str.Substring(3);
|
||
|
int.TryParse(str_cengID, out cengID);
|
||
|
if (transform.childCount>0 && transform.GetChild(0).childCount>0 )
|
||
|
{
|
||
|
maxSize = transform.GetChild(0).GetChild(0).GetComponent<ParticleSystem>().maxParticles;
|
||
|
curSize = maxSize;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
void OnEnable()
|
||
|
{
|
||
|
MessageDispatcher.AddListener("SmokeChange", SmokeChange);
|
||
|
ShouldShowSmoke = true;
|
||
|
}
|
||
|
|
||
|
private void SmokeChange(IMessage msg)
|
||
|
{
|
||
|
if (cengID == (int)msg.Data)
|
||
|
{
|
||
|
var pfire = GameObject.Find("pfire").transform;
|
||
|
foreach(Transform fire in pfire)
|
||
|
{
|
||
|
if(fire.GetComponent<CengID>().cengID == cengID)
|
||
|
{
|
||
|
MessageDispatcher.SendMessage("Operatinghints", (object)"该层有火未熄灭,无法排烟!");
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
//排烟控制
|
||
|
SmokeFlag = true;
|
||
|
MessageDispatcher.SendMessage("Operatinghints", (object)"开始排烟!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void OnDisable()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("SmokeChange", SmokeChange);
|
||
|
}
|
||
|
// Update is called once per frame
|
||
|
void FixedUpdate () {
|
||
|
if (SmokeFlag)
|
||
|
{
|
||
|
if (curSize > 0)
|
||
|
{
|
||
|
curSize -= Time.deltaTime * (maxSize / seconds);
|
||
|
SetSmoke(curSize);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
SmokeFlag = false;
|
||
|
curSize = maxSize;
|
||
|
gameObject.SetActive(false);
|
||
|
SetSmoke(curSize);
|
||
|
ShouldShowSmoke = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void SetSmoke(float curSize)
|
||
|
{
|
||
|
foreach(Transform child in transform)
|
||
|
{
|
||
|
foreach(Transform smoke in child)
|
||
|
{
|
||
|
var particle = smoke.GetComponent<ParticleSystem>();
|
||
|
particle.maxParticles = (int)curSize;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|