Browse Source

人员定位基站楼梯数据改为可以配置,重新烘培可以寻路楼层

develop
杨栋梁 9 months ago
parent
commit
e245b778e7
  1. 40
      Assets/LongZhiMeng/Prefab/ShiNei/nei-4.prefab
  2. 64
      Assets/LongZhiMeng/Prefab/ShiNei/nei-5.prefab
  3. BIN
      Assets/Scenes/MainScene/NavMesh-NavmeshSurface.asset
  4. 2
      Assets/Scripts/ANet/DeviceInfo.cs
  5. 2
      Assets/Scripts/ANet/DeviceItem.cs
  6. 36
      Assets/Scripts/ANet/DevicePanelManager.cs
  7. 153
      Assets/Scripts/ANet/PathFinding.cs
  8. 1
      Assets/Scripts/ANet/Prefabs/PathParent.prefab
  9. 4
      Assets/Scripts/Common/GameManager.cs
  10. 166
      Assets/Scripts/Main/Core/PersonnelLocation/LocationSimulator.cs
  11. 32
      Assets/Scripts/Manager/Config.cs
  12. 80
      Assets/StreamingAssets/Config.json

40
Assets/LongZhiMeng/Prefab/ShiNei/nei-4.prefab

@ -222,6 +222,7 @@ GameObject:
- component: {fileID: 8584423289966022819}
- component: {fileID: 4195963300943409128}
- component: {fileID: 4810315757957476332}
- component: {fileID: 14652159}
m_Layer: 9
m_Name: B4_Wall
m_TagString: Untagged
@ -319,6 +320,22 @@ MonoBehaviour:
floorId: -4
Equipment: 1
Power: 0
--- !u!114 &14652159
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 119984582534650853}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e3fdca004f2d45fe8abbed571a8abd5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_OverrideArea: 1
m_Area: 1
m_IgnoreFromBuild: 0
m_AffectedAgents: ffffffff
--- !u!1 &209440485209016414
GameObject:
m_ObjectHideFlags: 0
@ -442,7 +459,7 @@ GameObject:
- component: {fileID: 2067132798867395836}
- component: {fileID: 8689927616693301956}
- component: {fileID: 562145195400314680}
m_Layer: 9
m_Layer: 15
m_Name: LT65
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -5609,7 +5626,8 @@ GameObject:
- component: {fileID: 934963594617800395}
- component: {fileID: 177236123263773353}
- component: {fileID: 7355402753908917952}
m_Layer: 9
- component: {fileID: 14652160}
m_Layer: 14
m_Name: B4_CZZ
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -5706,6 +5724,22 @@ MonoBehaviour:
floorId: -4
Equipment: 1
Power: 0
--- !u!114 &14652160
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4171047506936287241}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e3fdca004f2d45fe8abbed571a8abd5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_OverrideArea: 1
m_Area: 1
m_IgnoreFromBuild: 0
m_AffectedAgents: ffffffff
--- !u!1 &4272724551034702147
GameObject:
m_ObjectHideFlags: 0
@ -12323,7 +12357,7 @@ GameObject:
- component: {fileID: 3289255703497826919}
- component: {fileID: 2420374136501766312}
- component: {fileID: 8635361495682100554}
m_Layer: 9
m_Layer: 14
m_Name: B4_Floor
m_TagString: Untagged
m_Icon: {fileID: 0}

64
Assets/LongZhiMeng/Prefab/ShiNei/nei-5.prefab

@ -1009,7 +1009,7 @@ GameObject:
- component: {fileID: 8736513398244836139}
- component: {fileID: 3076020743435447431}
- component: {fileID: 2883135339924689476}
m_Layer: 15
m_Layer: 0
m_Name: LT80
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -1639,7 +1639,7 @@ GameObject:
- component: {fileID: 8270513691876896516}
- component: {fileID: 5796460198407872174}
- component: {fileID: 2856167908211855524}
m_Layer: 15
m_Layer: 0
m_Name: LT79
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -2470,7 +2470,7 @@ GameObject:
- component: {fileID: 6292780013325109327}
- component: {fileID: 5710179564857778156}
- component: {fileID: 6761258167639674638}
m_Layer: 15
m_Layer: 0
m_Name: LT85
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -3518,7 +3518,7 @@ GameObject:
- component: {fileID: 4065088276986826924}
- component: {fileID: 4920687918572847181}
- component: {fileID: 8253019813129201132}
m_Layer: 15
m_Layer: 0
m_Name: LT81
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -3916,7 +3916,7 @@ GameObject:
- component: {fileID: 8849098653514059089}
- component: {fileID: 3769855221563518552}
- component: {fileID: 6044842954695581892}
m_Layer: 15
m_Layer: 0
m_Name: LT78
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -6296,6 +6296,7 @@ GameObject:
- component: {fileID: 4522333918780490830}
- component: {fileID: 3807230240899696989}
- component: {fileID: 4767787978474937656}
- component: {fileID: 1119978510}
m_Layer: 9
m_Name: B5_Wall
m_TagString: Untagged
@ -6393,6 +6394,22 @@ MonoBehaviour:
floorId: -5
Equipment: 1
Power: 0
--- !u!114 &1119978510
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3785181585580920066}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e3fdca004f2d45fe8abbed571a8abd5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_OverrideArea: 1
m_Area: 1
m_IgnoreFromBuild: 0
m_AffectedAgents: ffffffff
--- !u!1 &3934912049478156772
GameObject:
m_ObjectHideFlags: 0
@ -7265,7 +7282,7 @@ GameObject:
- component: {fileID: 4706818223685031804}
- component: {fileID: 2867885534027382574}
- component: {fileID: 7385417565108069315}
m_Layer: 15
m_Layer: 0
m_Name: LT82
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -7470,7 +7487,7 @@ GameObject:
- component: {fileID: 6698358921822060760}
- component: {fileID: 190428641712663357}
- component: {fileID: 1979830499400582886}
m_Layer: 15
m_Layer: 0
m_Name: LT76
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -8923,7 +8940,8 @@ GameObject:
- component: {fileID: 6507526558448951548}
- component: {fileID: 6736370099691725976}
- component: {fileID: 6407090298382525831}
m_Layer: 9
- component: {fileID: 1119978511}
m_Layer: 14
m_Name: B5_CZZ
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -9020,6 +9038,22 @@ MonoBehaviour:
floorId: -5
Equipment: 1
Power: 0
--- !u!114 &1119978511
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5086016180840526747}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e3fdca004f2d45fe8abbed571a8abd5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_OverrideArea: 1
m_Area: 1
m_IgnoreFromBuild: 0
m_AffectedAgents: ffffffff
--- !u!1 &5278901334673207475
GameObject:
m_ObjectHideFlags: 0
@ -10152,7 +10186,7 @@ GameObject:
- component: {fileID: 5606630640673256000}
- component: {fileID: 3336034004680812250}
- component: {fileID: 8373291608014601901}
m_Layer: 15
m_Layer: 0
m_Name: LT86
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -10601,7 +10635,7 @@ GameObject:
- component: {fileID: 7713560582214749036}
- component: {fileID: 2777961242466473191}
- component: {fileID: 8395288681916190803}
m_Layer: 15
m_Layer: 0
m_Name: LT77
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -11871,7 +11905,7 @@ GameObject:
- component: {fileID: 6687785829109330241}
- component: {fileID: 1696386882297568433}
- component: {fileID: 2639579858283849929}
m_Layer: 15
m_Layer: 0
m_Name: LT83
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -12919,7 +12953,7 @@ GameObject:
- component: {fileID: 8453793314049793078}
- component: {fileID: 7903395092938916131}
- component: {fileID: 7059810689048243568}
m_Layer: 9
m_Layer: 14
m_Name: B5_Floor
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -13317,7 +13351,7 @@ GameObject:
- component: {fileID: 4133104752455562498}
- component: {fileID: 7568392748715444118}
- component: {fileID: 8091224218162497660}
m_Layer: 15
m_Layer: 0
m_Name: LT87
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -13557,7 +13591,7 @@ GameObject:
- component: {fileID: 1025057594082597017}
- component: {fileID: 2356675421490092156}
- component: {fileID: 7897323096907996761}
m_Layer: 15
m_Layer: 0
m_Name: LT84
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -14393,7 +14427,7 @@ GameObject:
- component: {fileID: 5483656822029382327}
- component: {fileID: 150361346221733946}
- component: {fileID: 4315962088187642190}
m_Layer: 15
m_Layer: 0
m_Name: LT88
m_TagString: Untagged
m_Icon: {fileID: 0}

BIN
Assets/Scenes/MainScene/NavMesh-NavmeshSurface.asset

Binary file not shown.

2
Assets/Scripts/ANet/DeviceInfo.cs

@ -24,6 +24,8 @@ public class DeviceInfo : MonoBehaviour
}
public void OnShow(DeviceList info)
{
if (info.deviceNo == null)
return;
infoName.text = "设备信息";
bindInfo = info;

2
Assets/Scripts/ANet/DeviceItem.cs

@ -35,7 +35,7 @@ public class DeviceItem : MonoBehaviour
public void DataBind(DeviceList bindData, Color showColor)
{
BindData = bindData;
ShowText.text = bindData.deviceName;
ShowText.text = bindData.deviceName + bindData.descript;
LocalBtn.image.color = showColor;
}
private void ViewBtn_Click()

36
Assets/Scripts/ANet/DevicePanelManager.cs

@ -353,9 +353,10 @@ public class DevicePanelManager : MonoBehaviour
{
if (!EventSystem.current.IsPointerOverGameObject())
{
if (Input.GetMouseButtonDown(0) && hit.collider.GetComponent<InstantiateData>())
int floorid = GetFloorId(hit.transform);
if (Input.GetMouseButtonDown(0) && floorid != 0)
{
CreatePoint(hit.point, hit.collider.GetComponent<InstantiateData>().floorId);
CreatePoint(hit.point, floorid);
}
}
if (Input.GetMouseButtonDown(1))
@ -376,6 +377,37 @@ public class DevicePanelManager : MonoBehaviour
}
}
}
private int GetFloorId(Transform obj)
{
if (obj.GetComponent<InstantiateData>())
{
return obj.GetComponent<InstantiateData>().floorId;
}
else
{
if (obj.parent != null)
{
foreach (Transform child in obj.parent)
{
if (child.GetComponent<InstantiateData>())
{
return child.GetComponent<InstantiateData>().floorId;
}
}
}
if (obj.parent.parent != null)
{
foreach (Transform child in obj.parent.parent)
{
if (child.GetComponent<InstantiateData>())
{
return child.GetComponent<InstantiateData>().floorId;
}
}
}
return 0;
}
}
private void CreatePoint(Vector3 position, int floorId)
{
var pos = new Vector3(position.x, position.y + DistanceY, position.z);

153
Assets/Scripts/ANet/PathFinding.cs

@ -1,3 +1,4 @@
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -8,6 +9,7 @@ public class PathFinding : MonoBehaviour
public Transform PathParent;
public List<Transform> PathList = new List<Transform>();
public int NowIndex = 0;
public int NowFloor = 4;
// Start is called before the first frame update
void Start()
{
@ -21,8 +23,43 @@ public class PathFinding : MonoBehaviour
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
List<LTData> alld = new List<LTData>();
LTData data = new LTData();
Vector3 p1 = new Vector3(-17.47f, -17.5f, 41.83f);//1.7
Vector3 p2 = new Vector3(-17.47f, -15.9f, 37.48f);//1.4
Vector3 p3 = new Vector3(-15.48f, -15.9f, 37.48f);//1.4
Vector3 p4 = new Vector3(-15.48f, -14.3f, 41.83f);//1.7
data.FloorId = 4;
data.LTName = "LT65";
data.LTTopCode = "1";
data.LTMidCode = "2";
data.LTBottomCode = "3";
data.PTop = p1;
data.PTop_Half = p2;
data.PHalf_Bottom = p3;
data.PBottom = p4;
data.PWidthRange = 0.8f;
data.PHalfWidthRange = 0.4f;
data.IsTop_Bottom = false;
alld.Add(data);
alld.Add(data);
string adstr = JsonConvert.SerializeObject(alld);
Debug.Log(adstr);
}
if (Input.GetKeyDown(KeyCode.T))
{
LTData ltdata = null;
foreach (var item in Config.LTPostions)
{
if (item.FloorId == NowFloor)
{
ltdata = item;
break;
}
}
if (NowIndex == 0)
{
LocationData data = new LocationData();
@ -35,7 +72,7 @@ public class PathFinding : MonoBehaviour
agent.enabled = false;
agent.GetComponent<NavMeshAgent>().enabled = false;
GetComponent<LocationSimulator>().agentControllers.Add(data.targetNo, agent);
Vector3 pos = ConversionTransform(data);
Vector3 pos = ConversionTransform(data, ltdata);
GetComponent<LocationSimulator>().agentControllers[data.targetNo].transform.position = pos;
}
else if (NowIndex < PathList.Count)
@ -46,7 +83,7 @@ public class PathFinding : MonoBehaviour
data.xAxis = PathList[NowIndex].transform.position.x;
data.yAxis = PathList[NowIndex].transform.position.y;
data.zAxis = PathList[NowIndex].transform.position.z;
Vector3 pos = ConversionTransform(data);
Vector3 pos = ConversionTransform(data, ltdata);
GetComponent<LocationSimulator>().agentControllers[data.targetNo].transform.position = pos;
}
else
@ -61,78 +98,90 @@ public class PathFinding : MonoBehaviour
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public Vector3 ConversionTransform(LocationData data)
public Vector3 ConversionTransform(LocationData data, LTData ltData)
{
//判断数据被检测到的区域
string St1 = Config.LTTopCode;//楼梯入口基站
string St2 = Config.LTMidCode;//楼梯间基站
string St3 = Config.LTBottomCode;//楼梯底层基站
//纠正坐标
Vector3 p1 = new Vector3(-15.48f, -17.7f, 41.83f);//1.7
Vector3 p2 = new Vector3(-15.48f, -19.3f, 37.48f);//1.4
Vector3 p3 = new Vector3(-17.47f, -19.3f, 37.48f);//1.4
Vector3 p4 = new Vector3(-17.47f, -21.1f, 42.42f);//1.7
//换算最终位置
//-4地面高度-17.7f
float y = -17.7f;
if (ltData == null)
return Vector3.zero;
//取最高处作为pos.y方便向下打射线
float y = ltData.PTop.y > ltData.PBottom.y ? ltData.PTop.y : ltData.PBottom.y;
//对方传入转换后的数据
var pos = new Vector3((float)data.xAxis, y, (float)data.zAxis);
if (data.stations.Contains(St3) && !data.stations.Contains(St2))
{ //-5地面高度-21.1f
pos.y = p4.y;
if (data.stations.Contains(ltData.LTBottomCode) && !data.stations.Contains(ltData.LTMidCode))
{ //下面地面
pos.y = ltData.PBottom.y;
}
else if (data.stations.Contains(St1) && data.stations.Contains(St2))
{ //-4到-5楼梯上半段
if (pos.x < p1.x - 0.8 || pos.x > p1.x + 0.8)
else if (data.stations.Contains(ltData.LTBottomCode) && data.stations.Contains(ltData.LTMidCode))
{ //楼梯下半段
if (pos.x < ltData.PBottom.x - ltData.PWidthRange || pos.x > ltData.PBottom.x + ltData.PWidthRange)
{
pos.x = p1.x;
pos.x = ltData.PBottom.x;
}
if (pos.z > p1.z)
if (pos.z > ltData.PBottom.z)
{
pos.z = p1.z;
pos.z = ltData.PBottom.z;
}
if (pos.z < p2.z)
if (pos.z < ltData.PHalf_Bottom.z)
{
pos.z = p2.z;
pos.z = ltData.PHalf_Bottom.z;
}
pos.y = SetY(pos);
pos.y = SetY(pos, ltData.LTName);
if (pos.y == 0)
pos.y = ltData.PBottom.y;
}
else if (data.stations.Contains(St2) && data.stations.Contains(St3))
{ //-4到-5楼梯下半段
if (pos.x < p3.x - 0.8 || pos.x > p3.x + 0.8)
else if (data.stations.Contains(ltData.LTTopCode) && data.stations.Contains(ltData.LTMidCode))
{ //楼梯上半段
if (pos.x < ltData.PTop.x - ltData.PWidthRange || pos.x > ltData.PTop.x + ltData.PWidthRange)
{
pos.x = p3.x;
pos.x = ltData.PTop.x;
}
if (pos.z > p4.z)
if (pos.z > ltData.PTop.z)
{
pos.z = p4.z;
pos.z = ltData.PTop.z;
}
if (pos.z < p3.z)
if (pos.z < ltData.PTop_Half.z)
{
pos.z = p3.z;
pos.z = ltData.PTop_Half.z;
}
pos.y = SetY(pos);
pos.y = SetY(pos, ltData.LTName);
if (pos.y == 0)
pos.y = ltData.PTop.y;
}
else if (data.stations.Contains(St2) && !data.stations.Contains(St1) && !data.stations.Contains(St3))
else if (data.stations.Contains(ltData.LTMidCode) &&
!data.stations.Contains(ltData.LTTopCode) &&
!data.stations.Contains(ltData.LTBottomCode))
{
//-4到-5楼梯间过度
if (pos.z < p3.z - 0.4 || pos.z > p3.z + 0.4)
//楼梯间过度
if (pos.z < ltData.PTop_Half.z - ltData.PHalfWidthRange || pos.z > ltData.PTop_Half.z + ltData.PHalfWidthRange)
{
pos.z = p3.z;
pos.z = ltData.PTop_Half.z;
}
if (pos.x > p2.x)
if (pos.x > ltData.PTop_Half.x)
{
pos.x = p2.x;
pos.x = ltData.PTop_Half.x;
}
if (pos.x < p3.x)
if (pos.x < ltData.PHalf_Bottom.x)
{
pos.x = p3.x;
pos.x = ltData.PHalf_Bottom.x;
}
pos.y = p3.y;
pos.y = ltData.PTop_Half.y;
}
else if (data.stations.Contains(ltData.LTTopCode) && !data.stations.Contains(ltData.LTMidCode))
{//上面地面
pos.y = ltData.PTop.y;
}
else
{//其他基站则在正常高度
if (ltData.IsTop_Bottom)
pos.y = ltData.PTop.y;
else
pos.y = ltData.PBottom.y;
}
return pos;
}
/// <summary>
@ -140,25 +189,17 @@ public class PathFinding : MonoBehaviour
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public float SetY(Vector3 position)
public float SetY(Vector3 position, string ltname)
{
RaycastHit hit;
var hitlist = Physics.RaycastAll(position, Vector3.down, 100f, ~(1 << (LayerMask.NameToLayer("Defaut") | LayerMask.NameToLayer("Hidden"))));
if (hitlist.Length > 0)
{
foreach (var item in hitlist)
{
if (item.transform.gameObject.layer == LayerMask.NameToLayer("Stair"))
if (item.transform.name == ltname)
return item.point.y;
}
}
//if (Physics.Raycast(position, Vector3.down, out hit, 100f, 15))
//{
// // 如果射线击中地面,设置Y轴为地面高度
// return hit.point.y;
//}
return 0f;
}
}

1
Assets/Scripts/ANet/Prefabs/PathParent.prefab

@ -1555,6 +1555,7 @@ MonoBehaviour:
PathParent: {fileID: 2617003052103167149}
PathList: []
NowIndex: 0
NowFloor: 5
--- !u!114 &1790434944
MonoBehaviour:
m_ObjectHideFlags: 0

4
Assets/Scripts/Common/GameManager.cs

@ -49,9 +49,7 @@ public class GameManager : Singleton<GameManager>
Config.Range = webConfig.Range;
Config.Interval = webConfig.Interval;
Config.MapId = webConfig.MapId;
Config.LTTopCode = webConfig.LTTopCode;
Config.LTMidCode = webConfig.LTMidCode;
Config.LTBottomCode = webConfig.LTBottomCode;
Config.LTPostions = webConfig.LTPostions;
Config.AlarmServer = webConfig.AlarmServer;
Config.AlarmInterval = webConfig.AlarmInterval;
Debug.Log("ServerAddress:" + Config.ServerAddress + " Interval:" + Config.Interval + " Range:" + Config.Range);

166
Assets/Scripts/Main/Core/PersonnelLocation/LocationSimulator.cs

@ -4,6 +4,22 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LTData
{
public int FloorId;//楼层
public string LTName;//要走的楼梯民称
public string LTTopCode;//楼梯上面的定位设备编码
public string LTMidCode;//楼梯中间的定位设备编码
public string LTBottomCode;//楼梯下面的定位设备编码
public Vector3 PTop;//楼梯上面的点位
public Vector3 PTop_Half;//楼梯上面-中间的点位
public Vector3 PHalf_Bottom;//楼梯中间-下面的点位
public Vector3 PBottom;//楼梯下面的点位
public float PWidthRange;//楼梯宽度
public float PHalfWidthRange;//楼梯中间段的宽度
public bool IsTop_Bottom = false;//是否是从上到下走
}
public class LocationSimulator : MonoBehaviour
{
//定位人员
@ -248,35 +264,6 @@ public class LocationSimulator : MonoBehaviour
yield return new WaitForSeconds(Config.Interval);
}
}
/// <summary>
/// 确保角色始终在地面上
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public float SetY(Vector3 position)
{
//RaycastHit hit;
var hitlist = Physics.RaycastAll(position, Vector3.down, 100f, ~(1 << (LayerMask.NameToLayer("Defaut") | LayerMask.NameToLayer("Hidden"))));
if (hitlist.Length > 0)
{
foreach (var item in hitlist)
{
if (item.transform.gameObject.layer == LayerMask.NameToLayer("Stair"))
return item.point.y;
}
}
//if (Physics.Raycast(position, Vector3.down, out hit, 100f, 15))
//{
// // 如果射线击中地面,设置Y轴为地面高度
// return hit.point.y;
//}
return 0f;
}
/// <summary>
/// 创建agent对象
/// </summary>
@ -285,7 +272,6 @@ public class LocationSimulator : MonoBehaviour
/// <returns></returns>
public AgentController CreateAgent(LocationData data)
{
if (characterCount > 4)
characterCount = 0;
var obj = Instantiate(AssetManager.Instance.characters[characterCount]) as GameObject;
@ -324,77 +310,107 @@ public class LocationSimulator : MonoBehaviour
/// <returns></returns>
public Vector3 ConversionTransform(LocationData data)
{
//判断数据被检测到的区域
string St1 = Config.LTTopCode;//楼梯入口基站
string St2 = Config.LTMidCode;//楼梯间基站
string St3 = Config.LTBottomCode;//楼梯底层基站
//纠正坐标
Vector3 p1 = new Vector3(-15.48f, -17.7f, 41.83f);//0.8
Vector3 p2 = new Vector3(-15.48f, -19.3f, 37.48f);//0.4
Vector3 p3 = new Vector3(-17.47f, -19.3f, 37.48f);//0.4
Vector3 p4 = new Vector3(-17.47f, -21.1f, 42.42f);//0.8
//换算最终位置
//-4地面高度-17.7f
float y = p1.y;
var pos = new Vector3(-((float)data.xAxis - offsetX), y, -((float)data.yAxis - offsetZ));
if (data.stations.Contains(St3) && !data.stations.Contains(St2))
{ //-5地面高度-21.1f
pos.y = p4.y;
LTData ltData = Config.LTPostions[0];
if (ltData == null)
return Vector3.zero;
//取最高处作为pos.y方便向下打射线
float y = ltData.PTop.y > ltData.PBottom.y ? ltData.PTop.y : ltData.PBottom.y;
//对方传入转换后的数据
var pos = new Vector3((float)data.xAxis, y, (float)data.zAxis);
if (data.stations.Contains(ltData.LTBottomCode) && !data.stations.Contains(ltData.LTMidCode))
{ //下面地面
pos.y = ltData.PBottom.y;
}
else if (data.stations.Contains(St1) && data.stations.Contains(St2))
{ //-4到-5楼梯上半段
if (pos.x < p1.x - 0.8 || pos.x > p1.x + 0.8)
else if (data.stations.Contains(ltData.LTBottomCode) && data.stations.Contains(ltData.LTMidCode))
{ //楼梯下半段
if (pos.x < ltData.PBottom.x - ltData.PWidthRange || pos.x > ltData.PBottom.x + ltData.PWidthRange)
{
pos.x = p1.x;
pos.x = ltData.PBottom.x;
}
if (pos.z > p1.z)
if (pos.z > ltData.PBottom.z)
{
pos.z = p1.z;
pos.z = ltData.PBottom.z;
}
if (pos.z < p2.z)
if (pos.z < ltData.PHalf_Bottom.z)
{
pos.z = p2.z;
pos.z = ltData.PHalf_Bottom.z;
}
pos.y = SetY(pos);
pos.y = SetY(pos, ltData.LTName);
if (pos.y == 0)
pos.y = ltData.PBottom.y;
}
else if (data.stations.Contains(St2) && data.stations.Contains(St3))
{ //-4到-5楼梯下半段
if (pos.x < p3.x - 0.8 || pos.x > p3.x + 0.8)
else if (data.stations.Contains(ltData.LTTopCode) && data.stations.Contains(ltData.LTMidCode))
{ //楼梯上半段
if (pos.x < ltData.PTop.x - ltData.PWidthRange || pos.x > ltData.PTop.x + ltData.PWidthRange)
{
pos.x = p3.x;
pos.x = ltData.PTop.x;
}
if (pos.z > p4.z)
if (pos.z > ltData.PTop.z)
{
pos.z = p4.z;
pos.z = ltData.PTop.z;
}
if (pos.z < p3.z)
if (pos.z < ltData.PTop_Half.z)
{
pos.z = p3.z;
pos.z = ltData.PTop_Half.z;
}
pos.y = SetY(pos);
pos.y = SetY(pos, ltData.LTName);
if (pos.y == 0)
pos.y = ltData.PTop.y;
}
else if (data.stations.Contains(St2) && !data.stations.Contains(St1) && !data.stations.Contains(St3))
else if (data.stations.Contains(ltData.LTMidCode) &&
!data.stations.Contains(ltData.LTTopCode) &&
!data.stations.Contains(ltData.LTBottomCode))
{
//-4到-5楼梯间过度
if (pos.z < p3.z - 0.4 || pos.z > p3.z + 0.4)
//楼梯间过度
if (pos.z < ltData.PTop_Half.z - ltData.PHalfWidthRange || pos.z > ltData.PTop_Half.z + ltData.PHalfWidthRange)
{
pos.z = p3.z;
pos.z = ltData.PTop_Half.z;
}
if (pos.x > p2.x)
if (pos.x > ltData.PTop_Half.x)
{
pos.x = p2.x;
pos.x = ltData.PTop_Half.x;
}
if (pos.x < p3.x)
if (pos.x < ltData.PHalf_Bottom.x)
{
pos.x = p3.x;
pos.x = ltData.PHalf_Bottom.x;
}
pos.y = p3.y;
pos.y = ltData.PTop_Half.y;
}
else if (data.stations.Contains(ltData.LTTopCode) && !data.stations.Contains(ltData.LTMidCode))
{//上面地面
pos.y = ltData.PTop.y;
}
else
{//其他基站则在正常高度
if (ltData.IsTop_Bottom)
pos.y = ltData.PTop.y;
else
pos.y = ltData.PBottom.y;
}
return pos;
}
/// <summary>
/// 确保角色始终在地面上
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public float SetY(Vector3 position, string ltname)
{
var hitlist = Physics.RaycastAll(position, Vector3.down, 100f, ~(1 << (LayerMask.NameToLayer("Defaut") | LayerMask.NameToLayer("Hidden"))));
if (hitlist.Length > 0)
{
foreach (var item in hitlist)
{
if (item.transform.name == ltname)
return item.point.y;
}
}
return 0f;
}
}

32
Assets/Scripts/Manager/Config.cs

@ -27,18 +27,6 @@ public static class Config
/// </summary>
public static string MapId { get; set; }
/// <summary>
/// 人员定位楼梯上层定位设备code
/// </summary>
public static string LTTopCode { get; set; }
/// <summary>
/// 人员定位楼梯楼梯间定位设备code
/// </summary>
public static string LTMidCode { get; set; }
/// <summary>
/// 人员定位楼梯下层定位设备code
/// </summary>
public static string LTBottomCode { get; set; }
/// <summary>
/// 人员定位报警接口
/// </summary>
public static string AlarmServer { get; set; }
@ -62,6 +50,10 @@ public static class Config
/// 报警轮询间隔
/// </summary>
public static float AlarmInterval { get; set; }
/// <summary>
/// 楼梯定位数据类
/// </summary>
public static List<LTData> LTPostions { get; set; }
}
public class ConfigWebGL
@ -91,18 +83,6 @@ public class ConfigWebGL
/// </summary>
public string MapId { get; set; }
/// <summary>
/// 人员定位楼梯上层定位设备code
/// </summary>
public string LTTopCode { get; set; }
/// <summary>
/// 人员定位楼梯楼梯间定位设备code
/// </summary>
public string LTMidCode { get; set; }
/// <summary>
/// 人员定位楼梯下层定位设备code
/// </summary>
public string LTBottomCode { get; set; }
/// <summary>
/// 人员定位报警接口
/// </summary>
public string AlarmServer { get; set; }
@ -126,4 +106,8 @@ public class ConfigWebGL
/// 报警轮询间隔
/// </summary>
public float AlarmInterval { get; set; }
/// <summary>
/// 楼梯定位数据类
/// </summary>
public List<LTData> LTPostions { get; set; }
}

80
Assets/StreamingAssets/Config.json

@ -4,14 +4,74 @@
"AreaName": "虹口区",
"CompanyName": "凯德龙之梦",
"LocationServer": "http://101.201.70.191:8080",
"AlarmServer":"http://101.201.70.191:8080",
"MapId":"8",
"LTTopCode":"1",
"LTMidCode":"2",
"LTBottomCode":"3",
"PersonnelVideoUrl":"https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8",
"Tags": ["10671050","10671051","10671052","10671053","10671054","10671057","10671058","10671059","10671061","10671064"],
"Interval":1,
"Range":0.3,
"AlarmInterval":10
"AlarmServer": "http://101.201.70.191:8080",
"MapId": "8",
"PersonnelVideoUrl": "https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8",
"Tags": ["10671050", "10671051", "10671052", "10671053", "10671054", "10671057", "10671058", "10671059", "10671061", "10671064"],
"Interval": 1,
"Range": 0.3,
"AlarmInterval": 10,
"LTPostions":
[
{
"FloorId": 4,
"LTName": "LT65",
"LTTopCode": "1",
"LTMidCode": "2",
"LTBottomCode": "3",
"PTop": {
"x": -15.48,
"y": -14.3,
"z": 41.83
},
"PTop_Half": {
"x": -15.48,
"y": -15.9,
"z": 37.48
},
"PHalf_Bottom": {
"x": -17.47,
"y": -15.9,
"z": 37.48
},
"PBottom": {
"x": -17.47,
"y": -17.5,
"z": 41.83
},
"PWidthRange": 0.8,
"PHalfWidthRange": 0.4,
"IsTop_Bottom": false
},
{
"FloorId": 5,
"LTName": "LT79",
"LTTopCode": "1",
"LTMidCode": "2",
"LTBottomCode": "3",
"PTop": {
"x": -15.48,
"y": -17.5,
"z": 41.83
},
"PTop_Half": {
"x": -15.48,
"y": -19.3,
"z": 37.48
},
"PHalf_Bottom": {
"x": -17.47,
"y": -19.3,
"z": 37.48
},
"PBottom": {
"x": -17.47,
"y": -21.1,
"z": 41.83
},
"PWidthRange": 0.8,
"PHalfWidthRange": 0.4,
"IsTop_Bottom": true
}
]
}
Loading…
Cancel
Save