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.
199 lines
6.3 KiB
199 lines
6.3 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using AX.InputSystem;
|
||
|
using AX.NetworkSystem;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 全液面火的控制
|
||
|
/// </summary>
|
||
|
public class FireLiquidLevelCtrl : MonoBehaviour
|
||
|
{
|
||
|
private ParticleSystem lg1PS;
|
||
|
private ParticleSystem lg2PS;
|
||
|
private ParticleSystem smokePS;
|
||
|
private BoxCollider boxCollider;
|
||
|
|
||
|
public float fireScale = 1.0f;
|
||
|
public float FireScale
|
||
|
{
|
||
|
get { return fireScale; }
|
||
|
set { fireScale = value; ChangeFireState(); }
|
||
|
}
|
||
|
|
||
|
public string showTime = "00:00:00";//多少时间以后显示出来
|
||
|
|
||
|
private float minScale = 0.2f;
|
||
|
private float maxScale = 2.0f;
|
||
|
private float scaleSpeed = 2.0f;
|
||
|
|
||
|
private Vector3 boxCol_fire;//x,z:4.7-47
|
||
|
|
||
|
private Vector3 box_smoke;//(1,1,0.5)-(20,20,10)
|
||
|
private Vector3 pos_smoke;//Y:20-28.4
|
||
|
|
||
|
public long TargetNormalID;
|
||
|
// Use this for initialization
|
||
|
private void Awake()
|
||
|
{
|
||
|
lg1PS = transform.Find("GroundFire_LG1").GetComponent<ParticleSystem>();
|
||
|
lg2PS = transform.Find("GroundFire_LG2").GetComponent<ParticleSystem>();
|
||
|
smokePS = transform.Find("Fire_Smoke_LG").GetComponent<ParticleSystem>();
|
||
|
boxCollider = GetComponent<BoxCollider>();
|
||
|
boxCol_fire = boxCollider.size;
|
||
|
|
||
|
box_smoke = smokePS.shape.scale;
|
||
|
pos_smoke = smokePS.transform.localPosition;
|
||
|
|
||
|
FireScale = fireScale;
|
||
|
}
|
||
|
void Start()
|
||
|
{
|
||
|
MessageDispatcher.AddListener("FIRE_LIQUID_LEVEL_SCALE_COMMAND", Equals);
|
||
|
//MessageDispatcher.AddListener("FIRE_LIQUID_LEVEL_SCALE_COMMAND", Minus);
|
||
|
FireScaleValue.GetAllFireScales += addMyFireScale;
|
||
|
BurnTimer.isBurning = true;
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
////测试代码
|
||
|
//if (Input.GetButton("Plus"))
|
||
|
//{
|
||
|
// if (fireScale <= maxScale)
|
||
|
// {
|
||
|
// fireScale += Time.deltaTime * scaleSpeed;
|
||
|
// ChangeFireState();
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// fireScale = maxScale;
|
||
|
// }
|
||
|
// ChangeFireState();
|
||
|
//}
|
||
|
|
||
|
//if (Input.GetButton("Reduce"))
|
||
|
//{
|
||
|
// if (fireScale >= minScale)
|
||
|
// {
|
||
|
// fireScale -= Time.deltaTime * scaleSpeed;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// fireScale = minScale;
|
||
|
// }
|
||
|
// ChangeFireState();
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("FIRE_LIQUID_LEVEL_SCALE_COMMAND", Equals);
|
||
|
//MessageDispatcher.RemoveListener("FIRE_LIQUID_LEVEL_SCALE_COMMAND", Minus);
|
||
|
FireScaleValue.GetAllFireScales -= addMyFireScale;
|
||
|
MessageDispatcher.SendMessage("BurnTimeSet"); //BurnTimer.BurnTimeSet()
|
||
|
}
|
||
|
|
||
|
private void Equals(IMessage msg)
|
||
|
{
|
||
|
if (!GameSettings.othersSettings.isStartDrill)
|
||
|
{
|
||
|
var data = ((FireLiquidLevelCmdArgs)msg.Data);
|
||
|
if (GetComponent<BaseGameObjInfo>().gameObjID == data.SelectgameObjID)
|
||
|
{
|
||
|
//fireScale = data.FireScale;
|
||
|
FireScale = data.FireScale;
|
||
|
}
|
||
|
|
||
|
//全液面火同步
|
||
|
if (GameSettings.othersSettings.mode != Mode.DisasterManagement)
|
||
|
{
|
||
|
FireLiquidScaleSyncData arg = new FireLiquidScaleSyncData();
|
||
|
arg.gameObjID = GetComponent<CloneGameObjInfo>().gameObjID;
|
||
|
arg.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
arg.firescale = FireScale;
|
||
|
arg.oilTankID = TargetNormalID;
|
||
|
NetworkManager.Default.SendAsync("SET_FIRE_LIQUID_SYNC", arg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ChangeFireState();
|
||
|
}
|
||
|
|
||
|
//private void Minus(IMessage msg)
|
||
|
//{
|
||
|
// if (gameObject.name == (string)msg.Data)
|
||
|
// {
|
||
|
// if (fireScale >= minScale)
|
||
|
// {
|
||
|
// fireScale -= Time.deltaTime * scaleSpeed;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// fireScale = minScale;
|
||
|
// }
|
||
|
// ChangeFireState();
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 改变火的状态
|
||
|
/// </summary>
|
||
|
private void ChangeFireState()
|
||
|
{
|
||
|
var box_xz = GetValueAccordingStandardValue(4.7f, 47f);
|
||
|
boxCollider.size = new Vector3(box_xz, boxCol_fire.y, box_xz);
|
||
|
|
||
|
SetRate(lg1PS, 25f, 250f);
|
||
|
var radius_lg1 = lg1PS.shape;
|
||
|
radius_lg1.radius = GetValueAccordingStandardValue(2.2f, 22f);
|
||
|
|
||
|
SetRate(lg2PS, 10f, 100f);
|
||
|
var radius_lg2 = lg2PS.shape;
|
||
|
radius_lg2.radius = GetValueAccordingStandardValue(1f, 10f);
|
||
|
|
||
|
SetRate(smokePS, 1f, 5f);
|
||
|
SetStartSize(smokePS, 10f, 20f, 50f, 100f);
|
||
|
var box_Smoke = smokePS.shape;
|
||
|
box_Smoke.scale = new Vector3(GetValueAccordingStandardValue(1f, 20f),
|
||
|
GetValueAccordingStandardValue(1f, 20f),
|
||
|
GetValueAccordingStandardValue(0.5f, 10f));
|
||
|
smokePS.transform.localPosition = new Vector3(pos_smoke.x, GetValueAccordingStandardValue(20f, 28.4f), pos_smoke.z);
|
||
|
|
||
|
}
|
||
|
|
||
|
private float GetValueAccordingStandardValue(float min, float max)
|
||
|
{
|
||
|
return (fireScale - minScale) / (maxScale - minScale) * (max - min) + min;
|
||
|
}
|
||
|
|
||
|
private void SetRate(ParticleSystem ps, float min, float max)
|
||
|
{
|
||
|
var emission = ps.emission;
|
||
|
var rate = emission.rateOverTime;
|
||
|
rate.constant = GetValueAccordingStandardValue(min, max);
|
||
|
emission.rateOverTime = rate;
|
||
|
}
|
||
|
|
||
|
private void SetStartSize(ParticleSystem ps, float min_min, float min_max, float max_min, float max_max)
|
||
|
{
|
||
|
var main = ps.main;
|
||
|
var startSize = main.startSize;
|
||
|
startSize.constantMin = GetValueAccordingStandardValue(min_min, max_min);
|
||
|
startSize.constantMax = GetValueAccordingStandardValue(min_max, max_max);
|
||
|
main.startSize = startSize;
|
||
|
}
|
||
|
private FloatData addMyFireScale(FloatData area)
|
||
|
{
|
||
|
GameObject mytank = EntitiesManager.Instance.GetEntityByID(TargetNormalID);
|
||
|
//float r = mytank.GetComponent<OilTankMessage>().Tank_D / 2;
|
||
|
//float myscale = Mathf.PI * (r * r);
|
||
|
float myscale = Mathf.RoundToInt(GetComponent<BoxCollider>().size.x)
|
||
|
* Mathf.RoundToInt(GetComponent<BoxCollider>().size.z);
|
||
|
area.value += myscale;
|
||
|
return area;
|
||
|
}
|
||
|
}
|