using AdamSync;
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
/// 重点保护目标
///
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 Image regulate;
///
/// 关闭频率面板
///
public Button buttonreg;
///
/// 频率选择
///
public Toggle toggle1;
public Toggle toggle2;
public Toggle toggle3;
public Toggle toggle4;
public Toggle toggle5;
public Toggle toggle6;
public Toggle toggle7;
///
/// 接收的字段
///
public string frequency;
// Start is called before the first frame update
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 = "HUF";
}
});
toggle2.onValueChanged.AddListener((ison) =>
{
if (ison)
{
frequency = "L";
}
});
toggle3.onValueChanged.AddListener((ison) =>
{
if (ison)
{
frequency = "S";
}
});
toggle4.onValueChanged.AddListener((ison) =>
{
if (ison)
{
frequency = "C";
}
});
toggle5.onValueChanged.AddListener((ison) =>
{
if (ison)
{
frequency = "X";
}
});
toggle6.onValueChanged.AddListener((ison) =>
{
if (ison)
{
frequency = "Ku";
}
});
toggle7.onValueChanged.AddListener((ison) =>
{
if (ison)
{
frequency = "Ka";
}
});
}
// Update is called once per frame
void Update()
{
if (Camera.main)
KeyObjectiveUI.transform.LookAt(Camera.main.transform);
if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) != "0"&&Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
if (Physics.Raycast(ray,out hit,1000))
{
if (hit.collider.gameObject.tag== "AttackTarget" &&hit.transform.GetComponent())
{
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);
}
}