NewN_UAVPlane/Assets/Zion/Scripts/HighPriorityTarget.cs

206 lines
5.2 KiB
C#

using AdamSync;
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <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 Image regulate;
/// <summary>
/// 关闭频率面板
/// </summary>
public Button buttonreg;
/// <summary>
/// 频率选择
/// </summary>
public Toggle toggle1;
public Toggle toggle2;
public Toggle toggle3;
public Toggle toggle4;
public Toggle toggle5;
public Toggle toggle6;
public Toggle toggle7;
/// <summary>
/// 接收的字段
/// </summary>
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<HighPriorityTarget>())
{
regulate.gameObject.SetActive(true);
}
}
}
}
/// <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);
_ = 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);
}
}