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.
235 lines
6.7 KiB
235 lines
6.7 KiB
11 months ago
|
using UnityEngine;
|
||
|
/// <summary>
|
||
|
/// 举高车类控制器
|
||
|
/// </summary>
|
||
|
public class ElevatingController : FireExtinguishController
|
||
|
{
|
||
|
//手动实例化时主臂和二级臂需要展开设为true
|
||
|
//通过数据实例化时主臂和二级臂根据数据设置变换,此时设为false
|
||
|
public bool isInit = true;
|
||
|
//伸展速度
|
||
|
protected float zSpeed = 5;
|
||
|
//功能键按下(配合主键实现二级臂的旋转)
|
||
|
protected bool ctrlDown = false;
|
||
|
//第1伸展臂是否展开
|
||
|
protected bool firstZero = true;
|
||
|
protected bool firstFull = false;
|
||
|
//第2伸展臂是否展开
|
||
|
protected bool secondZero = true;
|
||
|
protected bool secondFull = false;
|
||
|
//第3伸展臂是否展开
|
||
|
protected bool thirdZero = true;
|
||
|
protected bool thirdFull = false;
|
||
|
//第4伸展臂是否展开
|
||
|
protected bool fourthZero = true;
|
||
|
protected bool fourthFull = false;
|
||
|
//第5伸展臂是否展开
|
||
|
protected bool fifthZero = true;
|
||
|
protected bool fifthFull = false;
|
||
|
//臂模型
|
||
|
public GameObject part1;
|
||
|
public GameObject part2;
|
||
|
public GameObject part3;
|
||
|
public GameObject part4;
|
||
|
public GameObject part5;
|
||
|
public GameObject part6;
|
||
|
public GameObject part7;
|
||
|
//记录各个举臂的变换
|
||
|
protected Vector3 part1Rot;
|
||
|
protected Vector3 part1Pos;
|
||
|
protected Vector3 part2Rot;
|
||
|
protected Vector3 part2Pos;
|
||
|
protected Vector3 part3Rot;
|
||
|
protected Vector3 part3Pos;
|
||
|
protected Vector3 part4Rot;
|
||
|
protected Vector3 part4Pos;
|
||
|
protected Vector3 part5Rot;
|
||
|
protected Vector3 part5Pos;
|
||
|
protected Vector3 part6Rot;
|
||
|
protected Vector3 part6Pos;
|
||
|
protected Vector3 part7Rot;
|
||
|
protected Vector3 part7Pos;
|
||
|
|
||
|
public override void InitData()
|
||
|
{
|
||
|
base.InitData();
|
||
|
part1 = transform.Find("Scene/Body/Base").gameObject;
|
||
|
part2 = transform.Find("Scene/Body/Base/Bi1").gameObject;
|
||
|
part3 = transform.Find("Scene/Body/Base/Bi1/Bi2").gameObject;
|
||
|
part4 = transform.Find("Scene/Body/Base/Bi1/Bi2/Bi3").gameObject;
|
||
|
part5 = transform.Find("Scene/Body/Base/Bi1/Bi2/Bi3/Bi4").gameObject;
|
||
|
part6 = transform.Find("Scene/Body/Base/Bi1/Bi2/Bi3/Bi4/Bi5").gameObject;
|
||
|
part7 = transform.Find("Scene/Body/Base/Bi1/Bi2/Bi3/Bi4/Bi5/Bi6").gameObject;
|
||
|
|
||
|
}
|
||
|
private void Start()
|
||
|
{
|
||
|
task = transform.Find("Info/Task").GetComponent<TextMesh>();
|
||
|
GetOriginalTransform();
|
||
|
if (isInit)
|
||
|
Init();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取初始变换数据
|
||
|
/// </summary>
|
||
|
protected virtual void GetOriginalTransform()
|
||
|
{
|
||
|
|
||
|
|
||
|
part1Pos = part1.transform.localPosition;
|
||
|
part1Rot = part1.transform.localEulerAngles;
|
||
|
|
||
|
part2Pos = part2.transform.localPosition;
|
||
|
part2Rot = part2.transform.localEulerAngles;
|
||
|
|
||
|
part3Pos = part3.transform.localPosition;
|
||
|
part3Rot = part3.transform.localEulerAngles;
|
||
|
|
||
|
part4Pos = part4.transform.localPosition;
|
||
|
part4Rot = part4.transform.localEulerAngles;
|
||
|
|
||
|
part5Pos = part5.transform.localPosition;
|
||
|
part5Rot = part5.transform.localEulerAngles;
|
||
|
|
||
|
part6Pos = part6.transform.localPosition;
|
||
|
part6Rot = part6.transform.localEulerAngles;
|
||
|
|
||
|
part7Pos = part7.transform.localPosition;
|
||
|
part7Rot = part7.transform.localEulerAngles;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 初始化
|
||
|
/// </summary>
|
||
|
protected virtual void Init()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
hose.SetActive(isHose = task.text.Contains("灭火") || task.text.Contains("掩护") || task.text.Contains("冷却"));
|
||
|
}
|
||
|
|
||
|
protected override void LateUpdate()
|
||
|
{
|
||
|
base.LateUpdate();
|
||
|
if (SelectionManager.IsContains(gameObject))
|
||
|
{
|
||
|
if (Input.GetKeyDown(PowerManager.Instance.fn))
|
||
|
{
|
||
|
ctrlDown = true;
|
||
|
}
|
||
|
if (Input.GetKeyUp(PowerManager.Instance.fn))
|
||
|
{
|
||
|
ctrlDown = false;
|
||
|
}
|
||
|
if (Input.GetKeyDown(PowerManager.Instance.reset))
|
||
|
OnReset();
|
||
|
|
||
|
BaseControl();
|
||
|
MainArmControl();
|
||
|
SecondArmControl();
|
||
|
PlatformControl();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 水炮旋转控制
|
||
|
/// </summary>
|
||
|
protected override void WaterGunControl()
|
||
|
{
|
||
|
if (!ctrlDown && Input.GetKey(PowerManager.Instance.waterGunUp))
|
||
|
{
|
||
|
waterGun.transform.Rotate(-Time.deltaTime * rotSpeed, 0, 0);
|
||
|
}
|
||
|
else if (!ctrlDown && Input.GetKey(PowerManager.Instance.waterGunDown))
|
||
|
{
|
||
|
waterGun.transform.Rotate(Time.deltaTime * rotSpeed, 0, 0);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 转盘控制
|
||
|
/// </summary>
|
||
|
private void BaseControl()
|
||
|
{
|
||
|
if (Input.GetKey(PowerManager.Instance.leftR))
|
||
|
{
|
||
|
part1.transform.Rotate(0, -Time.deltaTime * rotSpeed, 0);
|
||
|
}
|
||
|
else if (Input.GetKey(PowerManager.Instance.rightR))
|
||
|
{
|
||
|
part1.transform.Rotate(0, Time.deltaTime * rotSpeed, 0);
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 主臂控制
|
||
|
/// </summary>
|
||
|
protected virtual void MainArmControl()
|
||
|
{
|
||
|
if (!ctrlDown && Input.GetKey(PowerManager.Instance.down))
|
||
|
{
|
||
|
part2.transform.Rotate(Time.deltaTime * rotSpeed, 0, 0);
|
||
|
}
|
||
|
else if (!ctrlDown && Input.GetKey(PowerManager.Instance.up))
|
||
|
{
|
||
|
part2.transform.Rotate(-Time.deltaTime * rotSpeed, 0, 0);
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 二级臂控制
|
||
|
/// </summary>
|
||
|
protected virtual void SecondArmControl()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 平台控制
|
||
|
/// </summary>
|
||
|
protected virtual void PlatformControl()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 重置变换
|
||
|
/// </summary>
|
||
|
protected virtual void OnReset()
|
||
|
{
|
||
|
part1.transform.localPosition = part1Pos;
|
||
|
part1.transform.localEulerAngles = part1Rot;
|
||
|
|
||
|
part2.transform.localPosition = part2Pos;
|
||
|
part2.transform.localEulerAngles = part2Rot;
|
||
|
|
||
|
part3.transform.localPosition = part3Pos;
|
||
|
part3.transform.localEulerAngles = part3Rot;
|
||
|
|
||
|
part4.transform.localPosition = part4Pos;
|
||
|
part4.transform.localEulerAngles = part4Rot;
|
||
|
|
||
|
part5.transform.localPosition = part5Pos;
|
||
|
part5.transform.localEulerAngles = part5Rot;
|
||
|
|
||
|
part6.transform.localPosition = part6Pos;
|
||
|
part6.transform.localEulerAngles = part6Rot;
|
||
|
|
||
|
part7.transform.localPosition = part7Pos;
|
||
|
part7.transform.localEulerAngles = part7Rot;
|
||
|
|
||
|
|
||
|
firstZero = true;
|
||
|
firstFull = false;
|
||
|
secondZero = true;
|
||
|
secondFull = false;
|
||
|
thirdZero = true;
|
||
|
thirdFull = false;
|
||
|
fourthZero = true;
|
||
|
fourthFull = false;
|
||
|
fifthZero = true;
|
||
|
fifthFull = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|