public override void Enter(int preStateName)
        {
            base.Enter(preStateName);

            owner.MarkGameObject();

            SWS_Walk(owner.mainGameObject, owner.idxInTeam);
            if (owner.idxInTeam == owner.animalTeamModel.entityCrossRoadAnimalList.Count - 1)
            {
                ++owner.animalTeamModel.currentRoad;
                CrossRoadCameraController.GetInstance().MoveCamera(
                    CrossRoadModelManager.GetInstance().endPos);
            }
        }
예제 #2
0
        void Tick_Move(int deltaTimeMS)
        {
            if (!owner.isMoving)
            {
                return;
            }

            if (owner.arrivedLastPos)
            {
                return;
            }

            if (owner.isRotateForward || owner.isRotateback)
            {
                owner.PlayIdle();
                return;
            }

            //第一条到倒数第二条路
            if (owner.animalTeamModel.currentRoad < owner.cellStage.roadnum - 1)
            {
                //过马路记录
                if (owner.IsPassed(owner.firstPos) && !owner.isPassedRoad)
                {
                    owner.isPassedRoad = true;
                    owner.animalTeamModel.passedCurrRoadSet.Add(owner.idxInTeam);
                    DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", owner.idxInTeam),
                                                         "PassedFirstPos, currentRoad={0}", owner.animalTeamModel.currentRoad);
                }

                //到达终点记录
                if (owner.IsPassed(owner.nextRoadPos) && !owner.isArrivedNextRoadPos)
                {
                    owner.isArrivedNextRoadPos = true;
                    owner.position             = owner.targetPos;
                    owner.isMoving             = false;
                    owner.PlayIdle();
                    //自身开启往后转
                    if (owner.idxInTeam < owner.maxIdxInTeam)
                    {
                        owner.isRotateback = true;
                    }

                    //最后一个人到达,所有人到达
                    if (owner.idxInTeam == owner.maxIdxInTeam)
                    {
                        CrossRoadCameraController.GetInstance().MoveCamera(owner.nextFirstPos);
                        //owner.animalTeamModel.passedCurrRoadSet.Clear();

                        //++owner.animalTeamModel.currentRoad;

                        //设置最大前转等待时间
                        //owner.animalTeamModel.maxWaitRotateForward =
                        //    (int)owner.animalTeamModel.entityCrossRoadAnimalList[0].rotateAngle;


                        owner.animalTeamModel.maxWaitRotateForward = (int)(double)(
                            owner.animalTeamModel.entityCrossRoadAnimalList[0].rotateAngle / owner.rotateSpeedMS);

                        DebugFile.GetInstance().WriteKeyFile("CrossRoad", "currentRoad = {0}", owner.animalTeamModel.currentRoad);

                        for (int i = 0; i <= owner.maxIdxInTeam; i++)
                        {
                            var animal = owner.animalTeamModel.entityCrossRoadAnimalList[i];
                            animal.isMoving = false;
                            //animal.isPassedRoad = false;
                            animal.moveSpeed = animal.moveSpeedBak;

                            DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", owner.idxInTeam),
                                                                 "isMoving = false {0}, currentRoad={1}", 1, owner.animalTeamModel.currentRoad);

                            //除了最后一个全切到向前转
                            if (i < owner.maxIdxInTeam && !animal.isRotateForward)
                            //if (i < owner.maxIdxInTeam)
                            {
                                animal.isRotateForward = true;
                                animal.waitFrameCount  = 0;
                            }
                        }

                        //Debug.LogErrorFormat("LastTwo rotateForward {0}",
                        //    owner.animalTeamModel.currentRoad);
                    }
                    return;
                }
            }
            //最后一条路
            else if (owner.animalTeamModel.currentRoad == owner.cellStage.roadnum - 1)
            {
                if (owner.IsPassed(owner.firstPos))
                {
                    owner.isPassedRoad = true;
                    owner.animalTeamModel.passedCurrRoadSet.Add(owner.idxInTeam);
                }

                if (owner.IsPassed(owner.lastRoadPos))
                {
                    owner.PlayWalk();
                    owner.isMoving       = false;
                    owner.position       = owner.lastRoadPos;
                    owner.arrivedLastPos = true;

                    //切到跑终点状态
                    isToStateRunToEndPoint = true;
                    return;
                }
            }
            else
            {
                return;
            }

            //到达目标点停止
            if (owner.IsPassed(owner.targetPos))
            {
                owner.position = owner.targetPos;
                owner.isMoving = false;
                DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", owner.idxInTeam),
                                                     "isMoving = false {0}, currentRoad={1}", 3, owner.animalTeamModel.currentRoad);
                owner.PlayIdle();
                return;
            }

            //position += Vector3.forward * moveSpeed * deltaTimeMS;

            //return;
            //跨马路的时候加速
            if (owner.IsPassed(owner.firstPos))
            {
                //float animalAcceleration = CrossRoadStageManager.GetInstance().animalAcceleration;
                //float delta = owner.moveSpeed + animalAcceleration * 0.001f;
                //owner.position += Vector3.forward * delta * deltaTimeMS;
                //owner.moveSpeed = delta;

                float delta = owner.moveSpeed + owner.animalAccelerationMS;
                owner.position += Vector3.forward * delta * deltaTimeMS;
                owner.moveSpeed = delta;
                owner.PlayWalk();
            }
            else
            {
                owner.position += Vector3.forward * owner.moveSpeed * deltaTimeMS;
                owner.PlayWalk();
            }
        }
        public override void Tick(int deltaTimeMS)
        {
            if (!this.CouldActive())
            {
                return;
            }

            if (!isMoving)
            {
                return;
            }

            if (arrivedLastPos)
            {
                return;
            }

            if (animalTeamModel.currentRoad < cellStage.roadnum - 1)
            {
                //过马路记录
                if (IsPassed(firstPos))
                {
                    isPassedRoad = true;
                    animalTeamModel.passedCurrRoadSet.Add(idxInTeam);
                    DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", idxInTeam),
                                                         "PassedFirstPos, currentRoad={0}", animalTeamModel.currentRoad);
                }

                //到达终点记录
                if (IsPassed(nextRoadPos))
                {
                    //所有人到达
                    if (idxInTeam == animalTeamModel.entityCrossRoadAnimalList.Count - 1)
                    {
                        CrossRoadCameraController.GetInstance().MoveCamera(nextFirstPos);
                        animalTeamModel.passedCurrRoadSet.Clear();
                        ++animalTeamModel.currentRoad;
                        DebugFile.GetInstance().WriteKeyFile("CrossRoad", "currentRoad = {0}", animalTeamModel.currentRoad);
                        for (int i = 0; i < animalTeamModel.entityCrossRoadAnimalList.Count; i++)
                        {
                            var animal = animalTeamModel.entityCrossRoadAnimalList[i];
                            animal.isMoving     = false;
                            animal.isPassedRoad = false;
                            animal.moveSpeed    = CrossRoadStageManager.GetInstance().animalMoveSpeed * 0.001f;
                            DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", idxInTeam),
                                                                 "isMoving = false {0}, currentRoad={1}", 1, animalTeamModel.currentRoad);
                        }
                    }
                    position = targetPos;
                    isMoving = false;
                    DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", idxInTeam),
                                                         "isMoving = false {0}, currentRoad={1}", 2, animalTeamModel.currentRoad);
                    PlayIdle();
                    return;
                }
            }
            else if (animalTeamModel.currentRoad == cellStage.roadnum - 1)
            {
                if (IsPassed(firstPos))
                {
                    isPassedRoad = true;
                    animalTeamModel.passedCurrRoadSet.Add(idxInTeam);
                }

                if (IsPassed(lastRoadPos))
                {
                    PlayWalk();
                    isMoving       = false;
                    position       = lastRoadPos;
                    arrivedLastPos = true;
                    SWS_Walk(mainGameObject, idxInTeam);
                    if (idxInTeam == animalTeamModel.entityCrossRoadAnimalList.Count - 1)
                    {
                        ++animalTeamModel.currentRoad;
                        CrossRoadCameraController.GetInstance().MoveCamera(
                            CrossRoadModelManager.GetInstance().endAnimalTransferPos + Vector3.forward * 50f);
                    }
                    return;
                }
            }
            else
            {
                return;
            }

            //到达目标点停止
            if (IsPassed(targetPos))
            {
                position = targetPos;
                isMoving = false;
                DebugFile.GetInstance().WriteKeyFile(string.Format("Animal-{0}", idxInTeam),
                                                     "isMoving = false {0}, currentRoad={1}", 3, animalTeamModel.currentRoad);
                PlayIdle();
                return;
            }


            //position += Vector3.forward * moveSpeed * deltaTimeMS;

            ////跨马路的时候速度最快
            //if (IsPassed(firstPos))
            //{
            //    position += Vector3.forward * moveSpeed * deltaTimeMS;
            //}
            //else
            //{
            //    position += Vector3.forward * moveSpeed * 0.4f * deltaTimeMS;
            //}

            //跨马路的时候加速
            if (IsPassed(firstPos))
            {
                //匀加速或者减速
                float animalAcceleration = CrossRoadStageManager.GetInstance().animalAcceleration;
                float animalMaxSpeed     = CrossRoadStageManager.GetInstance().animalMaxSpeed;
                float animalMinSpeed     = CrossRoadStageManager.GetInstance().animalMinSpeed;

                Vector3 old   = Vector3.forward * moveSpeed * deltaTimeMS;
                float   delta = (moveSpeed + animalAcceleration * 0.001f) * deltaTimeMS;
                float   max   = animalMaxSpeed * 0.001f * deltaTimeMS;
                float   min   = animalMinSpeed * 0.001f * deltaTimeMS;
                if (animalAcceleration > 0)
                {
                    delta = Mathf.Min(delta, max);
                }
                else
                {
                    delta = Mathf.Max(delta, min);
                }
                position += Vector3.forward * delta;
                moveSpeed = delta / deltaTimeMS;
            }
            else
            {
                position += Vector3.forward * moveSpeed * deltaTimeMS;
            }


            ////前面的比后面的快
            //float delta = moveSpeed * (1 - idxInTeam / 15f);
            //position += Vector3.forward * delta * deltaTimeMS;
            //Debug.LogErrorFormat("{0}, {1}, {2}", idxInTeam, moveSpeed, delta);

            ////匀加速或者减速
            //float animalAcceleration = CrossRoadStageManager.GetInstance().animalAcceleration;
            //float animalMaxSpeed = CrossRoadStageManager.GetInstance().animalMaxSpeed;
            //float animalMinSpeed = CrossRoadStageManager.GetInstance().animalMinSpeed;

            //Vector3 old = Vector3.forward * moveSpeed * deltaTimeMS;
            //float delta = (moveSpeed + animalAcceleration * 0.001f) * deltaTimeMS;
            //float max = animalMaxSpeed * 0.001f * deltaTimeMS;
            //float min = animalMinSpeed * 0.001f * deltaTimeMS;
            //if (animalAcceleration > 0)
            //{
            //	delta = Mathf.Min(delta, max);
            //}
            //else
            //{
            //	delta = Mathf.Max(delta, min);
            //}
            //position += Vector3.forward * delta;
            //moveSpeed = delta / deltaTimeMS;
        }