using AX.MessageSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using AX.NetworkSystem;
using UnityEngine.AI;
using AX.NetworkSystem;
public class HaemalStrand : MonoBehaviour
{
private bool DrillBegin;
///
/// 跟随目标物体
///
public GameObject TargetObj;
///
/// 当前血量
///
public float Haemal;
///
/// 最大血量
///
public float MaxHaemal;
///
/// 被使用的技能显示
///
private string showSkill;
protected AroundState around;
///
/// 是否带了面具或者其他需要显示图片的东西
///
private Transform gasMask;
///
/// 被使用的技能或者其他说明
///
private Transform skill;
private Transform progress;
private Transform showHaemal;
private Transform HaemalText;
private Slider progressslider;
public Vector3 offest;
private Transform P_SafeArea;
// Use this for initialization
void Start()
{
DrillBegin = GameSettings.othersSettings.isStartDrill;
showHaemal = transform.Find("ShowHaemal");
gasMask = transform.Find("GasMask");
progress = transform.Find("Progress");
skill = progress.transform.Find("Skill");
progressslider = progress.GetComponent();
HaemalText = transform.Find("HaemalText");
P_SafeArea = GameObject.Find("P_AllParent/P_Tools/P_SafeArea").transform;
//DrillBegin = EventReportController.Instance.DrillBegin;
HaemalShow();
}
void Update()
{
HaemalShow();
FollowTarget();
}
public void FollowTarget()
{
if (!IsInView(TargetObj.transform.position))
{
GetComponent().transform.position = new Vector2(10000, 10000);
return;
}
Vector3 point = TargetObj.transform.position + offest;
Vector3 Targetscreenpos = Camera.main.WorldToScreenPoint(point);
Vector3 viewpos = GameObject.Find("UICamera").GetComponent().ScreenToWorldPoint(Targetscreenpos);
viewpos.z = 0;
GetComponent().transform.position = viewpos;
//if (gameObject.activeInHierarchy == true)
//{
// Vector3 Targetscreenpos = Camera.main.WorldToScreenPoint(TargetObj.transform.position);
// GetComponent().transform.position = Targetscreenpos;
//}
}
///
/// 血量显示
///
void HaemalShow()
{
Haemal = TargetObj.GetComponent().Haemal;
if (Haemal <= 0)
{
Haemal = 0;
}
showHaemal.GetComponent().fillAmount = Haemal / MaxHaemal;
HaemalText.GetComponent().text = Mathf.Ceil(Haemal) + "/" + MaxHaemal;
}
public bool IsInView(Vector3 worldPos)
{
Transform camTransform = Camera.main.transform;
Vector2 viewPos = Camera.main.WorldToViewportPoint(worldPos);
Vector3 dir = (worldPos - camTransform.position).normalized;
float dot = Vector3.Dot(camTransform.forward, dir);//判断物体是否在相机前面
if (dot > 0 && viewPos.x >= 0 && viewPos.x <= 1 && viewPos.y >= 0 && viewPos.y <= 1)
return true;
else
return false;
}
///
/// 急救或者移动重伤员时进度条显示
///
///
public void FirstAir(GameObject fireman)
{
progress.gameObject.SetActive(true);
skill.GetComponent().text = "急救中";
// skill.GetComponent().text = fireskill.ToString() + "中";
showSkill = skill.GetComponent().text;
if (TargetObj.GetComponent())
{
if (!TargetObj.GetComponent().IsBefirstAirOrMoving)
{
TargetObj.GetComponent().IsBefirstAirOrMoving = true;
}
}
if (TargetObj.GetComponent())
{
if (!TargetObj.GetComponent().IsBefirstAirOrMoving)
{
TargetObj.GetComponent().IsBefirstAirOrMoving = true;
}
}
StartCoroutine(FirstAirprogressloading(fireman));
fireman.GetComponent().IsFirstAirOrMoving = true;
}
IEnumerator FirstAirprogressloading(GameObject fireman)
{
while (progressslider.value<1)
{
yield return new WaitForSeconds(1f);
progressslider.value += 0.1f;
}
if (progressslider.value>=1)
{
EndProgress(fireman,null);
}
if(TargetObj.GetComponent())
{
TargetObj.GetComponent().BeFristAid = true;
LoadPromptWin.Instance.LoadTextPromptWindow("急救完成",1f);
}
if (TargetObj.GetComponent())
{
TargetObj.GetComponent().IsBefirstAirOrMoving = false;
}
if (TargetObj.GetComponent())
{
TargetObj.GetComponent().IsBefirstAirOrMoving = false;
}
}
void EndProgress(GameObject fireman1,GameObject fireman2)
{
// MessageDispatcher.SendMessage("End_Firstair_Or_Moving",fireskill);
progressslider.value = 0;
showSkill = "";
skill.GetComponent().text = "";
progress.gameObject.SetActive(false);
//if (TargetObj.GetComponent())
//{
// TargetObj. GetComponent().IsBefirstAirOrMoving = false;
//}
//if (TargetObj.GetComponent())
//{
// TargetObj. GetComponent().IsBefirstAirOrMoving = false;
//}
if (TargetObj.GetComponent())
{
TargetObj.GetComponent().IsMoving = false;
}
fireman1.GetComponent().IsFirstAirOrMoving = false;
if (fireman2!=null)
{
fireman2.GetComponent().IsFirstAirOrMoving = false;
}
}
public void Moving(GameObject fireman1,GameObject fireman2)
{
progress.gameObject.SetActive(true);
skill.GetComponent().text = "移动中";
// skill.GetComponent().text = fireskill.ToString() + "中";
showSkill = skill.GetComponent().text;
if (TargetObj.GetComponent())
{
if (!TargetObj.GetComponent().IsBefirstAirOrMoving)
{
TargetObj.GetComponent().IsBefirstAirOrMoving = true;
}
}
if (TargetObj.GetComponent())
{
if (!TargetObj.GetComponent().IsBefirstAirOrMoving)
{
TargetObj.GetComponent().IsBefirstAirOrMoving = true;
}
}
StartCoroutine(Movingprogressloading(fireman1,fireman2));
fireman1.GetComponent().IsFirstAirOrMoving = true;
fireman2.GetComponent().IsFirstAirOrMoving = true;
}
IEnumerator Movingprogressloading(GameObject fireman1, GameObject fireman2)
{
//WounderMoveSyncData arg1 = new WounderMoveSyncData()
//{
// SendUserID = CurrentUserInfo.mySelf.Id,
// WounderId = TargetObj.GetComponent().gameObjID,
// IsBegianMove = true
//};
//NetworkManager.Default.SendAsync("WOUNDER_MOVE_SYNC", arg1);
while (progressslider.value < 1)
{
yield return new WaitForSeconds(1f);
progressslider.value += (1f/30f);
}
if (progressslider.value >= 1)
{
EndProgress(fireman1, fireman2);
}
//读条结束
if (P_SafeArea.childCount < 1)
{
LoadPromptWin.Instance.LoadTextPromptWindow("尚未设置安全区,请重新移动", 2f);
if (TargetObj.GetComponent())
{
TargetObj.GetComponent().IsBefirstAirOrMoving = false;
}
if (TargetObj.GetComponent())
{
TargetObj.GetComponent().IsBefirstAirOrMoving = false;
}
}
else
{
SafeAreaMessage safearea = P_SafeArea.GetChild(0).GetComponent();
Debug.Log(safearea.transform.position+"安全区位置");
Vector3 offpos = safearea.transform.position + safearea.GetoffestPos(safearea.HasWounderNum);
fireman1.transform.position = offpos + new Vector3(0.3f, 0.25f, 0.5f);
fireman1.GetComponent().StopAllCoroutines();
fireman1.GetComponent().enabled = false;
fireman1.GetComponent().enabled = false;
fireman2.transform.position = offpos + new Vector3(-0.3f, 0.25f, -0.5f);
fireman2.GetComponent().StopAllCoroutines();
fireman2.GetComponent().enabled = false;
fireman2.GetComponent().enabled = false;
if (TargetObj.GetComponent())
{
TargetObj.transform.position = offpos;
TargetObj.GetComponent().StopAllCoroutines();
TargetObj.GetComponent().enabled = false;
TargetObj.GetComponent().enabled = false;
}
else
{
TargetObj.transform.position = offpos;
}
StartCoroutine(OpenNav(fireman1,fireman2,TargetObj));
fireman1.GetComponent().IsFirstAirOrMoving = false;
fireman2.GetComponent().IsFirstAirOrMoving = false;
safearea.HasWounderNum= safearea.HasWounderNum+1;
if (TargetObj.GetComponent())
{
//TargetObj.GetComponent().SetDestination(TargetObj.transform.position);
TargetObj.GetComponent().TargetPosition = TargetObj.transform.position;
TargetObj.GetComponent().pathFindEnable = false;
//TargetObj.GetComponent().baseOffset = 0.2f;
TargetObj.GetComponent().IsBefirstAirOrMoving = false;
TargetObj.GetComponent().OverMoveOrGuidance = true;
TargetObj.GetComponent().SaveFrirmanUserId = fireman1.GetComponent().UserID;
TrappedTime.CheckStopTime();
}
if (TargetObj.GetComponent())
{
TargetObj.GetComponent().IsBefirstAirOrMoving = false;
TargetObj.GetComponent().OverMoveOrGuidance = true;
TargetObj.GetComponent().SaveFrirmanUserId = fireman1.GetComponent().UserID;
TrappedTime.CheckStopTime();
}
WounderMoveSyncData arg = new WounderMoveSyncData()
{
SendUserID = CurrentUserInfo.mySelf.Id,
WounderId = TargetObj.GetComponent().gameObjID,
Fireman1Id = fireman1.GetComponent().gameObjID,
Fireman2Id = fireman2.GetComponent().gameObjID,
WounderPos = TargetObj.transform.position,
Fireman1Pos = fireman1.transform.position,
Fireman2Pos = fireman2.transform.position,
IsBegianMove = false
};
NetworkManager.Default.SendAsync("WOUNDER_MOVE_SYNC",arg);
}
}
IEnumerator OpenNav(GameObject fire1,GameObject fire2,GameObject target)
{
yield return new WaitForSeconds(0.5f);
fire1.GetComponent().enabled = true;
fire1.GetComponent().enabled = true;
fire2.GetComponent().enabled = true;
fire2.GetComponent().enabled = true;
}
}