Exemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        lps         = this.gameObject.GetComponent <ShowEquipState>().equipmentState as LiftPartState;
        speed       = lps.deliverSpeed;
        direction   = lps.deliverDirection;
        liftPattern = lps.liftPattern;
        //让该设备上所有的货物都运动
        List <GameObject> cargoList = new List <GameObject>();

        FindExtension.FindGameObjectsWithTagRecursive(this.gameObject, "Cargo", ref cargoList);
        if (lps.workState == State.On)
        {
            //顶升已经抬升,移动货物到传送带
            if (LiftPart.transform.localPosition == TargetPosition2)
            {
                if (cargoList.Count > 0)
                {
                    foreach (GameObject cargo in cargoList)
                    {
                        cargo.transform.localPosition += direction * speed * Time.deltaTime;
                    }
                }
                else
                {
                    liftPattern = LiftPattern.down;//没有货物,顶升开始下降
                }
            }
            //抬升(入库)
            if (liftPattern == LiftPattern.up)
            {
                //抬升到1
                LiftPart.transform.localPosition = Vector3.MoveTowards(LiftPart.transform.localPosition, TargetPosition2, speed * Time.deltaTime);
                if (LiftPart.transform.localPosition == TargetPosition2)
                {
                    liftPattern = LiftPattern.off;
                }
            }
            //下降(出库)
            else if (liftPattern == LiftPattern.down)
            {
                LiftPart.transform.localPosition = Vector3.MoveTowards(LiftPart.transform.localPosition, TargetPosition1, speed * Time.deltaTime);
                if (LiftPart.transform.localPosition == TargetPosition1)
                {
                    liftPattern = LiftPattern.off;
                }
            }
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        lts       = this.gameObject.GetComponent <ShowEquipState>().equipmentState as LiftTransferState;
        speed     = lts.deliverSpeed;
        direction = lts.deliverDirection;
        //让该设备上所有的货物都运动
        List <GameObject> cargoList = new List <GameObject>();

        FindExtension.FindGameObjectsWithTagRecursive(this.gameObject, "Cargo", ref cargoList);
        if (lts.workState == State.On)
        {
            foreach (GameObject cargo in cargoList)
            {
                cargo.transform.localPosition += direction * speed * Time.deltaTime;
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        UniConveyorState ucs = this.gameObject.GetComponent <ShowEquipState>().equipmentState as UniConveyorState;

        speed     = ucs.deliverSpeed;
        direction = ucs.deliverDirection;
        //让该设备上所有的货物都运动
        List <GameObject> cargoList = new List <GameObject>();

        FindExtension.FindChildWithTag(this.gameObject, "Cargo", ref cargoList);
        Debug.Log(cargoList.Count);
        if (ucs.workState == State.On)
        {
            foreach (GameObject cargo in cargoList)
            {
                cargo.transform.localPosition += direction * speed * Time.deltaTime;
            }
        }
    }
    // 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
    }