using AdamSync;
using System.Collections.Generic;
using UnityEngine;
///
/// 重点保护目标
///
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;
// Start is called before the first frame update
void Start()
{
HighPriorityTargets.Add(this);
Number = HighPriorityTargets.Count.ToString();
}
// Update is called once per frame
void Update()
{
if (Camera.main)
KeyObjectiveUI.transform.LookAt(Camera.main.transform);
}
///
/// 被攻击
///
/// 被攻击时触发点位置
/// 是否向外发送同步消息
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);
}
}