212 lines
5.5 KiB
C#
212 lines
5.5 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 GameObject regulate;
|
|
/// <summary>
|
|
/// 关闭频率面板
|
|
/// </summary>
|
|
public Button buttonreg;
|
|
/// <summary>
|
|
/// 频率选择
|
|
/// </summary>
|
|
public Toggle toggle1, toggle2,toggle3,toggle4,toggle5,toggle6,toggle7;
|
|
/// <summary>
|
|
/// 接收的字段
|
|
/// </summary>
|
|
public string frequency;
|
|
/// <summary>
|
|
/// 显示地图上的位置
|
|
/// </summary>
|
|
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 = "HUF";
|
|
gamepos.layer = 16;
|
|
}
|
|
});
|
|
toggle2.onValueChanged.AddListener((ison) =>
|
|
{
|
|
if (ison)
|
|
{
|
|
frequency = "L";
|
|
gamepos.layer = 17;
|
|
}
|
|
});
|
|
toggle3.onValueChanged.AddListener((ison) =>
|
|
{
|
|
if (ison)
|
|
{
|
|
frequency = "S";
|
|
gamepos.layer = 18;
|
|
}
|
|
});
|
|
toggle4.onValueChanged.AddListener((ison) =>
|
|
{
|
|
if (ison)
|
|
{
|
|
frequency = "C";
|
|
gamepos.layer = 19;
|
|
}
|
|
});
|
|
toggle5.onValueChanged.AddListener((ison) =>
|
|
{
|
|
if (ison)
|
|
{
|
|
frequency = "X";
|
|
gamepos.layer = 20;
|
|
}
|
|
});
|
|
toggle6.onValueChanged.AddListener((ison) =>
|
|
{
|
|
if (ison)
|
|
{
|
|
frequency = "Ku";
|
|
gamepos.layer = 21;
|
|
}
|
|
});
|
|
toggle7.onValueChanged.AddListener((ison) =>
|
|
{
|
|
if (ison)
|
|
{
|
|
frequency = "Ka";
|
|
gamepos.layer = 22;
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
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))
|
|
{
|
|
HighPriorityTarget highPriorityTarget = hit.transform.GetComponent<HighPriorityTarget>();
|
|
if (highPriorityTarget&& highPriorityTarget.Number==Number)
|
|
{
|
|
regulate.transform.position = Camera.main.WorldToScreenPoint(hit.point);
|
|
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);
|
|
}
|
|
|
|
}
|