private void Awake()
        {
            FingerGestures.GlobalTouchFilter = FingerGestureShouldProcessTouch;
            GetComponent <LongPressRecognizer>().Duration = CrossRoadStageManager.GetInstance().buttonClickLongPressTime;

            //PageMgr.ShowPage<UILittleGameMainPage>();
        }
        /// <summary>
        /// 接收金钱改变后返回主界面
        /// </summary>
        /// <param name="obj"></param>
        private void OnGetBroadcastDiamondOfPlayerData(Message obj)
        {
            //money_1_Text.text = playerData.playerZoo.playerCoin.GetCoinByScene(playerData.playerZoo.currSceneID).coinShow;

            CrossRoadStageManager.GetInstance().UnLoad();
            ZooGameLoader.GetInstance().BackFromCrossRoad();
        }
Exemple #3
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 100, 200, 50), "Cross Road Camera"))
            {
                TestCamera();
            }

            if (GUI.Button(new Rect(10, 200, 200, 50), "Back To Zoo"))
            {
                CrossRoadStageManager.GetInstance().UnLoad();
                ZooGameLoader.GetInstance().BackFromCrossRoad();
            }

            if (GUI.Button(new Rect(10, 300, 200, 50), "New Stage"))
            {
                CrossRoadStageManager.GetInstance().UnLoad();
                CrossRoadStageManager.GetInstance().Load(1);
                DebugFile.GetInstance().ClearAllFiles();
            }

            if (GUI.Button(new Rect(10, 400, 200, 50), "Retry"))
            {
                //todo 本关卡复活
                //动物卸载,并重新加载
                //相机回到初始
                MessageManager.GetInstance().Send((int)GameMessageDefine.IncreaseCrossRoadStageID);
            }
        }
        /// <summary>
        /// 按钮  再来一次界面
        /// </summary>
        /// <param name="obj"></param>
        private void OnClickAgainButton(string obj)
        {
            //LogWarp.LogError("  按钮  再来一次界面  ");
            int stageID = CrossRoadModelManager.GetInstance().stageID;

            CrossRoadStageManager.GetInstance().UnLoad();
            CrossRoadStageManager.GetInstance().Load(stageID);
            Hide();
        }
        void Next()
        {
            PageMgr.ClosePage <UIGameVictoryPage>();
            PageMgr.ClosePage <UIGameFailPage>();

            int stageID = CrossRoadModelManager.GetInstance().stageID;

            CrossRoadStageManager.GetInstance().UnLoad();
            CrossRoadGame.CrossRoadStageManager.GetInstance().Load(stageID);
        }
        void Next()
        {
            PageMgr.ClosePage <UIGameVictoryPage>();
            PageMgr.ClosePage <UIGameFailPage>();

            SendCrossRoadAward();
            CrossRoadStageManager.GetInstance().UnLoad();
            CrossRoadGame.CrossRoadStageManager.GetInstance().Load(playerData.playerLittleGame.stageID + 1);
            returnButton.enabled  = false;
            receiveButton.enabled = false;
        }
Exemple #7
0
        int GetWaitRotateForward()
        {
            //int wait = owner.animalTeamModel.maxWaitRotateForward
            //    * (owner.maxIdxInTeam - owner.idxInTeam) / 100;
            int wait = (int)(double)(owner.animalTeamModel.maxWaitRotateForward
                                     * (owner.maxIdxInTeam - owner.idxInTeam) * CrossRoadStageManager.GetInstance().waitRotateRatio);

            //int wait = 33 * 5;
            //Debug.LogErrorFormat("{0} , wait = {1}", owner.idxInTeam, wait);
            return(wait);
        }
 /// <summary>
 /// 按钮  返回主界面
 /// </summary>
 /// <param name="obj"></param>
 private void OnClickReturnButton(string obj)
 {
     CrossRoadStageManager.GetInstance().UnLoad();
     //ZooGameLoader.GetInstance().BackFromCrossRoad();
 }
        public void AddCrossRoad(int numRoad, Rect rc, Vector3 center, Vector3 startPos, Vector3 endPos, int cdVal, RoadDir roadDir, float carSpeedMin, float carSpeedMax)
        {
            //一条路的资源被分成几份
            //1条道的路分成2份
            //2条道的路分成4份
            //3条道的路分成6份
            Vector3 offset = Vector3.forward * rc.height / (numRoad * 2);

            for (int i = 0; i < numRoad; i++)
            {
                //方向随机
                float p         = Random.Range(0.1f, 1.0f);
                var   _roadDir  = roadDir;
                var   _startPos = startPos;
                var   _endPos   = endPos;
                if (p > 0.5f)
                {
                    _roadDir = RoadDir.RightToLeft;
                    Vector3 tmp = _startPos;
                    _startPos = _endPos;
                    _endPos   = tmp;
                }
                //路的最南面起点
                Vector3 startbottom = _startPos;
                startbottom += Vector3.back * rc.height * 0.5f;
                //GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = startbottom;

                Vector3 endbottom = _endPos;
                endbottom += Vector3.back * rc.height * 0.5f;
                //GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = endbottom;

                // i  第几条道     需要加的offset    公式=i * 2 + 1
                // 0   1           1 =               0 * 2 + 1
                // 1   2           3 =               1 * 2 + 1
                // 2   3           5 =               2 * 2 + 1
                int offsetMul = i * 2 + 1;
                var calcStart = startbottom + offset * offsetMul;

                float screenClampX = CrossRoadStageManager.GetInstance().carStartOffsetX;
                //if (roadDir == RoadDir.LeftToRight)
                //{
                //    screenClampX = GetXInLineByY(calcStart.z,
                //        Math_F.Vector3_2D(CrossRoadModelManager.GetInstance().spLBW),
                //        Math_F.Vector3_2D(CrossRoadModelManager.GetInstance().spLTW));

                //    calcStart.x = Mathf.Max(calcStart.x, screenClampX);
                //}
                //else
                //{
                //    screenClampX = GetXInLineByY(calcStart.z,
                //        Math_F.Vector3_2D(CrossRoadModelManager.GetInstance().spRBW),
                //        Math_F.Vector3_2D(CrossRoadModelManager.GetInstance().spRTW));

                //    calcStart.x = Mathf.Min(calcStart.x, screenClampX);
                //}
                if (_roadDir == RoadDir.LeftToRight)
                {
                    calcStart.x = center.x + (-1 * screenClampX);
                }
                else
                {
                    calcStart.x = center.x + (1 * screenClampX);
                }
#if UNITY_EDITOR
                var goStart = GameObject.CreatePrimitive(PrimitiveType.Cube);
                goStart.transform.position = calcStart;
                goStart.name = "CalcStart-" + calcStart.ToString() + " " + _roadDir;
#endif

                var calcEnd = endbottom + offset * offsetMul;
#if UNITY_EDITOR
                var goEnd = GameObject.CreatePrimitive(PrimitiveType.Cube);
                goEnd.transform.position = calcEnd;
                goEnd.name = "CalcEnd-" + calcEnd.ToString() + " " + _roadDir;
#endif
                var crossRoad = new CrossRoad();
                crossRoad.startPos      = calcStart;
                crossRoad.endPos        = calcEnd;
                crossRoad.spawnCarCDVal = cdVal;
                crossRoad.minCarSpeed   = carSpeedMin;
                crossRoad.maxCarSpeed   = carSpeedMax;
                crossRoad.roadDir       = _roadDir;
                crossRoadList.Add(crossRoad);
            }

            crossRoadRectArea.Add(rc);
        }
        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;
        }