激光同步及接口整理脚本

This commit is contained in:
账号名 2023-11-22 14:17:28 +08:00
parent 86968b959b
commit 86b6c637e6
11 changed files with 427 additions and 731 deletions

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,8 @@ using UnityEngine.Rendering.PostProcessing;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using static InterfaceManager;
using YL;
using static NetMQ.NetMQSelector;
using static UnityEditor.ShaderData;
@ -88,7 +90,7 @@ public class Scenariopage : MonoBehaviour
public Image contingency_list_panl;//想定列表面板
public Button off_btnn5;//关闭按钮
public Button queren_btnn3;//确认按钮
private string url = "http://172.16.1.254:48888/Handler/Thinkingfile.ashx?action=all";//想定Wbe接口
//private string url = Url_Action;//想定Wbe接口
//public List<Text> textlist = new List<Text>();
[SerializeField]
Editinformation scen = new Editinformation();
@ -288,7 +290,7 @@ public class Scenariopage : MonoBehaviour
void Start()
{
//调用接口
StartCoroutine(Post1(url, (bol, str) =>
StartCoroutine(Post1(Url_Action, (bol, str) =>
{
Scenario(bol, str);
}));

View File

@ -762,7 +762,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 742343356}
m_LocalRotation: {x: 0.30070576, y: 0, z: 0, w: 0.953717}
m_LocalPosition: {x: 323, y: 178, z: -84}
m_LocalPosition: {x: 26, y: 190, z: -443}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -916,7 +916,7 @@ PrefabInstance:
- target: {fileID: 3977472425108262603, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5, type: 3}
@ -1866,12 +1866,12 @@ PrefabInstance:
- target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162,
type: 3}
propertyPath: m_Name
value: "\u6FC0\u5149\u706B\u63A7\u5E73\u53F0"
value: "\u6FC0\u5149\u706B\u63A7\u5E73\u53F0(1)"
objectReference: {fileID: 0}
- target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162,
type: 3}
@ -1945,12 +1945,12 @@ PrefabInstance:
- target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162,
type: 3}
propertyPath: m_Name
value: "\u6FC0\u5149\u706B\u63A7\u5E73\u53F0"
value: "\u6FC0\u5149\u706B\u63A7\u5E73\u53F0(2)"
objectReference: {fileID: 0}
- target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162,
type: 3}

View File

@ -26,6 +26,7 @@ public class DeviceManager : MonoSingleton<DeviceManager>
public void GetSend2roomMsg(string data)
{
data = data.Replace("send2room", "");
string[] info = data.Split(',');
EquipmentCommon equipmentCommon = devices.Find(x => x.deviceID == info[0]);
if (equipmentCommon)

View File

@ -0,0 +1,207 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static class InterfaceManager
{
public static string IP { get => "111.229.30.246:"; }
public static string Port { get => "48888"; }
public static string IpAddress { get => string.Format("http://{0}:{1}", IP, Port); }
#region
/// <summary>
/// 想定Wbe接口
/// </summary>
public static string Url_Action { get => IpAddress + "/Handler/Thinkingfile.ashx?action=all"; }
/// <summary>
///
/// </summary>
public static string Url_Updatedevicepara { get => IpAddress + "/Handler/Thinkingfile.ashx?action=updatedevicepara"; }
#endregion
public static string GetLocalTxt(string path)
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(path)) { return reader.ReadToEnd(); }
}
public static IEnumerator GetBytes(string url, Action<string> callback)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator GetString(string url, Action<string> callback)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator GetString(string url, int time, Action<string> callback)
{
while (true)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return new WaitForSeconds(time); // 每隔 time 秒调用一次接口
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
}
public static IEnumerator PostString(string url, WWWForm formdata, Dictionary<string, string> headers = null, Action<string> callback = null)
{
using (UnityWebRequest www = UnityWebRequest.Post(url, formdata))
{
foreach (var item in headers)
{
www.SetRequestHeader(item.Key, item.Value);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator GetString(string url, Dictionary<string, string> headers = null,int time=50,Action<string> callback = null)
{
while (true)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return new WaitForSeconds(time); // 每隔 time 秒调用一次接口
foreach (var item in headers)
{
www.SetRequestHeader(item.Key, item.Value);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
}
public static IEnumerator GetString(string url, Dictionary<string, string> headers = null, Action<string> callback = null)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
foreach (var item in headers)
{
www.SetRequestHeader(item.Key, item.Value);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87232468ce4d4234599cf08409219d0b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -107,11 +107,6 @@ public class EquipmentCommon : MonoBehaviour
}
}
public char replaceInfo;
public Dictionary<string, string> replaceInfoDic = new Dictionary<string, string>();
/// <summary>
/// 物体生成时接受数据
/// </summary>
@ -121,6 +116,7 @@ public class EquipmentCommon : MonoBehaviour
//向其他的单位发送创建信息
if (isPlayer && equipmentCommon)//但是是由我自主创建的时候发送一次 且只发送一次
{
Dictionary<string, string> replaceInfoDic = new Dictionary<string, string>();
string paraListJson = JsonConvert.SerializeObject(weaponitemone);
replaceInfoDic.Add("PracticeId", GlobalFlag.roomID);
replaceInfoDic.Add("PracticeSubjectId", GlobalFlag.practiceSubjectID);
@ -175,37 +171,50 @@ public class EquipmentCommon : MonoBehaviour
if (!nowData.Equals(latestData))
{
latestData = nowData;
Debug.Log(latestData);
//Debug.Log(latestData);
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
}
}
}
/// <summary>
/// 无人机
/// </summary>
/// <returns></returns>
protected string GetSyncData()
{
return string.Format("{0},{1},{2},{3},{4},{5},{6}", equipmentCommon.deviceID, transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.T))
{
isPlayer = !isPlayer;
}
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
public void ReceivingPositionAngle(string[] data)
{
Debug.Log(data[0]);
Vector3 pos = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]));
Vector3 rot = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6]));
transform.position = pos;
transform.position = rot;
switch (equipmentType)
{
case "无人机List":
Vector3 pos = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]));
Vector3 rot = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6]));
transform.position = pos;
transform.eulerAngles = rot;
break;
case "激光火控平台":
LaserFireControlPlatformManger laserFireControlPlatformManger = GetComponent<LaserFireControlPlatformManger>();
if (laserFireControlPlatformManger)
laserFireControlPlatformManger.NonSelfGeneratedEmissionLaser(data);
break;
case "探测雷达":
break;
case "地面无线电干扰":
break;
default:
break;
}
}
}

View File

@ -72,6 +72,9 @@ public class LaserFireControlPlatformManger : MonoBehaviour
#endregion
#region
/// <summary>
/// 是否这在攻击无人机
/// </summary>
public bool isLasing = false;
public GameObject LaserModer;
public GameObject LaserPoint;
@ -140,6 +143,7 @@ public class LaserFireControlPlatformManger : MonoBehaviour
}
}
#region
/// <summary>
/// 数据写入
@ -147,12 +151,6 @@ public class LaserFireControlPlatformManger : MonoBehaviour
/// <param name="weaponitemone"></param>
public void FillInTheData(List<List_paraItem> weaponitemone)
{
//if (equipmentCommon)
//{
//string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}+{transform.eulerAngles.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}";
//Debug.Log(msg);
//_ = SyncCreateRoom.SendMessageAsync(msg);
//}
for (int i = 0; i < weaponitemone.Count; i++)
{
switch (weaponitemone[i].para_name)
@ -182,12 +180,12 @@ public class LaserFireControlPlatformManger : MonoBehaviour
{
if (targetPoint != null)
{
if (isLasing) return;
isLasing = true;
LaserModer.transform.DOLookAt(targetPoint.position, 0.3f).OnComplete(()=> {
LaserModer.transform.DOLookAt(targetPoint.position, 0.1f).OnComplete(()=> {
Debug.Log("目标点位..:"+targetPoint.position);
CastRayAndRender();
});
var nowData = GetSyncData();
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
}
else
{
@ -195,8 +193,6 @@ public class LaserFireControlPlatformManger : MonoBehaviour
}
}
public LayerMask layerMask; // 用于指定需要检测的层级
/// <summary>
/// 激光显示
/// </summary>
@ -236,7 +232,7 @@ public class LaserFireControlPlatformManger : MonoBehaviour
/// </summary>
public IEnumerator LaserExtinction()
{
yield return new WaitForSeconds(0.1f);
yield return new WaitForSeconds(1f);
if (InnerLaserlineRenderer)
{
InnerLaserlineRenderer.SetPosition(0, LaserPoint.transform.position); // 设置线段起点为物体位置
@ -249,4 +245,37 @@ public class LaserFireControlPlatformManger : MonoBehaviour
}
isLasing = false;
}
#endregion
/// <summary>
/// 激光发射点位
/// </summary>
/// <returns></returns>
protected string GetSyncData()
{
Debug.Log("目标点位..:" + targetPoint.position);
return string.Format("{0},{1},{2},{3}", equipmentCommon.deviceID, targetPoint.position.x, targetPoint.position.y, targetPoint.position.z);
}
/// <summary>
/// 非自生成激光发射台发射激光发射激光
/// </summary>
/// <param name="data"></param>
public void NonSelfGeneratedEmissionLaser(string[] data)
{
Vector3 vector3 = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]));
if (InnerLaserlineRenderer)
{
InnerLaserlineRenderer.SetPosition(0, LaserPoint.transform.position); // 设置线段起点为物体位置
InnerLaserlineRenderer.SetPosition(1, vector3); // 设置线段终点为目标点
}
if (OuterLaserlineRenderer)
{
OuterLaserlineRenderer.SetPosition(0, LaserPoint.transform.position); // 设置线段起点为物体位置
OuterLaserlineRenderer.SetPosition(1, vector3); // 设置线段终点为目标点
}
StartCoroutine(LaserExtinction());
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using AdamThinkDevicesData;
using AdamSync;
using System.Linq;
/// <summary>
/// 雷达控制
@ -143,10 +144,12 @@ public class RadarManger : MonoBehaviour
{
if (newValue)
{
Debug.Log("开始检索");
StartTimer();
}
else
{
Debug.Log("停止检索");
StopTimer();
}
}
@ -156,7 +159,7 @@ public class RadarManger : MonoBehaviour
{
while (true)
{
Debug.Log("Timer fired at: " + Time.time);
//Debug.Log("Timer fired at: " + Time.time);
yield return new WaitForSeconds(interval); // 等待一段时间后继续执行
RetrievalUAV();
}
@ -281,26 +284,25 @@ public class RadarManger : MonoBehaviour
/// </summary>
public void RetrievalUAV()
{
Collider[] colliders = Physics.OverlapSphere(transform.position, detectionRadius); // 检索范围内的所有碰撞体
List<Collider> colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体
int number = 0;
foreach (Collider col in colliders)
var colliders2 = colliders.FindAll(x => x.tag == "WRJ");
if (colliders2.Count > 0)
{
if (col.transform.tag == "WRJ")
for(int i=0;i< colliders2.Count; i++)
{
UnmannedAerialVehicle unmannedAerialVehicle = col.GetComponent<UnmannedAerialVehicle>();
if (number>= NumberOfProbes)
if (unmannedAerialVehicle)
UnmannedAerialVehicle unmannedAerialVehicle = colliders2[i].GetComponent<UnmannedAerialVehicle>();
if (unmannedAerialVehicle)
{
//Debug.Log("检测到无人机: " + col.name);
LaserFireControlPlatformManger laserFireControlPlatformManger = LaserFireControlPlatformManger.laserFireControlPlatformMangers.Find(x=>(x!=null&&x.isLasing==false));
if (laserFireControlPlatformManger&& !laserFireControlPlatformManger.isLasing)
LaserFireControlPlatformManger laserFireControlPlatformManger = LaserFireControlPlatformManger.laserFireControlPlatformMangers.Find(x => (x != null && x.isLasing == false));
if (laserFireControlPlatformManger)
{
number++;
laserFireControlPlatformManger.targetPoint = col.transform;
laserFireControlPlatformManger.isLasing = true;
Debug.Log(laserFireControlPlatformManger.transform.name + "攻击无人机: " + unmannedAerialVehicle.transform.name);
laserFireControlPlatformManger.targetPoint = unmannedAerialVehicle.transform;
laserFireControlPlatformManger.Lasing();
}
number++;
}
}
}

View File

@ -48,9 +48,9 @@ public class SingleMachineTest : MonoBehaviour
laserFireControlPlatformMangers.ForEach(x => x.FillInTheData(root.data[3].list_para));
terrestrialRadioInterferenceMangers.ForEach(x => x.FillInTheData(root.data[1].list_para));
// 开始协程
StartTimer();
//StartTimer();
}
void FixedUpdate()
{
if (Input.GetMouseButtonDown(1))
@ -66,21 +66,25 @@ public class SingleMachineTest : MonoBehaviour
}
}
// 按下空格键来切换定时器的运行状态
if (Input.GetKeyDown(KeyCode.Space))
}
[ContextMenu("Add")]
public void Add()
{
if (isTimerRunning)
{
if (isTimerRunning)
{
// 暂停定时器
Debug.Log("暂停定时器执行调用: " + Time.time);
StopTimer();
}
else
{
// 继续定时器
Debug.Log("继续定时器执行调用: " + Time.time);
StartTimer();
}
isTimerRunning = false;
// 暂停定时器
Debug.Log("暂停定时器执行调用: " + Time.time);
StopTimer();
}
else
{
isTimerRunning = true;
// 继续定时器
Debug.Log("继续定时器执行调用: " + Time.time);
StartTimer();
}
}
@ -101,7 +105,7 @@ public class SingleMachineTest : MonoBehaviour
if (timerCoroutine == null)
{
timerCoroutine = StartCoroutine(Timer());
isTimerRunning = true;
unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = true);
radarMangers.ForEach(x => x.isStartRehearsing = true);
laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = true);
@ -118,7 +122,7 @@ public class SingleMachineTest : MonoBehaviour
{
StopCoroutine(timerCoroutine);
timerCoroutine = null;
isTimerRunning = false;
unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = false);
radarMangers.ForEach(x => x.isStartRehearsing = false);
laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = false);

View File

@ -155,7 +155,7 @@ public class UnmannedAerialVehicle : MonoBehaviour
Bao1.transform.SetParent(null);
Bao1.SetActive(true);
DistroyThis();
Debug.Log("无人机被激光打击销毁了");
Debug.Log(transform.name+"被激光打击销毁了");
break;
case "无线电干扰":
Vector3 _pos = transform.position - new Vector3(0, 30, 0);
@ -167,7 +167,7 @@ public class UnmannedAerialVehicle : MonoBehaviour
Bao2.SetActive(true);
DistroyThis();
});
Debug.Log("无人机被无线电干扰销毁了");
Debug.Log(transform.name + "无人机被无线电干扰销毁了");
break;
case "攻击到目标":
GameObject Bao3 = Instantiate(explodePrefab, transform);
@ -175,7 +175,7 @@ public class UnmannedAerialVehicle : MonoBehaviour
Bao3.transform.SetParent(null);
Bao3.SetActive(true);
DistroyThis();
Debug.Log("无人机自杀式攻击销毁了");
Debug.Log(transform.name + "无人机自杀式攻击销毁了");
break;
case "没有攻击到目标":
GameObject Bao4 = Instantiate(explodePrefab, transform);
@ -183,7 +183,7 @@ public class UnmannedAerialVehicle : MonoBehaviour
Bao4.transform.SetParent(null);
Bao4.SetActive(true);
DistroyThis();
Debug.Log("无人机自杀式销毁了");
Debug.Log(transform.name + "无人机自杀式销毁了");
break;
default:
break;