You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.7 KiB
165 lines
4.7 KiB
4 years ago
|
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<Vector3> path;
|
||
|
private bool IsGetOff = false;
|
||
|
private void Start()
|
||
|
{
|
||
|
arm = GetComponent<ArmAction>();
|
||
|
animator = GetComponent<Animator>();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 固定支架
|
||
|
/// </summary>
|
||
|
public void Fixation()
|
||
|
{
|
||
|
animator.speed = 1;
|
||
|
animator.SetBool("ZJ", true);
|
||
|
GetComponent<AgentController>().pathFindEnable = false;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 收起固定支架
|
||
|
/// </summary>
|
||
|
private void FixationReset()
|
||
|
{
|
||
|
animator.speed = 5;
|
||
|
animator.SetBool("ZJ", false);
|
||
|
if (GetComponent<TruckBindWaterSource>().allConnectWaterHose.Count > 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
GetComponent<AgentController>().pathFindEnable = true;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 举臂
|
||
|
/// </summary>
|
||
|
public void ArmLifting(Vector3 position)
|
||
|
{
|
||
|
arm.MoveTo(position, speed);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 手臂复位
|
||
|
/// </summary>
|
||
|
public void ArmReset()
|
||
|
{
|
||
|
arm.ActionReset();
|
||
|
FixationReset();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 下车
|
||
|
/// </summary>
|
||
|
/// <param name="offset">距离车的位置</param>
|
||
|
/// <param name="num">人数</param>
|
||
|
public void GetOff(int offset)
|
||
|
{
|
||
|
if (IsGetOff)
|
||
|
{
|
||
|
LoadPromptWin.Instance.LoadTextPromptWindow("已经完成下车", 1);
|
||
|
return;
|
||
|
}
|
||
|
int num = (int)GetComponent<TruckMessage>().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);
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 在指定点克隆消防员
|
||
|
/// </summary>
|
||
|
/// <param name="pos"></param>
|
||
|
public void CloneFireman(Vector3 pos)
|
||
|
{
|
||
|
var arg = new CloneCmdArgs();
|
||
|
arg.gameObjID = GetComponent<CloneGameObjInfo>().GameObjID;
|
||
|
arg.cloneObjType = CloneObjType.fireman;
|
||
|
arg.hitPos = pos;
|
||
|
CloneCommand.Instance.Execute(EntitiesManager.Instance.CreateObjID(CurrentUserInfo.mySelf.Id), arg);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取克隆路径
|
||
|
/// </summary>
|
||
|
/// <param name="dir">克隆路径对于相对位置的向量的方向</param>
|
||
|
/// <param name="distance">克隆路径的对于相对位置偏移距离</param>
|
||
|
/// <param name="num">克隆点的数量</param>
|
||
|
/// <param name="r">克隆路径的旋转角度</param>
|
||
|
/// <param name="pos">克隆路径的相对位置</param>
|
||
|
/// <returns></returns>
|
||
|
public List<Vector3> GetClonePath(Vector3 dir, int distance, int num, Quaternion r, Vector3 pos)
|
||
|
{
|
||
|
List<Vector3> tempPath = new List<Vector3>();
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 检查路径是否可用,
|
||
|
/// </summary>
|
||
|
/// <param name="path"></param>
|
||
|
/// <returns></returns>
|
||
|
private bool CheckClonePath(List<Vector3> 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;
|
||
|
}
|
||
|
}
|