using AX.InputSystem;
using AX.MessageSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class ParentLinesMessage : MonoBehaviour
{
public string EquipId = "82";
private float DefultHoseLenght = 20;
///
/// 开始点的物体
///
public GameObject StartHitGameObj;
///
/// 结束点的位置
///
public GameObject EndHitGameObj;
///
/// 开始克隆点
///
public Vector3 StartPoint;
///
/// 结束克隆点
///
public Vector3 EndPoint;
///
/// 此次克隆线的长度
///
public float LineLenght;
///
/// 结束绘制时剩余长度
///
public float RemainLenght;
public bool HasWaterConnent = false;
public GameObject WaterSource;
public long CreatFiremanID;
///
/// 记录水带在给那些物体供水,没有出水出水时,list长度为0.
/// 监听出水,物体出水时其所有水源连接的管线都要添加该物体
///
// public List SprayInfo = new List();
///
/// 该水带是否已经计算过消耗,用来防止结束点连接消防员、消防车、水源计算了消耗关闭连接管线按钮时再次计算消耗
///
public bool hascalculate;
///
/// 记录这条管线所连接的管线信息,用做捡起管线,捡起管线时如果起点不是车辆则水源信息则为消防设施
/// 获取到管线的起点实际就能获取到水源信息
///
//public List> WaterSourceConnect = new List>();
///
/// 该管线是否有水通过,用以判断该管线是否可删除,
///
// public bool HasWaterCross;
public void OnEnable()
{
//MessageDispatcher.AddListener("Delect_WaterHose", DeletedWaterHose);
MessageDispatcher.AddListener("WATERHOSEEXPEND", HoseExpend);
UsedHoseValue.getAllUsedHose += addMyLinesNumber;
}
public void OnDisable()
{
// MessageDispatcher.RemoveListener("Delect_WaterHose", DeletedWaterHose);
MessageDispatcher.RemoveListener("WATERHOSEEXPEND", HoseExpend);
UsedHoseValue.getAllUsedHose -= addMyLinesNumber;
}
public void OnDestroy()
{
//MessageDispatcher.RemoveListener("Delect_WaterHose", DeletedWaterHose);
MessageDispatcher.RemoveListener("WATERHOSEEXPEND", HoseExpend);
UsedHoseValue.getAllUsedHose -= addMyLinesNumber;
}
private void DeletedWaterHose(IMessage obj)
{
if (SelectedObjs.selectedObj == gameObject)
{
//删除的管线 连接的 消防员信息修改
if (StartHitGameObj.GetComponent())
{
StartHitGameObj.GetComponent().Resert();
}
if (EndHitGameObj.GetComponent())
{
EndHitGameObj.GetComponent().Resert();
}
//删除的管线 连接的 水炮信息修改
if (StartHitGameObj.GetComponent())
{
StartHitGameObj.GetComponent().Resert();
}
if (EndHitGameObj.GetComponent())
{
EndHitGameObj.GetComponent().Resert();
}
//删除管线连接的暴风雪炮信息修改
if (StartHitGameObj.GetComponent())
{
StartHitGameObj.GetComponent().Resert();
}
if (EndHitGameObj.GetComponent())
{
EndHitGameObj.GetComponent().Resert();
}
//删除管线时连接的灭火机器人的信息修改
if (StartHitGameObj.GetComponent())
{
StartHitGameObj.GetComponent().Resert();
}
if (EndHitGameObj.GetComponent())
{
EndHitGameObj.GetComponent().Resert();
}
//删除的管线 连接的消防车信息修改
if (StartHitGameObj.GetComponent() || EndHitGameObj.GetComponent())
{
var arg = new WaterHoseDelectCmdArgs();
arg.StartObjId = StartHitGameObj.GetComponent().gameObjID;
arg.EndObjId = EndHitGameObj.GetComponent().gameObjID;
arg.SelectHoseWater = gameObject;
MessageDispatcher.SendMessage("DelectWaterHose", arg);
// WaterHoseDestoryCommand.Instance.Execute(GetComponent().gameObjID, arg);
}
}
}
private void HoseExpend(IMessage obj)
{
var data = (WaterHoseExpend)obj.Data;
if (data.WaterHoseDraw == gameObject)
{
RemainLenght = data.ExpendNum * DefultHoseLenght - data.Distance;
}
}
///
/// 获取管线另一端连接的物体
///
///
///
public GameObject GetAnotherGameObj(GameObject oneside)
{
if (oneside == StartHitGameObj)
{
return EndHitGameObj;
}
else
{
return StartHitGameObj;
}
}
public GameObject GetAnotherGameObj(long oneside)
{
if (oneside == StartHitGameObj.GetComponent().gameObjID)
{
return EndHitGameObj;
}
else if (oneside == EndHitGameObj.GetComponent().gameObjID)
{
return StartHitGameObj;
}
else
{
Debug.LogError("同步Id有问题?");
return null;
}
}
private IntData addMyLinesNumber(IntData data)
{
int num = (int)((LineLenght + RemainLenght) / 20);
data.value += num;
return data;
}
}