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.
901 lines
35 KiB
901 lines
35 KiB
4 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System;
|
||
|
using AX.MessageSystem;
|
||
|
using System.Linq;
|
||
|
using UnityEngine.AI;
|
||
|
|
||
|
public class XiaoFangYuanDrawLine : MonoBehaviour
|
||
|
{
|
||
|
|
||
|
// Use this for initialization
|
||
|
public GameObject cloneObj;
|
||
|
public GameObject nullobject;
|
||
|
private GameObject prlineObj;
|
||
|
public GameObject Line;//管线模型
|
||
|
public GameObject Zhaomingxian;//照明线模型
|
||
|
public GameObject Guanxian;//管线模型
|
||
|
private Vector3 placementPos;//第一碰撞点
|
||
|
private Vector3 placementPos2;//第二碰撞点
|
||
|
private Vector3[] nowpath;
|
||
|
private Vector3[] newpath;
|
||
|
//private float timer = 0;
|
||
|
// private bool IsFirstPFFlag = false;//该记录的第一次寻路标志,开始记录时赋值true
|
||
|
private UnityEngine.AI.NavMeshPath NavMeshPath;
|
||
|
public List<Vector3> Allpath = new List<Vector3>();//关键点
|
||
|
public List<string> AllLine = new List<string>();//水带、照明线
|
||
|
public List<float> AllLineDistance = new List<float>();//水带长度
|
||
|
private int pointIndex = 1;
|
||
|
private bool flag;
|
||
|
float time;
|
||
|
float allLineDistance;//可用管线长度(管线总长减别人已用的长度)
|
||
|
float drawLineDistance;//已用管线长度
|
||
|
float DifferenceLine;//管线超出长度
|
||
|
private int MultipleSpeed = 1;//回放播放倍数
|
||
|
private Bag bag;
|
||
|
public int BeginLineNum;//开始铺设时水带数量
|
||
|
public int BeginLiftLineNum;//开始铺设时照明线数量
|
||
|
private float jugelength = 106f;
|
||
|
public int num;
|
||
|
private CloneGameObjInfo gameinfo;
|
||
|
void Awake()
|
||
|
{
|
||
|
|
||
|
NavMeshPath = new NavMeshPath();
|
||
|
|
||
|
//TheBackView.instance.SpeedChangeEvent += OnSpeedChangeEvent;
|
||
|
// MultipleSpeed = LoadManager.Instance.speedFactor;
|
||
|
}
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
//string name = this.name + "drawline";
|
||
|
|
||
|
//string name_ = "TeamName-drawline-Zhaomingxian-" + this.name;
|
||
|
//if (!GameObject.Find(name_))
|
||
|
//{
|
||
|
// prlineObj = Instantiate(nullobject) as GameObject;
|
||
|
// prlineObj.name = name_;
|
||
|
// prlineObj.transform.parent = GameObject.Find("P_DrawLine").transform;
|
||
|
// // prlineObj.AddComponent<DestroyObj>();//用来记录删除消防管线
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// prlineObj = GameObject.Find(name_);
|
||
|
//}
|
||
|
CreatParent();
|
||
|
bag = GetComponent<Bag>();
|
||
|
gameinfo = GetComponent<CloneGameObjInfo>();
|
||
|
}
|
||
|
void OnDestroy()
|
||
|
{
|
||
|
// Destroy(prlineObj);
|
||
|
//TheBackView.instance.SpeedChangeEvent -= OnSpeedChangeEvent;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 找到当前最靠近的Index点
|
||
|
/// </summary>
|
||
|
/// <param name="nowpath"></param>
|
||
|
/// <param name="point"></param>
|
||
|
/// <returns></returns>
|
||
|
//private int GetNearest(List<Vector3> nowpath, Vector3 point)
|
||
|
//{
|
||
|
// int index = 0;
|
||
|
// var result = (from x in nowpath
|
||
|
// select new { Key = x, Value = Vector3.Distance(point, x), Index = index++ })
|
||
|
// .OrderBy(x => x.Value).Take(Mathf.Min(1, nowpath.Count)); // 太多了,按照接近程度 take 10 个。
|
||
|
|
||
|
// index = result.ToList()[0].Index;
|
||
|
// return index;
|
||
|
//}
|
||
|
//private bool IsPointOnSegment(Vector3 Pi, Vector3 Pj, Vector3 Q)
|
||
|
//{
|
||
|
// if ((Q.x - Pi.x) * (Pj.z - Pi.z) == (Pj.x - Pi.x) * (Q.z - Pi.z) //叉乘
|
||
|
// && Mathf.Min(Pi.x, Pj.x) <= Q.x && Q.x <= Mathf.Max(Pi.x, Pj.x)//保证Q点坐标在pi,pj之间
|
||
|
// && Mathf.Min(Pi.z, Pj.z) <= Q.y && Q.y <= Mathf.Max(Pi.z, Pj.z))
|
||
|
// return true;
|
||
|
// else
|
||
|
// return false;
|
||
|
|
||
|
//}
|
||
|
// Update is called once per frame
|
||
|
void /*Fixed*/Update()
|
||
|
{
|
||
|
if (Line == null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
if (!HasLine())
|
||
|
{
|
||
|
nowpath = null;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
drawLine();
|
||
|
time += Time.deltaTime;
|
||
|
if (time >= 0.5f / MultipleSpeed)//间隔0.5秒重新规划下管线
|
||
|
{
|
||
|
time = 0.0f;
|
||
|
if (nowpath != null && pointIndex < nowpath.Length && GetComponent<UnityEngine.AI.NavMeshAgent>().velocity.magnitude > 0)//只有移动的时候需要纠正路线
|
||
|
{
|
||
|
if (Vector3.Distance(nowpath[nowpath.Length - 1], Allpath[0]) > getHaveLine())
|
||
|
changeLine(true);
|
||
|
else
|
||
|
{
|
||
|
changeLine(false);
|
||
|
}
|
||
|
}
|
||
|
else if (flag)//寻路停止后再纠正一下管线位置
|
||
|
{
|
||
|
|
||
|
changeLine(true);
|
||
|
|
||
|
flag = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
private void drawLine()
|
||
|
{
|
||
|
if (nowpath != null)
|
||
|
{
|
||
|
if (Allpath.Count == 0)
|
||
|
{
|
||
|
Allpath.Add(nowpath[0]);
|
||
|
}
|
||
|
for (int i = pointIndex; i < nowpath.Length; i++)
|
||
|
{
|
||
|
if (Vector3.Distance(transform.position, nowpath[i]) < 1.0f)
|
||
|
{
|
||
|
placementPos = nowpath[i - 1];
|
||
|
placementPos2 = nowpath[i];
|
||
|
pointIndex = i + 1;
|
||
|
|
||
|
Allpath.Add(placementPos2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
private void changeLine(bool has)
|
||
|
{
|
||
|
//float dis = Allpath.Count == 0 ? 0.0f : Vector3.Distance(transform.position, Allpath[Allpath.Count - 1]);
|
||
|
if (has)
|
||
|
{
|
||
|
if (!getDistance())
|
||
|
{
|
||
|
if (this.GetComponent<AgentController>().enabled)
|
||
|
{
|
||
|
this.GetComponent<AgentController>().StopAllCoroutines();
|
||
|
this.GetComponent<AgentController>().enabled = false;
|
||
|
this.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false;
|
||
|
|
||
|
this.transform.position = correctLine();
|
||
|
//this.GetComponent<XiaoFangYuanMessage>().positionjiuzheng = true;
|
||
|
this.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true;
|
||
|
this.GetComponent<AgentController>().enabled = true;
|
||
|
nowpath = null;//停止画线
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.GetComponent<AgentController>().enabled = true;
|
||
|
this.GetComponent<AgentController>().StopAllCoroutines();
|
||
|
this.GetComponent<AgentController>().enabled = false;
|
||
|
this.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false;
|
||
|
|
||
|
this.transform.position = correctLine();
|
||
|
//this.GetComponent<XiaoFangYuanMessage>().positionjiuzheng = true;
|
||
|
this.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true;
|
||
|
nowpath = null;//停止画线
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if (Allpath.Count == 0)
|
||
|
{
|
||
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>().velocity.magnitude > 0)
|
||
|
{
|
||
|
MessageDispatcher.SendMessage("Operatinghints", (object)"水带长度不足,请装备水带");
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
else if (Allpath.Count == 1)
|
||
|
{
|
||
|
for (int i = AllLine.Count - 1; i >= 0; i--)
|
||
|
{
|
||
|
if (GameObject.Find(AllLine[i]))
|
||
|
{
|
||
|
GameObject line = GameObject.Find(AllLine[i]);
|
||
|
Record(line.GetComponent<DrawLinMessage>(), true, false);
|
||
|
Destroy(GameObject.Find(AllLine[i]));
|
||
|
//NetworkManager.Instance.Send("ENTITY_DESTROY", AllLine[i]);
|
||
|
}
|
||
|
AllLine.RemoveAt(i);
|
||
|
//if(i< AllLineDistance.Count - 1)
|
||
|
//{
|
||
|
AllLineDistance.RemoveAt(i);
|
||
|
//}
|
||
|
}
|
||
|
NavMeshPath.ClearCorners();
|
||
|
|
||
|
try
|
||
|
{
|
||
|
//计算范围外距离最近的关键点和当前位置的平滑路径
|
||
|
UnityEngine.AI.NavMesh.CalculatePath(Allpath[0], transform.position, -1, NavMeshPath);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
System.Diagnostics.Trace.TraceError(e.Message);
|
||
|
}
|
||
|
|
||
|
//根据生成的关键点画线
|
||
|
newpath = NavMeshPath.corners;
|
||
|
for (int k = 1; k < newpath.Length; k++)
|
||
|
{
|
||
|
placementPos = newpath[k - 1];
|
||
|
placementPos2 = newpath[k];
|
||
|
Vector3 tempPos = (placementPos + placementPos2) / 2;//计算两个点的中点坐标,
|
||
|
InstanceLine(tempPos);
|
||
|
}
|
||
|
}
|
||
|
else if (Allpath.Count >= 2)
|
||
|
{
|
||
|
float dis = Vector3.Distance(transform.position, Allpath[Allpath.Count - 1]);
|
||
|
for (int i = Allpath.Count - 1; i >= 1; i--)
|
||
|
{
|
||
|
//实际有效点是 i-1
|
||
|
dis += Vector3.Distance(Allpath[i], Allpath[i - 1]);
|
||
|
|
||
|
if (dis > 10.0f)
|
||
|
{
|
||
|
//倒序删除范围内的活动关键点
|
||
|
for (int j = Allpath.Count - 1; j >= i; j--)
|
||
|
{
|
||
|
Allpath.RemoveAt(j);
|
||
|
}
|
||
|
for (int j = AllLine.Count - 1; j >= i - 1; j--)//这里分开循环是因为Allpath,AllLine的长度并不是一直相同的
|
||
|
{
|
||
|
if (GameObject.Find(AllLine[j]))
|
||
|
{
|
||
|
GameObject line = GameObject.Find(AllLine[j]);
|
||
|
Record(line.GetComponent<DrawLinMessage>(), true, false);
|
||
|
Destroy(GameObject.Find(AllLine[j]));
|
||
|
//NetworkManager.Instance.Send("ENTITY_DESTROY", AllLine[j]);
|
||
|
}
|
||
|
AllLine.RemoveAt(j);
|
||
|
//if (j < AllLineDistance.Count - 1)
|
||
|
//{
|
||
|
AllLineDistance.RemoveAt(j);
|
||
|
//}
|
||
|
}
|
||
|
NavMeshPath.ClearCorners();
|
||
|
|
||
|
try
|
||
|
{
|
||
|
//计算范围外距离最近的关键点和当前位置的平滑路径
|
||
|
UnityEngine.AI.NavMesh.CalculatePath(Allpath[i - 1], transform.position, -1, NavMeshPath);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
System.Diagnostics.Trace.TraceError(e.Message);
|
||
|
}
|
||
|
|
||
|
//根据生成的关键点画线
|
||
|
newpath = NavMeshPath.corners;
|
||
|
for (int k = 1; k < newpath.Length; k++)
|
||
|
{
|
||
|
placementPos = newpath[k - 1];
|
||
|
placementPos2 = newpath[k];
|
||
|
Vector3 tempPos = (placementPos + placementPos2) / 2;//计算两个点的中点坐标,
|
||
|
InstanceLine(tempPos);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
else if (i == 1)//从起点到现在位置都没超过限定距离
|
||
|
{
|
||
|
for (int j = Allpath.Count - 1; j > 0; j--)
|
||
|
{
|
||
|
Allpath.RemoveAt(j);//删除除起点外的所有点
|
||
|
}
|
||
|
for (int j = AllLine.Count - 1; j >= 0; j--)
|
||
|
{
|
||
|
if (GameObject.Find(AllLine[j]))
|
||
|
{
|
||
|
GameObject line = GameObject.Find(AllLine[j]);
|
||
|
Record(line.GetComponent<DrawLinMessage>(), true, false);
|
||
|
Destroy(GameObject.Find(AllLine[j]));
|
||
|
//NetworkManager.Instance.Send("ENTITY_DESTROY", AllLine[j]);
|
||
|
}
|
||
|
AllLine.RemoveAt(j);//删除所有线
|
||
|
//if (j < AllLineDistance.Count - 1)
|
||
|
//{
|
||
|
AllLineDistance.RemoveAt(j);
|
||
|
//}
|
||
|
}
|
||
|
NavMeshPath.ClearCorners();
|
||
|
|
||
|
try
|
||
|
{
|
||
|
//计算范围外距离最近的关键点和当前位置的平滑路径
|
||
|
UnityEngine.AI.NavMesh.CalculatePath(Allpath[0], transform.position, -1, NavMeshPath);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
System.Diagnostics.Trace.TraceError(e.Message);
|
||
|
}
|
||
|
|
||
|
//根据生成的关键点画线
|
||
|
newpath = NavMeshPath.corners;
|
||
|
for (int k = 1; k < newpath.Length; k++)
|
||
|
{
|
||
|
placementPos = newpath[k - 1];
|
||
|
placementPos2 = newpath[k];
|
||
|
Vector3 tempPos = (placementPos + placementPos2) / 2;//计算两个点的中点坐标
|
||
|
InstanceLine(tempPos);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
setLineXiaoHao();
|
||
|
}
|
||
|
public void setLine()
|
||
|
{
|
||
|
BeginLineNum = bag.GetEquipNum("消防高压水带");
|
||
|
BeginLiftLineNum = bag.GetEquipNum("救生照明线");
|
||
|
var work = GetComponent<FireManMessage>().workType;
|
||
|
if (work == FireManSkills.LayWaterHose || work == FireManSkills.SprayFoam ||
|
||
|
work == FireManSkills.SprayWater || work == FireManSkills.Decontamination)
|
||
|
{
|
||
|
if (BeginLineNum <= 0)
|
||
|
{
|
||
|
if (!RecordEvent.IsReplay())
|
||
|
{
|
||
|
ResourceLoadWindow.Instance.LoadTextHintWindow("水带数量不足", 0.5f);
|
||
|
FireManSkillsPanel.GetInstance.CloselayhoseToggle();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
Line = Guanxian;
|
||
|
}
|
||
|
else if (work == FireManSkills.LayLifeSavingFlarePath)
|
||
|
{
|
||
|
if (BeginLiftLineNum <= 0)
|
||
|
{
|
||
|
if (!RecordEvent.IsReplay())
|
||
|
{
|
||
|
ResourceLoadWindow.Instance.LoadTextHintWindow("救生照明线数量不足", 0.5f);
|
||
|
FireManSkillsPanel.GetInstance.CloseLayLiftToggle();
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
Line = Zhaomingxian;
|
||
|
}
|
||
|
|
||
|
////如果重新开始铺设,前一段没有设为结束段,将其设为结束段(出现在录制之前没有结束,继续铺设)
|
||
|
//if (prlineObj.transform.childCount > 0)
|
||
|
//{
|
||
|
// DrawLinMessage mess = prlineObj.transform.GetChild(prlineObj.transform.childCount - 1).GetComponent<DrawLinMessage>();
|
||
|
// if (!mess.Recorddata.IsEndDraw)
|
||
|
// {
|
||
|
// mess.Recorddata.IsEndDraw = true;
|
||
|
// }
|
||
|
//}
|
||
|
}
|
||
|
public void setPath(Vector3[] path)
|
||
|
{
|
||
|
//setLine();
|
||
|
// Debug.Log(Line.name);
|
||
|
nowpath = path;
|
||
|
pointIndex = 1;
|
||
|
flag = true;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 判断是否携带了管线和照明线
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public bool HasLine()
|
||
|
{
|
||
|
float disLine = 0.0f;//携带管线长
|
||
|
float disZhaoMingXian = 0.0f;//携带照明线长
|
||
|
disLine = BeginLineNum * EquipSelect.GetInstance.DrawLineLength;
|
||
|
disZhaoMingXian = BeginLiftLineNum * EquipSelect.GetInstance.LiftLightLength;
|
||
|
//List<GameObject> AllMembers = this.GetComponent<XiaoFangYuanToShiNei>().AllMembers;
|
||
|
//List<GameObject> AllMembers = InputManager.Instance_.GetSelectedCharacters();
|
||
|
//List<GameObject> AllMembers = GetComponent<AgentRecord>().xfyList;
|
||
|
//for (int i = 0; i < AllMembers.Count; i++)
|
||
|
//{
|
||
|
// obj = AllMembers[i];
|
||
|
// if (obj && obj.name.Contains("xiaofangyuan"))
|
||
|
// {
|
||
|
// disLine += obj.GetComponent<XiaoFangYuanDrawLine>().getHaveLine();
|
||
|
// disZhaoMingXian += obj.GetComponent<XiaoFangYuanDrawLine>().getHaveZhaoMingXian();
|
||
|
// }
|
||
|
//}
|
||
|
if (Line.name.Equals(Guanxian.name))
|
||
|
{
|
||
|
if (disLine < 0.5f)
|
||
|
{
|
||
|
//ResourceLoadWindow.Instance.LoadTextHintWindow("水带不足", 0.5f);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
else if (Line.name.Equals(Zhaomingxian.name))
|
||
|
{
|
||
|
if (disZhaoMingXian < 0.5f)
|
||
|
{
|
||
|
//ResourceLoadWindow.Instance.LoadTextHintWindow("救生照明线不足", 0.5f);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 判断消防员携带水带是否还有剩余
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
private bool getDistance()
|
||
|
{
|
||
|
bool flag = true;
|
||
|
allLineDistance = getAllLine();
|
||
|
drawLineDistance = getDrawLine();
|
||
|
if (allLineDistance < 0)//allLineDistance < drawLineDistance
|
||
|
{//可用管线<0
|
||
|
flag = false;
|
||
|
//DifferenceLine = drawLineDistance - allLineDistance;//超出可用范围长度
|
||
|
DifferenceLine = Mathf.Abs(allLineDistance);//超出可用范围长度
|
||
|
|
||
|
}
|
||
|
return flag;
|
||
|
}
|
||
|
//获取该消防员可用的管线、照明线长度
|
||
|
private float getAllLine()
|
||
|
{
|
||
|
float dis = 0.0f;
|
||
|
float disLine = 0.0f;//携带管线长
|
||
|
float disZhaoMingXian = 0.0f;//携带照明线长
|
||
|
float disDraw = 0.0f;//已用长度
|
||
|
//GameObject obj;
|
||
|
//List<GameObject> AllMembers = this.GetComponent<XiaoFangYuanToShiNei>().AllMembers;
|
||
|
//for (int i = 0; i < AllMembers.Count; i++)
|
||
|
//{
|
||
|
// obj = AllMembers[i];
|
||
|
// disLine += obj.GetComponent<XiaoFangYuanDrawLine>().getHaveLine();
|
||
|
// disZhaoMingXian += obj.GetComponent<XiaoFangYuanDrawLine>().getHaveZhaoMingXian();
|
||
|
// disDraw += obj.GetComponent<XiaoFangYuanDrawLine>().getDrawLine();
|
||
|
//}
|
||
|
disLine += getHaveLine();
|
||
|
disZhaoMingXian += getHaveZhaoMingXian();
|
||
|
disDraw += getDrawLine();
|
||
|
//dis = disLine > disZhaoMingXian ? disZhaoMingXian : disLine;//取最短值作为管线可用长度
|
||
|
//dis -= disDraw;
|
||
|
//dis += this.GetComponent<XiaoFangYuanDrawLine>().getDrawLine();
|
||
|
|
||
|
//if (dis>getHaveZhaoMingXian())
|
||
|
//{
|
||
|
// dis = getHaveZhaoMingXian();
|
||
|
// MessageDispatcher.SendMessage("Operatinghints", (object)"水带长度不足,请装备水带");
|
||
|
//}
|
||
|
//Debug.Log("可用照明线长度为:" + dis+"携带照明线的长度为:"+getHaveZhaoMingXian());
|
||
|
if (Line.name.Equals(Guanxian.name))
|
||
|
{
|
||
|
dis = disLine - disDraw;
|
||
|
}
|
||
|
else if (Line.name.Equals(Zhaomingxian.name))
|
||
|
{
|
||
|
dis = disZhaoMingXian - disDraw;
|
||
|
}
|
||
|
return dis;
|
||
|
}
|
||
|
//获取该消防员已用的管线长度
|
||
|
public float getDrawLine()
|
||
|
{
|
||
|
float dis = 0.0f;
|
||
|
if (AllLineDistance.Count > 0)
|
||
|
{
|
||
|
for (int i = 0; i < AllLineDistance.Count; i++)
|
||
|
{
|
||
|
dis += AllLineDistance[i];
|
||
|
}
|
||
|
}
|
||
|
return dis;
|
||
|
}
|
||
|
//获取该消防员携带的管线长度
|
||
|
public float getHaveLine()
|
||
|
{
|
||
|
float dis = 0.0f;
|
||
|
//Dictionary<string, CostEquip> costSelectedEquips = this.GetComponent<Bag>().costSelectedEquips;
|
||
|
//foreach (var item in costSelectedEquips)
|
||
|
//{
|
||
|
// if (item.Key.Contains("消防高压水带"))
|
||
|
// {
|
||
|
// dis = item.Value.selectedEquipNum * item.Value.unit;
|
||
|
// }
|
||
|
//}
|
||
|
dis = BeginLineNum * EquipSelect.GetInstance.DrawLineLength;
|
||
|
return dis;
|
||
|
}
|
||
|
//获取该消防员携带的照明线长度
|
||
|
public float getHaveZhaoMingXian()
|
||
|
{
|
||
|
float dis = 0.0f;
|
||
|
//Dictionary<string, CostEquip> costSelectedEquips = this.GetComponent<Bag>().costSelectedEquips;
|
||
|
//foreach (var item in costSelectedEquips)
|
||
|
//{
|
||
|
// if (item.Key.Contains("救生照明线"))
|
||
|
// {
|
||
|
// dis = item.Value.selectedEquipNum * item.Value.unit;
|
||
|
// }
|
||
|
//}
|
||
|
dis = BeginLiftLineNum * EquipSelect.GetInstance.LiftLightLength;
|
||
|
return dis;
|
||
|
}
|
||
|
//管线超出可用管线范围纠正方法
|
||
|
private Vector3 correctLine()
|
||
|
{
|
||
|
//int k = 0;
|
||
|
Vector3 pos = new Vector3();
|
||
|
float dis = 0;
|
||
|
for (int i = AllLineDistance.Count - 1; i >= 0; i--)
|
||
|
{
|
||
|
//倒序找出应该回退到第几条线上
|
||
|
dis += AllLineDistance[i];
|
||
|
if (dis >= DifferenceLine)
|
||
|
// if (dis >= getAllLine())
|
||
|
{
|
||
|
float ab = dis - DifferenceLine;
|
||
|
//float ab = dis - getAllLine();
|
||
|
float x = Allpath[i].x + (Allpath[i + 1].x - Allpath[i].x) * ab / AllLineDistance[i];
|
||
|
float y = Allpath[i].y + (Allpath[i + 1].y - Allpath[i].y) * ab / AllLineDistance[i];
|
||
|
float z = Allpath[i].z + (Allpath[i + 1].z - Allpath[i].z) * ab / AllLineDistance[i];
|
||
|
pos = new Vector3(x, y, z);//算出回退后消防员所在位置
|
||
|
//倒序删除多出的关键点和线
|
||
|
for (int j = Allpath.Count - 1; j >= i + 1; j--)
|
||
|
{
|
||
|
Allpath.RemoveAt(j);
|
||
|
}
|
||
|
for (int j = AllLine.Count - 1; j >= i; j--)//这里分开循环是因为Allpath,AllLine的长度并不是一直相同的
|
||
|
{
|
||
|
if (GameObject.Find(AllLine[j]))
|
||
|
{
|
||
|
GameObject line = GameObject.Find(AllLine[j]);
|
||
|
Record(line.GetComponent<DrawLinMessage>(), true, false);
|
||
|
Destroy(GameObject.Find(AllLine[j]));
|
||
|
//NetworkManager.Instance.Send("ENTITY_DESTROY", AllLine[j]);
|
||
|
}
|
||
|
AllLine.RemoveAt(j);
|
||
|
//if(j< AllLineDistance.Count - 1)
|
||
|
//{
|
||
|
AllLineDistance.RemoveAt(j);
|
||
|
//}
|
||
|
}
|
||
|
//将删除后最后一个点和消防员新位置连点成线
|
||
|
placementPos = Allpath[i];
|
||
|
placementPos2 = pos;
|
||
|
Vector3 tempPos = (placementPos + placementPos2) / 2;//计算两个点的中点坐标
|
||
|
InstanceLine(tempPos);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return pos;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 消耗为0时,执行该方法即可将消耗重置,已使用数量标记为0
|
||
|
/// 消耗不为0时,即为计算消耗
|
||
|
/// </summary>
|
||
|
private void setLineXiaoHao()
|
||
|
{
|
||
|
float dis = 0.0f;
|
||
|
float disLine = 0.0f;//管线长
|
||
|
float disZhaoMingXian = 0.0f;//照明线长
|
||
|
|
||
|
dis += getDrawLine();
|
||
|
if (Line.name.Equals(Guanxian.name))
|
||
|
{
|
||
|
disLine = dis;
|
||
|
}
|
||
|
else if (Line.name.Equals(Zhaomingxian.name))
|
||
|
{
|
||
|
disZhaoMingXian = dis;
|
||
|
}
|
||
|
if (Line.name.Equals(Guanxian.name))
|
||
|
{
|
||
|
int useNum = 0;
|
||
|
if (disLine >= BeginLineNum * EquipSelect.GetInstance.DrawLineLength)
|
||
|
//如果消耗管线总数大于此人选择的管线,那么此人管线全部标记为已消耗,再从下一个人身上继续扣除
|
||
|
{
|
||
|
useNum = BeginLineNum;
|
||
|
bag.SetEquipNum("消防高压水带", 0);
|
||
|
disLine -= BeginLineNum * EquipSelect.GetInstance.DrawLineLength;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//如果剩余消耗管线总数小于此人选择的管线,那么此人管线向上取整标记为已消耗,无需再从下一个人身上继续扣除了
|
||
|
useNum = (int)Math.Ceiling(disLine / EquipSelect.GetInstance.DrawLineLength);//向上取整
|
||
|
bag.SetEquipNum("消防高压水带", BeginLineNum - useNum);
|
||
|
disLine = 0.0f;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else if (Line.name.Equals(Zhaomingxian.name))
|
||
|
{
|
||
|
|
||
|
int useNum = 0;
|
||
|
if (disZhaoMingXian >= BeginLiftLineNum * EquipSelect.GetInstance.LiftLightLength)
|
||
|
{
|
||
|
useNum = BeginLiftLineNum;
|
||
|
bag.SetEquipNum("救生照明线", 0);
|
||
|
disZhaoMingXian -= BeginLiftLineNum * EquipSelect.GetInstance.LiftLightLength;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
useNum = (int)Math.Ceiling(disZhaoMingXian / EquipSelect.GetInstance.LiftLightLength);//向上取整
|
||
|
bag.SetEquipNum("救生照明线", BeginLiftLineNum - useNum);
|
||
|
disZhaoMingXian = 0.0f;
|
||
|
}
|
||
|
}
|
||
|
// Line.GetComponent<DrawLinMessage>().length = dis;
|
||
|
#region 组消耗
|
||
|
|
||
|
//for (int i = 0; i < AllMembers.Count; i++)//按照顺序将消耗分配给成员
|
||
|
//{
|
||
|
// obj = AllMembers[i];
|
||
|
// Dictionary<string, CostEquip> costSelectedEquips = obj.GetComponent<Bag>().costSelectedEquips;
|
||
|
// foreach (var item in costSelectedEquips)
|
||
|
// {
|
||
|
// if (item.Key.Contains("消防高压水带"))
|
||
|
// {
|
||
|
// item.Value.useNum = 0;
|
||
|
// if (disLine >= item.Value.selectedEquipNum * item.Value.unit)
|
||
|
// //如果消耗管线总数大于此人选择的管线,那么此人管线全部标记为已消耗,再从下一个人身上继续扣除
|
||
|
// {
|
||
|
// item.Value.useNum = item.Value.selectedEquipNum;
|
||
|
// disLine -= item.Value.selectedEquipNum * item.Value.unit;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// //如果剩余消耗管线总数小于此人选择的管线,那么此人管线向上取整标记为已消耗,无需再从下一个人身上继续扣除了
|
||
|
// item.Value.useNum =(int) Math.Ceiling(disLine / item.Value.unit);//向上取整
|
||
|
// disLine = 0.0f;
|
||
|
// }
|
||
|
// }
|
||
|
// else if (item.Key.Contains("救生照明线"))
|
||
|
// {
|
||
|
// item.Value.useNum = 0;
|
||
|
// if (disZhaoMingXian >= item.Value.selectedEquipNum * item.Value.unit)
|
||
|
// {
|
||
|
// item.Value.useNum = item.Value.selectedEquipNum;
|
||
|
// disZhaoMingXian -= item.Value.selectedEquipNum * item.Value.unit;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// item.Value.useNum = (int)Math.Ceiling(disZhaoMingXian / item.Value.unit);//向上取整
|
||
|
// disZhaoMingXian = 0.0f;
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
public void DelectAllLine()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
//收起管线
|
||
|
public void destoryLine()
|
||
|
{
|
||
|
// changeLine();
|
||
|
//setLineXiaoHao();
|
||
|
FireManMessage mess = GetComponent<FireManMessage>();
|
||
|
//GetComponent<XiaoFangYuanDrawLine>().setLine();
|
||
|
if (mess.workType == FireManSkills.LayLifeSavingFlarePath ||
|
||
|
mess.workType == FireManSkills.LayWaterHose ||
|
||
|
mess.workType == FireManSkills.SprayFoam ||
|
||
|
mess.workType == FireManSkills.SprayWater ||
|
||
|
mess.workType == FireManSkills.Decontamination)
|
||
|
{
|
||
|
ResourceLoadWindow.Instance.LoadTextHintWindow("请先停止出水或者铺设", 0.5f);
|
||
|
return;
|
||
|
}
|
||
|
//装备添加
|
||
|
//收起管线时,实例化的管线中的DrawLinMessage的Recorddata为IsEndDraw的即为该段铺设的结束
|
||
|
int linenum = 0;
|
||
|
int liftlinenum = 0;
|
||
|
List<Equip> linelist = new List<Equip>();
|
||
|
if (prlineObj.transform.childCount > 0)
|
||
|
{
|
||
|
for (int i = 0; i < prlineObj.transform.childCount; i++)
|
||
|
{
|
||
|
|
||
|
// float linelength = 0;
|
||
|
//float liftlinelength = 0;
|
||
|
Transform line = prlineObj.transform.GetChild(i);
|
||
|
if (line.GetComponent<DrawLinMessage>().Recorddata.IsEndDraw)
|
||
|
{
|
||
|
if (line.GetComponent<CloneGameObjInfo>().gameObjType == CloneObjType.DrawLine)
|
||
|
{
|
||
|
//linelength += line.GetComponent<DrawLinMessage>().length;
|
||
|
linenum += Mathf.CeilToInt(line.GetComponent<DrawLinMessage>().AllLength / EquipSelect.GetInstance.DrawLineLength);
|
||
|
}
|
||
|
else if (line.GetComponent<CloneGameObjInfo>().gameObjType == CloneObjType.LiftLightLine)
|
||
|
{
|
||
|
liftlinenum += Mathf.CeilToInt(line.GetComponent<DrawLinMessage>().AllLength / EquipSelect.GetInstance.LiftLightLength);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Record(line.GetComponent<DrawLinMessage>(), true, false);
|
||
|
Destroy(line.gameObject);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
Equip Drawline = EquipSelect.GetInstance.GetInitEquipByName("消防高压水带");
|
||
|
Drawline.Number = linenum;
|
||
|
linelist.Add(Drawline);
|
||
|
Equip liftline = EquipSelect.GetInstance.GetInitEquipByName("救生照明线");
|
||
|
liftline.Number = liftlinenum;
|
||
|
linelist.Add(liftline);
|
||
|
bag.EquipAdd(linelist);
|
||
|
//数据重置
|
||
|
BeginLineNum = 0;
|
||
|
BeginLiftLineNum = 0;
|
||
|
Allpath.Clear();
|
||
|
AllLine.Clear();
|
||
|
AllLineDistance.Clear();
|
||
|
nowpath = null;
|
||
|
}
|
||
|
public void EndDraw()
|
||
|
{
|
||
|
if (cloneObj == null)
|
||
|
{//回放之前铺设了管线,但是没有停止铺设,回访结束初始化之后将新生成的最后一段管线设置为cloneObj
|
||
|
if (prlineObj.transform.childCount > 0)
|
||
|
{
|
||
|
cloneObj = prlineObj.transform.GetChild(prlineObj.transform.childCount - 1).gameObject;
|
||
|
}
|
||
|
}
|
||
|
if (cloneObj != null)
|
||
|
{
|
||
|
//cloneObj.GetComponent<DrawLinMessage>().AllLength = getDrawLine();
|
||
|
setLineXiaoHao();
|
||
|
Record(cloneObj.GetComponent<DrawLinMessage>(), true, true);
|
||
|
//cloneObj.name += "-endLine";
|
||
|
Allpath.Clear();
|
||
|
AllLine.Clear();
|
||
|
AllLineDistance.Clear();
|
||
|
nowpath = null;
|
||
|
//BeginLineNum = 0;
|
||
|
//BeginLiftLineNum = 0;
|
||
|
//Line = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//private void OnSpeedChangeEvent(SpeedChangeEventArgs e)
|
||
|
//{
|
||
|
// if (e.speed == 0)
|
||
|
// return;
|
||
|
// MultipleSpeed = e.speed;
|
||
|
//}
|
||
|
private void SetCloneInfo(GameObject game)
|
||
|
{
|
||
|
|
||
|
if (game.GetComponent<CloneGameObjInfo>())
|
||
|
{
|
||
|
game.GetComponent<CloneGameObjInfo>().buildNum = gameObject.GetComponent<CloneGameObjInfo>().buildNum;
|
||
|
game.GetComponent<CloneGameObjInfo>().floorNum = gameObject.GetComponent<CloneGameObjInfo>().floorNum;
|
||
|
game.GetComponent<CloneGameObjInfo>().interlayerNum = gameObject.GetComponent<CloneGameObjInfo>().interlayerNum;
|
||
|
game.name = gameObject.name + "-" + game.GetComponent<CloneGameObjInfo>().gameObjType + "-" + num;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 克隆管线并赋值信息
|
||
|
/// </summary>
|
||
|
/// <param name="tempPos"></param>
|
||
|
private void InstanceLine(Vector3 tempPos)
|
||
|
{
|
||
|
num++;
|
||
|
cloneObj = Instantiate(Line, tempPos, Quaternion.identity) as GameObject;
|
||
|
SetCloneInfo(cloneObj);
|
||
|
cloneObj.transform.parent = prlineObj.transform;
|
||
|
cloneObj.transform.forward = (cloneObj.transform.position - placementPos).normalized;//改变线条的朝向
|
||
|
float distance = Vector3.Distance(placementPos, placementPos2);//计算两点的距离
|
||
|
cloneObj.transform.localScale = new Vector3(6f, 6f, distance * jugelength);//延长线条,连接两点。
|
||
|
cloneObj.GetComponent<DrawLinMessage>().Linelength = distance;
|
||
|
cloneObj.GetComponent<DrawLinMessage>().AllLength = getDrawLine() + distance;
|
||
|
Record(cloneObj.GetComponent<DrawLinMessage>(), false, true);
|
||
|
Allpath.Add(placementPos2);
|
||
|
AllLine.Add(cloneObj.name);
|
||
|
AllLineDistance.Add(distance);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 克隆/删除/放下管线 事件记录
|
||
|
/// </summary>
|
||
|
/// <param name="mess"></param>
|
||
|
/// <param name="IsEndDraw"></param>
|
||
|
/// <param name="IsCreat"></param>
|
||
|
public void Record(DrawLinMessage mess, bool IsEndDraw, bool IsCreat)
|
||
|
{
|
||
|
DrawLineRecordData data = new DrawLineRecordData();
|
||
|
data.myTransform.setMyPosition(mess.transform.localPosition);
|
||
|
data.myTransform.setMyRotation(mess.transform.localRotation);
|
||
|
data.myTransform.setMyScale(mess.transform.localScale);
|
||
|
data.objectName = mess.name;
|
||
|
data.gameObjType = mess.GetComponent<CloneGameObjInfo>().gameObjType;
|
||
|
data.IsCreat = true;
|
||
|
data.linelength = mess.Linelength;
|
||
|
data.alllength = mess.AllLength;
|
||
|
data.floorNum = gameinfo.floorNum;
|
||
|
data.buildNum = gameinfo.buildNum;
|
||
|
data.interlayerNum = gameinfo.interlayerNum;
|
||
|
data.parentobjname = mess.transform.parent.name;
|
||
|
data.clonepos = mess.transform.position;
|
||
|
data.IsEndDraw = IsEndDraw;
|
||
|
data.IsCreat = IsCreat;
|
||
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
|
||
|
{
|
||
|
var eventData = new EventData();
|
||
|
eventData.time = RecordManager.Instance.RecordTimer;
|
||
|
eventData.cloneObjType = CloneObjType.None;
|
||
|
eventData.eventType = RecordEventType.DrawLine;
|
||
|
string json = JsonUtility.ToJson(data);
|
||
|
eventData.json = json;
|
||
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
|
||
|
}
|
||
|
if (IsCreat)
|
||
|
{
|
||
|
mess.Recorddata = data;
|
||
|
}
|
||
|
}
|
||
|
public List<DrawLineRecordData> GetmessageList()
|
||
|
{
|
||
|
List<DrawLineRecordData> list = new List<DrawLineRecordData>();
|
||
|
for (int i = 0; i < prlineObj.transform.childCount; i++)
|
||
|
{
|
||
|
list.Add(prlineObj.transform.GetChild(i).GetComponent<DrawLinMessage>().Recorddata);
|
||
|
}
|
||
|
return list;
|
||
|
}
|
||
|
public void RecordInit()
|
||
|
{
|
||
|
CreatParent();
|
||
|
if (prlineObj)
|
||
|
{
|
||
|
if (prlineObj.transform.childCount > 0)
|
||
|
{
|
||
|
for (int i = 0; i < prlineObj.transform.childCount; i++)
|
||
|
{
|
||
|
Destroy(prlineObj.transform.GetChild(i).gameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public void CreatParent()
|
||
|
{
|
||
|
|
||
|
string name_ = "drawline-" + this.name;
|
||
|
if (!GameObject.Find(name_))
|
||
|
{
|
||
|
prlineObj = Instantiate(nullobject) as GameObject;
|
||
|
prlineObj.name = name_;
|
||
|
prlineObj.transform.parent = GameObject.Find("P_DrawLine").transform;
|
||
|
// prlineObj.AddComponent<DestroyObj>();//用来记录删除消防管线
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
prlineObj = GameObject.Find(name_);
|
||
|
}
|
||
|
}
|
||
|
}
|