using AX.InputSystem; using AX.MessageSystem; using UnityEngine; public class HighSprayingTruckArm : ControlTruckArm { private Transform part3; private Transform part4; private Transform part5; private Transform part6; private Transform part8; private Transform water; public bool firstZero = true; public bool firstFull = false; public bool secondZero = true; public bool secondFull = false; public bool thirdZero = true; public bool thirdFull = false; public bool fourthZero = true; public bool fourthFull = false; private bool allzero = true;//下降极限 private bool allfull = false;//上升极限 const float Maxlength = 15.8f; const float Minlength = 0.01634139f; //private float part7EulerAngleX = 0; private float part8EulerAngleX = 0; private bool selfctrl = true; private void Start() { GameObjID = GetComponent().GameObjID; } protected override void InitObject() { HorizontalBaseSupport = this.transform.Find("Bi"); VerticalBaseSupport = this.transform.Find("Bi/Bi1"); part3 = this.transform.Find("Bi/Bi1/Bi2"); part4 = this.transform.Find("Bi/Bi1/Bi2/Bi3"); part5 = this.transform.Find("Bi/Bi1/Bi2/Bi3/Bi4"); part6 = this.transform.Find("Bi/Bi1/Bi2/Bi3/Bi4/Bi5"); LastArm = this.transform.Find("Bi/Bi1/Bi2/Bi3/Bi4/Bi5/Bi6"); part8 = this.transform.Find("Bi/Bi1/Bi2/Bi3/Bi4/Bi5/Bi6/Sprayer"); Part1MinFrame_y = HorizontalBaseSupport.localEulerAngles.y; Part2MinFrame_x = VerticalBaseSupport.localEulerAngles.x; Part3MinFrame_z = part3.localPosition.z; Part4MinFrame_z = part4.localPosition.z; Part5MinFrame_z = part5.localPosition.z; Part6MinFrame_z = part6.localPosition.z; } public bool AllZero { get { return allzero; } private set { allzero = value; } } public bool AllFull { get { return allfull; } private set { allfull = value; } } float part3maxframe_z = 0; float Part1MaxFrame_y = 360f; float Part1MinFrame_y; float Part2MaxFrame_x = 84f; float Part2MinFrame_x = 3.542f; public float Part3MaxFrame_z { set { if (value >= Maxlength) part3maxframe_z = Maxlength; else part3maxframe_z = value; } get { return part3maxframe_z; } } float Part3MinFrame_z; float part4maxframe_z = 0; public float Part4MaxFrame_z { set { if (value >= Maxlength) part4maxframe_z = Maxlength; else part4maxframe_z = value; } get { return part4maxframe_z; } } float Part4MinFrame_z; float part5maxframe_z = 0; public float Part5MaxFrame_z { set { if (value >= Maxlength) part5maxframe_z = Maxlength; else part5maxframe_z = value; } get { return part5maxframe_z; } } float Part5MinFrame_z; float part6maxframe_z = 0; public float Part6MaxFrame_z { set { if (value >= Maxlength) part6maxframe_z = Maxlength; else part6maxframe_z = value; } get { return part6maxframe_z; } } float Part6MinFrame_z; public float part6currentheight { set { fourthFull = false; fourthZero = false; if (value >= Part6MaxFrame_z) { value = Part6MaxFrame_z; fourthFull = true; } if (value <= Part6MinFrame_z) { value = Part6MinFrame_z; fourthZero = true; } part6.localPosition = new Vector3(0.002715454f, 0.2560883f, value); } get { return part6.localPosition.z; } } public float part5currentheight { set { thirdZero = false; thirdFull = false; if (value >= Part5MaxFrame_z) { value = Part5MaxFrame_z; thirdFull = true; } if (value <= Part5MinFrame_z) { value = Part5MinFrame_z; thirdZero = true; } part5.localPosition = new Vector3(0, 0, value); } get { return part5.localPosition.z; } } public float part4currentheight { set { secondZero = false; secondFull = false; if (value >= Part4MaxFrame_z) { value = Part4MaxFrame_z; secondFull = true; } if (value <= Part4MinFrame_z) { value = Part4MinFrame_z; secondZero = true; } part4.localPosition = new Vector3(0, 0, value); } get { return part4.localPosition.z; } } public float part3currentheight { set { firstFull = false; firstZero = false; if (value >= Part3MaxFrame_z) { value = Part3MaxFrame_z; firstFull = true; } if (value <= Part3MinFrame_z) { value = Part3MinFrame_z; firstZero = true; } part3.localPosition = new Vector3(-0.037948f, 0.2298138f, value); } get { return part3.localPosition.z; } } public void Restoration() { part3currentheight = Part3MinFrame_z; part4currentheight = Part4MinFrame_z; part5currentheight = Part5MinFrame_z; part6currentheight = Part6MinFrame_z; } public override void Raise(float weight) { if (AllFull) return; AllZero = false; if (!fourthFull) part6currentheight += weight; if (fourthFull && !thirdFull) part5currentheight += weight; if (thirdFull && !secondFull) part4currentheight += weight; if (secondFull && !firstFull) part3currentheight += weight; if (firstFull && secondFull && thirdFull && fourthFull) { AllFull = true; //if (RecordEvent.IsRecord()) // AddSizeEvent(transform); } OutArmLength += weight; if (RecordEvent.IsRecord()) { TruckArmRiceData data = new TruckArmRiceData() { GameId = gameinfo.gameObjID, IsRice = true, AllZero = AllZero, AllFull = AllFull, fourth = fourthFull, third = thirdFull, second = secondFull, first = firstFull, part6currentheight = part6currentheight, part5currentheight = part5currentheight, part4currentheight = part4currentheight, part3currentheight = part3currentheight, OutArmLength = OutArmLength, }; AddTruckArmRiceEvent(data); } } public override void SetOutArmLength(float outarmlength) { if (AllFull) return; AllZero = false; OutArmLength = 0f; if (!fourthFull) { part6currentheight += outarmlength; OutArmLength += part6currentheight; outarmlength -= part6currentheight; } if (fourthFull && !thirdFull) { part5currentheight += outarmlength; OutArmLength += part5currentheight; outarmlength -= part5currentheight; } if (thirdFull && !secondFull) { part4currentheight += outarmlength; OutArmLength += part4currentheight; outarmlength -= part4currentheight; } if (secondFull && !firstFull) { part3currentheight += outarmlength; OutArmLength += part3currentheight; outarmlength -= part3currentheight; } if (firstFull && secondFull && thirdFull && fourthFull) { AllFull = true; } } public override void Decline(float weight) { if (AllZero) return; AllFull = false; if (!fourthZero) part6currentheight -= weight; if (fourthZero && !thirdZero) part5currentheight -= weight; if (thirdZero && !secondZero) part4currentheight -= weight; if (secondZero && !firstZero) part3currentheight -= weight; if (firstZero && secondZero && thirdZero && fourthZero) { AllZero = true; //if (RecordEvent.IsRecord()) // AddSizeEvent(transform); } OutArmLength -= weight; if (RecordEvent.IsRecord()) { TruckArmRiceData data = new TruckArmRiceData() { GameId = gameinfo.gameObjID, IsRice = false, AllZero = AllZero, AllFull = AllFull, fourth = fourthZero, third = thirdZero, second = secondZero, first = firstZero, part6currentheight = part6currentheight, part5currentheight = part5currentheight, part4currentheight = part4currentheight, part3currentheight = part3currentheight, OutArmLength = OutArmLength, }; AddTruckArmRiceEvent(data); } } /// /// 赋值车臂最大的的高度 /// /// 高度 public override void SetHeight(float height) { var Jieshu = Mathf.FloorToInt(height / Maxlength); float yushu = 0; for (int i = 1; i <= Jieshu; i++) { if (i == Jieshu) yushu = height % Maxlength; else yushu = Maxlength; if (i == 1) Part3MaxFrame_z = yushu; if (i == 2) Part4MaxFrame_z = yushu; if (i == 3) Part5MaxFrame_z = yushu; if (i == 4) Part6MaxFrame_z = yushu; } } public override void FixedSupport(IMessage message) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { ControlTruckArmFlag = true; // AddListener(); CarAnimationCtrl.Down(); } } public override void PackUpTheLiftArm(IMessage message) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { ControlTruckArmFlag = false; CarAnimationCtrl.Up(); OutArmLength = 0f; // RemoveListener(); HorizontalBaseSupport.localEulerAngles = Vector3.zero; VerticalBaseSupport.localEulerAngles = new Vector3(356.4572f, 0, 0);//模型穿插,调整模型预设后,这里参数也跟着修改。 part3currentheight = Part3MinFrame_z; part4currentheight = Part4MinFrame_z; part5currentheight = Part5MinFrame_z; part6currentheight = Part6MinFrame_z; LastArm.localEulerAngles = Vector3.zero; LastArmEulerAngleX = 0; part8.localEulerAngles = Vector3.zero; part8EulerAngleX = 0; allzero = true; allfull = false; } } public override void AutoLiftTruckArm(IMessage message) { } public override void LeftShift_J(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID==GameObjID) { var speed = ((WeightCmdArgs)message.Data).Weight; LastArmEulerAngleX += speed; LastArmEulerAngleX = Mathf.Clamp(LastArmEulerAngleX, -175, 0); LastArm.localEulerAngles = new Vector3(LastArmEulerAngleX, 0, 0); if (RecordEvent.IsRecord()) { TruckArmRotateData data = new TruckArmRotateData() { GameId = gameinfo.gameObjID, ArmType = RotateArmType.LastArm, EulerAngle = LastArm.localEulerAngles, }; AddTruckArmRotateEvent(data); } } } } public override void LeftShift_U(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { var speed = ((WeightCmdArgs)message.Data).Weight; LastArmEulerAngleX -= speed; LastArmEulerAngleX = Mathf.Clamp(LastArmEulerAngleX, -175, 0); LastArm.localEulerAngles = new Vector3(LastArmEulerAngleX, 0, 0); if (RecordEvent.IsRecord()) { TruckArmRotateData data = new TruckArmRotateData() { GameId = gameinfo.gameObjID, ArmType = RotateArmType.LastArm, EulerAngle = LastArm.localEulerAngles, }; AddTruckArmRotateEvent(data); } } } } public override void D(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { var speed = ((WeightCmdArgs)message.Data).Weight; HorizontalBaseSupport.localEulerAngles += new Vector3(0, speed, 0); if (RecordEvent.IsRecord()) { TruckArmRotateData data = new TruckArmRotateData() { GameId = gameinfo.gameObjID, ArmType = RotateArmType.HorizontalBaseSupport, EulerAngle = HorizontalBaseSupport.localEulerAngles, }; AddTruckArmRotateEvent(data); } } } } public override void A(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { var speed = ((WeightCmdArgs)message.Data).Weight; HorizontalBaseSupport.localEulerAngles -= new Vector3(0, speed, 0); if (RecordEvent.IsRecord()) { TruckArmRotateData data = new TruckArmRotateData() { GameId = gameinfo.gameObjID, ArmType = RotateArmType.HorizontalBaseSupport, EulerAngle = HorizontalBaseSupport.localEulerAngles, }; AddTruckArmRotateEvent(data); } } } } public override void S(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { var speed = ((WeightCmdArgs)message.Data).Weight; float x = VerticalBaseSupport.localEulerAngles.x; float y = VerticalBaseSupport.localEulerAngles.y; x = CheckValue(x); x += speed; x = Mathf.Clamp(x, -84, -3.542f);//模型穿插,调整模型预设后,这里参数也跟着修改。 VerticalBaseSupport.localEulerAngles = new Vector3(x, y, 0); if (RecordEvent.IsRecord()) { TruckArmRotateData data = new TruckArmRotateData() { GameId = gameinfo.gameObjID, ArmType = RotateArmType.VerticalBaseSupport, EulerAngle = VerticalBaseSupport.localEulerAngles, }; AddTruckArmRotateEvent(data); } } } } public override void W(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { var speed = ((WeightCmdArgs)message.Data).Weight; float x = VerticalBaseSupport.localEulerAngles.x; float y = VerticalBaseSupport.localEulerAngles.y; x = CheckValue(x); x -= speed; x = Mathf.Clamp(x, -84, -3.542f); VerticalBaseSupport.localEulerAngles = new Vector3(x, y, 0); if (RecordEvent.IsRecord()) { TruckArmRotateData data = new TruckArmRotateData() { GameId = gameinfo.gameObjID, ArmType = RotateArmType.VerticalBaseSupport, EulerAngle = VerticalBaseSupport.localEulerAngles, }; AddTruckArmRotateEvent(data); } } } } public override void LeftShift_S(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { //if (RecordEvent.IsRecord() && !AllZero) // CreateSizeEvent(this.transform); var weight = ((WeightCmdArgs)message.Data).Weight / 4f; Decline(weight); } } } public override void LeftShift_W(IMessage message) { if (selfctrl) { var gameObjID = (long)message.Sender; if (gameObjID == GameObjID) { //if (RecordEvent.IsRecord() && !AllFull) // CreateSizeEvent(this.transform); var weight = ((WeightCmdArgs)message.Data).Weight / 4f; Raise(weight); } } } public override void ReplayArmRice(TruckArmRiceData data) { if (data.IsRice) { AllZero = data.AllZero; AllFull = data.AllFull; fourthFull = data.fourth; thirdFull = data.third; secondFull = data.second; firstFull = data.first; part6currentheight = data.part6currentheight; part5currentheight = data.part5currentheight; part4currentheight = data.part4currentheight; part3currentheight = data.part3currentheight; OutArmLength = data.OutArmLength; } else { AllZero = data.AllZero; AllFull = data.AllFull; fourthZero = data.fourth; thirdZero = data.third; secondZero = data.second; firstZero = data.first; part6currentheight = data.part6currentheight; part5currentheight = data.part5currentheight; part4currentheight = data.part4currentheight; part3currentheight = data.part3currentheight; OutArmLength = data.OutArmLength; } } public override void ReplayArmRotate(TruckArmRotateData data) { if (data.ArmType == RotateArmType.LastArm) { LastArm.localEulerAngles = data.EulerAngle; } else if (data.ArmType == RotateArmType.HorizontalBaseSupport) { HorizontalBaseSupport.localEulerAngles = data.EulerAngle; } else if (data.ArmType == RotateArmType.VerticalBaseSupport) { VerticalBaseSupport.localEulerAngles = data.EulerAngle; } } }