249 lines
7.5 KiB
C#
249 lines
7.5 KiB
C#
using AdamSync;
|
|
using AdamThinkDevicesData;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using static InterfaceManager;
|
|
/// <summary>
|
|
/// 重点保护目标
|
|
/// </summary>
|
|
public class HighPriorityTarget : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 重点保护目标集合
|
|
/// </summary>
|
|
public static List<HighPriorityTarget> HighPriorityTargets = new List<HighPriorityTarget>();
|
|
/// <summary>
|
|
/// 重点设备完整度
|
|
/// </summary>
|
|
public static float EquipmentIntegrity = 1;
|
|
/// <summary>
|
|
/// 编号
|
|
/// </summary>
|
|
public string Number;
|
|
#region 单体保护目标属性
|
|
/// <summary>
|
|
/// 单体保护目标属性血量
|
|
/// </summary>
|
|
public float HP = 100;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 重点目标UI看向摄像机
|
|
/// </summary>
|
|
public Transform KeyObjectiveUI;
|
|
|
|
/// <summary>
|
|
/// 爆炸预制体
|
|
/// </summary>
|
|
public GameObject explodePrefab;
|
|
/// <summary>
|
|
/// 完整模型
|
|
/// </summary>
|
|
public GameObject ModerFull;
|
|
/// <summary>
|
|
/// 损坏模型
|
|
/// </summary>
|
|
public GameObject ModerDamage;
|
|
/// <summary>
|
|
/// 调节频率面板
|
|
/// </summary>
|
|
public GameObject regulate;
|
|
/// <summary>
|
|
/// 关闭频率面板
|
|
/// </summary>
|
|
public Button buttonreg;
|
|
/// <summary>
|
|
/// 频率选择
|
|
/// </summary>
|
|
//public Toggle toggle1, toggle2, toggle3, toggle4, toggle5, toggle6, toggle7;
|
|
/// <summary>
|
|
/// 频段设置
|
|
/// </summary>
|
|
public List<Toggle> togFrequencyBands = new List<Toggle>();
|
|
/// <summary>
|
|
/// 接收的字段
|
|
/// </summary>
|
|
public string frequency;
|
|
/// <summary>
|
|
/// 显示地图上的位置
|
|
/// </summary>
|
|
public GameObject gamepos;
|
|
void Start()
|
|
{
|
|
//gamepos.gameObject.SetActive(false);
|
|
HighPriorityTargets.Add(this);
|
|
Number = HighPriorityTargets.Count.ToString();
|
|
buttonreg.onClick.AddListener(() =>
|
|
{
|
|
regulate.gameObject.SetActive(false);
|
|
});
|
|
//Interferencefrequency();
|
|
//频段设置
|
|
foreach (Toggle toggle in togFrequencyBands)
|
|
{
|
|
toggle.onValueChanged.AddListener(delegate { FrequencyBandsValueChanged(toggle); });
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 频段设置
|
|
/// </summary>
|
|
/// <param name="change"></param>
|
|
void FrequencyBandsValueChanged(Toggle change)
|
|
{
|
|
if (change.isOn)
|
|
{
|
|
frequency = change.transform.name;
|
|
int layerValue = LayerMask.NameToLayer(frequency);
|
|
gamepos.layer = layerValue;
|
|
string nowData = GetSyncDataTwo();
|
|
MyNetMQClient.instance.Send(nowData);
|
|
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
|
//MQTTManager.instance.SendData(MQTTManager.instance.BandSetting, nowData);
|
|
}
|
|
}
|
|
|
|
public void FrequencyGamepos(string _frequency)
|
|
{
|
|
int layerValue = LayerMask.NameToLayer(_frequency);
|
|
frequency = _frequency;
|
|
gamepos.layer = layerValue;
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (Camera.main)
|
|
KeyObjectiveUI.transform.LookAt(Camera.main.transform);
|
|
if (GlobalFlag.blueOrRed == 1)
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
return;
|
|
}
|
|
if (Physics.Raycast(ray, out hit, 1000))
|
|
{
|
|
HighPriorityTarget highPriorityTarget = hit.transform.GetComponent<HighPriorityTarget>();
|
|
if (!GlobalFlag.isStartRehearsing && highPriorityTarget && highPriorityTarget.Number == Number)
|
|
{
|
|
GameManager.Instance.GetAllImportance();
|
|
|
|
regulate.transform.position = Camera.main.WorldToScreenPoint(hit.point);
|
|
regulate.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//if (Spectrumdetection.Radius > 0)
|
|
//{
|
|
// if (gamepos)
|
|
// {
|
|
// gamepos.gameObject.SetActive(true);
|
|
// switch (Spectrumdetection.Radius)
|
|
// {
|
|
// case 1:
|
|
// gamepos.transform.localScale = new Vector3(10, 1, 10);
|
|
// break;
|
|
// case 2:
|
|
// gamepos.transform.localScale = new Vector3(20, 1, 20);
|
|
// break;
|
|
// case 3:
|
|
// gamepos.transform.localScale = new Vector3(30, 1, 30);
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 被攻击
|
|
/// </summary>
|
|
/// <param name="Pos">被攻击时触发点位置</param>
|
|
/// <param name="isSend">是否向外发送同步消息</param>
|
|
public void BeAssaulted(Vector3 Pos, bool isSend, int hp = 0)
|
|
{
|
|
|
|
if (isSend)
|
|
{
|
|
HP -= 10;
|
|
string nowData = GetSyncDis(Pos);
|
|
Debug.Log("发送:" + nowData);
|
|
MyNetMQClient.instance.Send(nowData);
|
|
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
|
//MQTTManager.instance.SendData(MQTTManager.instance.KeyTarget, nowData);
|
|
}
|
|
else
|
|
{
|
|
HP = hp;
|
|
}
|
|
GameObject Bao = Instantiate(explodePrefab);
|
|
Bao.transform.position = Pos;
|
|
Bao.SetActive(true);
|
|
if (HP < 50 && HP > 0)
|
|
{
|
|
ModerFull.SetActive(false);
|
|
ModerDamage.SetActive(true);
|
|
}
|
|
else if (HP <= 0)
|
|
{
|
|
GameObject BaoMain = Instantiate(explodePrefab, transform);
|
|
BaoMain.transform.localPosition = Vector3.zero;
|
|
BaoMain.transform.localScale = Vector3.one * 10;
|
|
BaoMain.transform.SetParent(null);
|
|
BaoMain.SetActive(true);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
}
|
|
|
|
protected string GetSyncDis(Vector3 pos)
|
|
{
|
|
return string.Format("{0},{1},{2},{3},{4},{5}", "KeyTarget", Number, HP, pos.x, pos.y, pos.z);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步频率
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected string GetSyncDataTwo()
|
|
{
|
|
UploadLog();
|
|
return string.Format("{0},{1},{2},{3}", "BandSetting", "ZYMB", Number, frequency);
|
|
}
|
|
|
|
/// <summary>
|
|
///上传日志
|
|
/// </summary>
|
|
/// <param name="deviceID"></param>
|
|
public void UploadLog()
|
|
{
|
|
string currentTime = System.DateTime.Now.ToString();
|
|
List<UploadLogMain> uploadLogMains = new List<UploadLogMain>();
|
|
UploadLogMain uploadLogMain = new UploadLogMain();
|
|
uploadLogMain.PracticeId = GlobalFlag.practiceSubjectID;
|
|
uploadLogMain.ThinkId = GlobalFlag.currentThinkId;
|
|
string log = currentTime + " " + "重要用户(" + Number + ")频段设置为" + frequency;
|
|
uploadLogMain.log = log;
|
|
uploadLogMains.Add(uploadLogMain);
|
|
string uploadLogMainJson = JsonConvert.SerializeObject(uploadLogMains);
|
|
WWWForm wWWForm = new WWWForm();
|
|
wWWForm.AddField("data", uploadLogMainJson);
|
|
StartCoroutine(PostString(Url_Addpracticelog, wWWForm, data =>
|
|
{
|
|
//Debug.Log(data);
|
|
}));
|
|
}
|
|
}
|