コード例 #1
0
        /// <summary>
        /// 加载路,并存储路的rect区域
        /// </summary>
        protected void LoadRoad()
        {
            roadModel.Release();
            var animalRoad = LoadAnimalRoad();

            roadModel.spaceRoad = FSMCrossRoadGame.GetSize_Z(animalRoad);

            var cellStage = Config.crossroadstageConfig.getInstace().getCell(stageID);

            for (int i = 0; i < cellStage.roadnum; i++)
            {
                int numRoad = cellStage.roadweightmin;
                if (cellStage.roadweightmin != cellStage.roadweightmax)
                {
                    numRoad = Random.Range(cellStage.roadweightmin, cellStage.roadweightmax + 1);
                }

                int roadResID = Config.crossroadroadConfig.getInstace().getCell(numRoad).resid;

                var road = ResourceManager.GetInstance().LoadGameObject(Config.resourceConfig.getInstace().getCell(roadResID).prefabpath);

                int carInterval = (int)(Random.Range(cellStage.Intervalmin, cellStage.Intervalmax) * 1000);

                lastRoadPos = startPoint + (roadModel.spaceRoad * i * Vector3.forward);
                Vector3 bcSize = road.GetComponent <BoxCollider>().size;

                float halfWidth = bcSize.z * 0.5f;
                if (i > 0)
                {
                    lastRoadPos += (preHalfWidth + halfWidth + preOffset) * Vector3.forward;
                    preOffset   += (preHalfWidth + halfWidth);
                }

                preHalfWidth = halfWidth;
                var roadRect = new Rect(
                    lastRoadPos.x, lastRoadPos.z,
                    bcSize.x, bcSize.z);
                roadModel.AddCrossRoad(
                    numRoad, roadRect, lastRoadPos, lastRoadPos + (Vector3.left * bcSize.x * 0.5f),
                    lastRoadPos + (Vector3.right * bcSize.x * 0.5f),
                    carInterval, RoadDir.LeftToRight, cellStage.speedmin, cellStage.speedmax);

                road.transform.position = lastRoadPos;

                roadModel.AddToAnimalRoadSegment(lastRoadPos, roadRect);
#if UNITY_EDITOR
                road.name = string.Format("CarRoad-{0}-{1}", i, halfWidth);
#endif

                animalRoad.transform.position = lastRoadPos - Vector3.forward * 0.5f * (roadModel.spaceRoad + bcSize.z);
#if UNITY_EDITOR
                animalRoad.name = string.Format("AnimalRoad-{0}", i);
#endif
                if (i < cellStage.roadnum - 1)
                {
                    animalRoad = LoadAnimalRoad();
                }
            }
        }
コード例 #2
0
        public void Init()
        {
            //初始化加载状态机
            fsmLoad = new FSMCrossRoadGame();
            fsmLoad.AddState(new StateLoadOrgScene((int)CrossRoadGameState.LoadOrgScene, fsmLoad));
            fsmLoad.AddState(new StateLoadSceneObject((int)CrossRoadGameState.LoadSceneObject, fsmLoad));
            fsmLoad.AddState(new StateLoadAnimal((int)CrossRoadGameState.LoadAnimal, fsmLoad));
            fsmLoad.Run();

            //module容器
            gameModules = new GameModules();
            //注册消息
            MessageManager.GetInstance().Regist((int)GameMessageDefine.LoadCrossRoadLevelFinished, OnLoadCrossRoadLevelFinished);
            MessageManager.GetInstance().Regist((int)GameMessageDefine.CrossRoadGameFailure, OnGetCrossRoadGameFailure);
        }
コード例 #3
0
        protected void OnLoadAnimal(Message msg)
        {
            animalTeamModel.numArrivedEndPoint = 0;

            List <int> animalResourceloadList = GetAnimaelList(cellStage.animalnum);

            for (int i = 0; i < animalResourceloadList.Count; i++)
            {
                var animal = EntityManager.GetInstance().GenEntityGameObject(
                    animalResourceloadList[i], EntityFuncType.Animal_LittleGame) as EntityCrossRoadAnimal;
                animal.Init(animalAnimationSpeed, animalMoveSpeed, i,
                            animalAcceleration, rotateSpeed);
                animal.position = animalRoadSegment[animalTeamModel.currentRoad]
                                  + Vector3.back * (standardAnimalBoxSize.z * i + standardAnimalBoxSize.z * 0.8f);
                GameObject colliderGB = animal.GetTrans().Find("Collider").gameObject;
                colliderGB.SetActive(true);
                FSMCrossRoadGame.Scale_Z(animal.mainGameObject, standardAnimalBoxSize.z);
                animal.position = new Vector3(animal.position.x, 0, animal.position.z);
                if (animal.simpleAnimation != null)
                {
                    animal.simpleAnimation.Init(animal.mainGameObject);
                }

                if (colliderGB.GetComponent <Rigidbody>() == null)
                {
                    colliderGB.AddComponent <Rigidbody>();
                    SetRigidbody(colliderGB);
                }

                if (colliderGB.GetComponent <AnimalCollisionEnterHelp>() == null)
                {
                    colliderGB.AddComponent <AnimalCollisionEnterHelp>();
                }

                if (animal.runEffSp == null)
                {
                    animal.runEffSp = new SimpleParticle();
                    animal.runEffSp.Init(animal.mainGameObject.transform.Find("Effect/MoveEffect").gameObject);
                }

                animal.Active();
                animalTeamModel.entityCrossRoadAnimalList.Add(animal);
                CrossRoadModelManager.GetInstance().entityModel.AddToEntityMovables(animal);
            }
        }
コード例 #4
0
        protected void OnLoadAnimal(Message msg)
        {
            for (int i = 0; i < 15; i++)
            {
                var animal = EntityManager.GetInstance().GenEntityGameObject(
                    2201, EntityFuncType.Animal_LittleGame) as EntityCrossRoadAnimal;
                animal.Init(animalAnimationSpeed, animalMoveSpeed, i);
                animal.position = animalRoadSegment[animalTeamModel.currentRoad]
                                  + Vector3.back * (standardAnimalBoxSize.z * i + standardAnimalBoxSize.z * 0.8f);
                //animal.position = animalRoadSegment[animalTeamModel.currentRoad]
                //    + Vector3.back * (standardAnimalBoxSize.z * i);
                GameObject colliderGB = animal.GetTrans().Find("Collider").gameObject;
                colliderGB.SetActive(true);
                FSMCrossRoadGame.Scale_Z(animal.mainGameObject, standardAnimalBoxSize.z);
                //animal.position = new Vector3(animal.position.x, colliderGB.transform.position.y * -1, animal.position.z);
                animal.position = new Vector3(animal.position.x, 0, animal.position.z);
                if (animal.simpleAnimation != null)
                {
                    animal.simpleAnimation.Init(animal.mainGameObject);
                }

                if (colliderGB.GetComponent <Rigidbody>() == null)
                {
                    colliderGB.AddComponent <Rigidbody>();
                    SetRigidbody(colliderGB);
                }

                if (colliderGB.GetComponent <AnimalCollisionEnterHelp>() == null)
                {
                    colliderGB.AddComponent <AnimalCollisionEnterHelp>();
                }

                animal.Active();
                animalTeamModel.entityCrossRoadAnimalList.Add(animal);
                CrossRoadModelManager.GetInstance().entityModel.AddToEntityMovables(animal);
            }
        }