private void FixedUpdate() { cargoMessage = cargo.GetComponent <ShowCargoInfo>().Cargomessage; Debug.Log("进入cargoEnterController"); Debug.Log("货物设备队列的数目:" + cargoMessage.EquipmentsQueue.Count); //货物信息 //从货物的设备队列中取出一个设备 GameObject equipment = cargoMessage.EquipmentsQueue.Peek(); //货物经过当前设备,准备进入下一个设备 if (EquipExtension.isCrossEquip(cargo, equipment)) { //出队,换新设备 cargoMessage.EquipmentsQueue.Dequeue(); GameObject nextEquip = cargoMessage.EquipmentsQueue.Peek(); if (nextEquip != null) { cargo.transform.parent = nextEquip.transform; } else { Debug.Log("货物" + cargo.name + "入库已经完成!"); } } //设备队列不空 //while (cargoMessage.EquipmentsQueue.Count > 0) //{ // //货物信息 // //从货物的设备队列中取出一个设备 // GameObject equipment = cargoMessage.EquipmentsQueue.Peek(); // //货物经过当前设备,准备进入下一个设备 // if (EquipExtension.isCrossEquip(cargo, equipment)) // { // //出队,换新设备 // cargoMessage.EquipmentsQueue.Dequeue(); // GameObject nextEquip = cargoMessage.EquipmentsQueue.Peek(); // if (nextEquip != null) // { // cargo.transform.parent = nextEquip.transform; // } // else // { // Debug.Log("货物" + cargo.name + "入库已经完成!"); // } // } //} }
//检测货物是否越过设备 public static bool isCrossEquip(GameObject cargo, GameObject equipment) { Vector3 finalCargoPos = new Vector3(0, 0, 0); EquipmentState es = equipment.GetComponent <ShowEquipState>().equipmentState; switch (es.kind) { case "BeltConveyor": finalCargoPos.y += GlobalVariable.KPD.HighValues[0]; finalCargoPos += es.deliverDirection * GlobalVariable.KPD.ConveyorLengths[0]; break; case "RollerConveyor": finalCargoPos.y += GlobalVariable.KPD.HighValues[1]; finalCargoPos += es.deliverDirection * GlobalVariable.KPD.ConveyorLengths[1]; break; case "LiftTransfer": finalCargoPos.y += GlobalVariable.KPD.HighValues[1]; //如果下一个设备是顶升部分吗,在中心就要直接换设备 if (EquipExtension.nextEquipKind(cargo).Equals("LiftPart")) { } else { finalCargoPos += es.deliverDirection * GlobalVariable.KPD.ConveyorWidth; } break; case "LiftPart": //这个不一样 //抬升货物是在顶升边缘,放下货物是在顶升下落的中心 finalCargoPos += es.deliverDirection * GlobalVariable.KPD.ConveyorWidth / 2; break; default: break; } return(cargo.transform.localPosition == finalCargoPos); }
//判断货物是否到达设备过渡点( public static bool isCrossTrans(GameObject cargo, GameObject equipment) { CargoMessage cm = cargo.GetComponent <ShowCargoInfo>().Cargomessage; Vector3 cargoTransPos = new Vector3(0, 0, 0); EquipmentState es = equipment.GetComponent <ShowEquipState>().equipmentState; switch (es.kind) { case "BeltConveyor": cargoTransPos.y += GlobalVariable.KPD.HighValues[0]; cargoTransPos += es.deliverDirection * (GlobalVariable.KPD.ConveyorLengths[0] - cm.Size.x / 2); break; case "RollerConveyor": cargoTransPos.y += GlobalVariable.KPD.HighValues[1]; cargoTransPos += es.deliverDirection * (GlobalVariable.KPD.ConveyorLengths[1] - cm.Size.x / 2); break; case "LiftTransfer": cargoTransPos.y += GlobalVariable.KPD.HighValues[1]; //如果下一个设备是顶升部分,在顶升的中心进行过度 if (EquipExtension.nextEquipKind(cargo).Equals("LiftPart")) { } else { cargoTransPos += es.deliverDirection * GlobalVariable.KPD.ConveyorWidth; } break; case "LiftPart": //抬升是在上升点的中心,放下货物是在下落点的中心 return(equipment.transform.localPosition.y == GlobalVariable.KPD.HighValues[0]); default: break; } return(cargo.transform.localPosition == cargoTransPos); }
// Update is called once per frame //控制设备的开启和关闭 void FixedUpdate() { EquipmentState es = equipment.GetComponent <ShowEquipState>().equipmentState; //让该设备上所有的货物都运动 List <GameObject> cargoList = new List <GameObject>(); FindExtension.FindGameObjectsWithTagRecursive(equipment, "Cargo", ref cargoList); //设备坏了,停止工作 if (es.facilityState == FacilityState.Error) { es.workState = State.Off; } //货物过渡 foreach (GameObject cargo in cargoList) { CargoMessage cm = cargo.GetComponent <ShowCargoInfo>().Cargomessage; if (EquipExtension.isCrossTrans(cargo, equipment))//到达过渡位置 { GameObject nextEquip = cm.EquipmentsQueue.ElementAt(2); EquipmentState nextEquipState = new EquipmentState();//有问题 List <GameObject> nextCargoList = new List <GameObject>(); FindExtension.FindGameObjectsWithTagRecursive(equipment, "Cargo", ref nextCargoList); //如果是最后一个传送带设备,关闭当前设备 if (nextEquip == null) { es.workState = State.Off; } else { nextEquipState = nextEquip.GetComponent <ShowEquipState>().equipmentState; } //货物下一个设备是最后一个顶升,这个顶升对它来说是独占设备 if (EquipExtension.isNextLastLiftTransfer(cargo)) { if (nextCargoList.Count > 0)//顶升上有货物 { es.workState = State.Off; } else { nextEquipState.isExcusive = Exclusive.Yes; } } //下一个设备开启 if (nextEquipState.workState == State.On) { if (nextEquipState.isExcusive == Exclusive.Yes)//如果是独占设备,本设备关闭 { es.workState = State.Off; } } //下一个设备关闭 if (nextEquipState.workState == State.Off) { if (nextCargoList.Count == 0)//下一个设备上没有货物,开启下一个设备 { nextEquipState.workState = State.On; } else //下一个设备有货物,关闭本设备 { es.workState = State.Off; } } } } //过渡思路 #region //if (货物到达设备关键点2)//准备过渡 //{ // 拿出下一个设备 // if (下一个设备不存在) // { // 设备=off // } // if(下一个设备On) // { // if (设备只能被单独占用(比如顶升)){ // 设备=off // } else { // 货物继续运动 // } // } // if (下一个设备off && 下一个设备的货物队列 == 0) // { // if (下一个设备 == Normal) // { // 下一个设备=on; // } // } // if(下一个设备off && 下一个设备货物队列 > 0) // { // 本设备=off; // } //} #endregion }