using AdamSync; using AdamThinkDevicesData; using Newtonsoft.Json; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using static InterfaceManager; /// /// 重点保护目标 /// public class HighPriorityTarget : MonoBehaviour { /// /// 重点保护目标集合 /// public static List HighPriorityTargets = new List(); /// /// 重点设备完整度 /// public static float EquipmentIntegrity = 1; /// /// 编号 /// public string Number; #region 单体保护目标属性 /// /// 单体保护目标属性血量 /// public float HP = 100; #endregion /// /// 重点目标UI看向摄像机 /// public Transform KeyObjectiveUI; /// /// 爆炸预制体 /// public GameObject explodePrefab; /// /// 完整模型 /// public GameObject ModerFull; /// /// 损坏模型 /// public GameObject ModerDamage; /// /// 调节频率面板 /// public GameObject regulate; /// /// 关闭频率面板 /// public Button buttonreg; /// /// 频率选择 /// public Toggle toggle1, toggle2, toggle3, toggle4, toggle5, toggle6, toggle7; /// /// 接收的字段 /// public string frequency; /// /// 显示地图上的位置 /// public GameObject gamepos; void Start() { HighPriorityTargets.Add(this); Number = HighPriorityTargets.Count.ToString(); buttonreg.onClick.AddListener(() => { regulate.gameObject.SetActive(false); }); Interferencefrequency(); } private void Interferencefrequency() { toggle1.onValueChanged.AddListener((ison) => { if (ison) { frequency = "UHF"; gamepos.layer = 16; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(nowData); } }); toggle2.onValueChanged.AddListener((ison) => { if (ison) { frequency = "L"; gamepos.layer = 17; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(nowData); } }); toggle3.onValueChanged.AddListener((ison) => { if (ison) { frequency = "S"; gamepos.layer = 18; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(nowData); } }); toggle4.onValueChanged.AddListener((ison) => { if (ison) { frequency = "C"; gamepos.layer = 19; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(nowData); } }); toggle5.onValueChanged.AddListener((ison) => { if (ison) { frequency = "X"; gamepos.layer = 20; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(nowData); } }); toggle6.onValueChanged.AddListener((ison) => { if (ison) { frequency = "Ku"; gamepos.layer = 21; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(nowData); } }); toggle7.onValueChanged.AddListener((ison) => { if (ison) { frequency = "Ka"; gamepos.layer = 22; string nowData = GetSyncDataTwo(); DeviceManager.Instance.send2roomStr.Enqueue(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(); if (highPriorityTarget && highPriorityTarget.Number == Number) { regulate.transform.position = Camera.main.WorldToScreenPoint(hit.point); regulate.gameObject.SetActive(true); } } } } } /// /// 被攻击 /// /// 被攻击时触发点位置 /// 是否向外发送同步消息 public void BeAssaulted(Vector3 Pos, bool isSend, int hp = 0) { if (isSend) { HP -= 10; string nowData = GetSyncDis(Pos); //Debug.Log("发送:"+nowData); _ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", 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); } /// /// 同步频率 /// /// protected string GetSyncDataTwo() { UploadLog(); return string.Format("{0},{1},{2},{3}", "BandSetting", "ZYMB", Number, frequency); } /// ///上传日志 /// /// public void UploadLog() { string currentTime = System.DateTime.Now.ToString(); List uploadLogMains = new List(); 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); })); } }