using AX.InputSystem; using AX.MessageSystem; using AX.NetworkSystem; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class CarSkill : MonoBehaviour { float speed = 20; //举臂动作 private ArmAction arm; //动画动作 private Animator animator; //下车路径 private List path; private bool IsGetOff = false; private void Start() { arm = GetComponent(); animator = GetComponent(); } /// /// 固定支架 /// public void Fixation() { animator.speed = 1; animator.SetBool("ZJ", true); GetComponent().pathFindEnable = false; GetComponent().ControlTruckArmFlag = true; } /// /// 收起固定支架 /// private void FixationReset() { animator.speed = 5; animator.SetBool("ZJ", false); if (GetComponent().allConnectWaterHose.Count > 0) { return; } GetComponent().pathFindEnable = true; } /// /// 举臂 /// public void ArmLifting(Vector3 position) { arm.MoveTo(position, speed); } /// /// 手臂复位 /// public void ArmReset() { // arm.ActionReset(); FixationReset(); GetComponent().ControlTruckArmFlag = false; } /// /// 下车 /// /// 距离车的位置 /// 人数 public void GetOff(int offset) { if (IsGetOff) { LoadPromptWin.Instance.LoadTextPromptWindow("已经完成下车", 1); return; } int num = (int)GetComponent().MyCarMessage.PassengerCapacity; path = GetClonePath(Vector3.left, offset, num,transform.rotation,transform.position); if (path == null) { path = GetClonePath(Vector3.right, offset, num,transform.rotation,transform.position); } if (path != null) { IsGetOff = true; for (int i = 0; i < path.Count; i++) { CloneFireman(path[i]); } } else { LoadPromptWin.Instance.LoadTextPromptWindow("没有可以下车的位置", 1); } } /// /// 在指定点克隆消防员 /// /// public void CloneFireman(Vector3 pos) { var arg = new CloneCmdArgs(); arg.gameObjID = GetComponent().GameObjID; arg.cloneObjType = CloneObjType.fireman; arg.hitPos = pos; CloneCommand.Instance.Execute(EntitiesManager.Instance.CreateObjID(CurrentUserInfo.mySelf.Id), arg); } /// /// 获取克隆路径 /// /// 克隆路径对于相对位置的向量的方向 /// 克隆路径的对于相对位置偏移距离 /// 克隆点的数量 /// 克隆路径的旋转角度 /// 克隆路径的相对位置 /// public List GetClonePath(Vector3 dir, int distance, int num, Quaternion r, Vector3 pos) { List tempPath = new List(); Vector3 startPos = (pos + (r * Vector3.forward) * 8); Vector3 start = (startPos + (r * dir) * distance); //克隆点阵 for (int i = 0; i < num; i++) { Vector3 end = (start - (r * Vector3.forward) * 1); tempPath.Add(end); start = end; } if (CheckClonePath(tempPath)) { return tempPath; } else { return null; } } /// /// 检查路径是否可用, /// /// /// private bool CheckClonePath(List path) { bool b = true; int[] list = new int[path.Count]; for (int i = 0; i < path.Count; i++) { int res = list[i]; NavMeshHit hit; // 对高度进行修正 for (int k = -10; k < 30; ++k) { if (NavMesh.SamplePosition(path[i], out hit, 0.2f, NavMesh.AllAreas)) { res = 1; break; } else { b = false; } } Debug.DrawRay(path[i], Vector3.up, res == 1 ? Color.green : Color.red, 5); } return b; } }