Exemplo n.º 1
0
 public void Save()
 {
     SaveLoadModel.Save();
     UserDataManager.Instance.Data.Coins -= _totalCost;
     UserDataManager.Instance.SaveToFile();
     foreach (iRoadSectn s in Road.Instance.Sectns.Where(s => s.Chargeable == true))
     {
         s.Chargeable = false;
     }
     foreach (PlaceableObject Ch in BillOfSceneryMaterials.Items)
     {
         Ch.Chargeable = false;
     }
     Main.Instance.ShowCoins();
     if (MenuItemToSave != null)
     {
         MenuItemToSave.EnableSaveButton(false);
     }
     Destroy(this.gameObject);
 }
Exemplo n.º 2
0
 public void BuildTrack()
 {
     if (SelectedItem == null)
     {
         return;
     }
     if (SelectedItem.Id == -1)
     {
         Main.Instance.StartLoadingMenuScene("SceneSelector");
     }
     else
     {           //N.B. the SaveLoadModel decides whether to load the game or keep the current one
         if (Game.current != null)
         {
             if (SelectedItem.Id != Game.current.GameId)
             {
                 //TerrainController.Instance.RestoreBackup();
             }
         }
         PlayerManager.Type = "BuilderPlayer";
         SaveLoadModel.LoadGameData(SelectedItem.Id);
         Main.Instance.StartLoadingGameScene(GameData.current.Scene); // Once the scene is loaded it activates and moves the EventSystem across
     }
 }
Exemplo n.º 3
0
    void SceneChange(Scene OldScene, Scene NewScene)
    {
        if (OldScene.name == null)
        {
            return;
        }
        Debug.Log("Main SceneChange from " + OldScene.name + " to " + NewScene.name);
        if (NewScene.name == "SceneSelector")
        {
            return;
        }
        if (NewScene.name == "RaceSelector")
        {
            _musicPlayer.Fade();
        }

        int Level = NewScene.buildIndex;

        if (Level < 6)
        {
            return;
        }
        if (OnLevelLoaded != null)
        {
            OnLevelLoaded(Level);
        }

        if (PlayerManager.Type == "CarPlayer")
        {
            if (GameLoadedFromFileNeedsDecoding)
            {
                SaveLoadModel.DecodeGameScene();
                GameLoadedFromFileNeedsDecoding = false;
            }
            PopupTip();
            StartCoroutine(CreateTrackAndRacers());
        }

        if (PlayerManager.Type == "Replayer")
        {
            if (GameLoadedFromFileNeedsDecoding)
            {
                SaveLoadModel.DecodeGameScene(); GameLoadedFromFileNeedsDecoding = false;
            }
            PopupTip();
            StartCoroutine(CreateTrackAndRacers());
        }

        if (PlayerManager.Type == "BuilderPlayer")
        {
            if (SelectedGameID == -1)
            {
                Game.current           = new Game();
                GameData.current       = new GameData();
                GameData.current.Scene = NewScene.name;
                SaveLoadModel.Save();
                SaveLoadModel.LoadTerrainBackup(NewScene.name);
                TerrainController.Instance.Init();
                //Clear all the bez points and add the 2 empty ones.
                //We need these, because cos although the Constructor calls Init(), its a singleton class so the constructor only gets called at the beginning
                BezierLine.Instance.Init();

                //Clear all the road sections and add the empty Road Section
                //We need these, because cos although the Constructor calls Init(), its a singleton class so the constructor only gets called at the beginning
                Road.Instance.Init();

                //Clear all the PlaceableObjects
                Scenery.Instance.RemoveObjects();
            }
            else
            {
                SaveLoadModel.LoadGameData(SelectedGameID);
                if (GameLoadedFromFileNeedsDecoding)
                {
                    SaveLoadModel.DecodeGameScene();
                    GameLoadedFromFileNeedsDecoding = false;
                }
            }
            PopupTip();
            StartCoroutine(BPMPlayOfflineCoroutine());
        }
    }
Exemplo n.º 4
0
    private void OnSegmentEnter()
    {
        if (Progrss < 20 && PrevProgrss > RoadSegCount - 20)
        {
            Lap++;
            if (!isMachine)
            {
                float LapTime = Time.time - LapStartTime;
                _Race.LapStats.Add(new LapStat {
                    stFr = LapStartFrame, finFr = Recrdng.Current.FrameCount - 1, time = LapTime
                });
                if (Game.current.BestLap == null || LapTime < Game.current.BestLap)
                {
                    int LapScore = RoadSegCount / 50;
                    Race.Current.LapRecBonus += LapScore;
                    StringBuilder s = new StringBuilder("New Lap Record\n$");
                    s.Append(LapScore.ToString());
                    Main.Instance.PopupMsg(s.ToString(), Color.green);
                    Game.current.BestLap = LapTime;
                    SaveLoadModel.SaveSavedGames();
                }
                if (Main.Instance.Ghost)
                {
                    GhostController gc = (GhostController)DrivingPlayManager.Current.GhostCarManager.VehicleController;
                    gc.Frame = 0;
                }
                LapStartTime  = Time.time;
                LapStartFrame = Recrdng.Current.FrameCount;
            }
        }
        TotProgrss = Progrss + (Lap - 1) * RoadSegCount;

        //keeping the AI cars close to the player
        if (isMachine)
        {
            foreach (Racer pr in PlayerOpposition)
            {
                if (_hogBonusTime == 0 && pr.TotProgrss > TotProgrss + 20 || pr.TotProgrss < TotProgrss - 301)
                //Player is too far ahead or really far behind
                {
                    JumpTo(pr);
                }
                if (pr.TotProgrss < TotProgrss - 10)
                //AICar is a bit ahead of the player slow down
                {
                    _vehicleController.motorForce = _defaultMotorForce * 0.4f;
                }
                else
                {
                    _vehicleController.motorForce = _defaultMotorForce;
                }
            }
        }
        else
        {
            if (txtLap == null)
            {
                txtLap = GameObject.Find("txtLap").GetComponent <Text>();
            }
            float LapTime = Time.time - LapStartTime;
            if (LapTime > 10)
            {
                txtLap.text = GenFunc.HMS(LapTime);
            }
            if (Lap == Race.Current.Laps + 1)
            {
                Race.Current.Finish();
            }
            if (TotProgrss > RoadSegCount * Race.Current.Laps - 100 && ChFlag == false)
            {
                Transform trStart = GameObject.Find("StartingLine").transform;
                foreach (ParticleSystem ps in trStart.GetComponentsInChildren <ParticleSystem>())
                {
                    ps.Play();
                }
                Race.Current.ShowChequeredFlag(true);
                CamSelector.Instance.SelectCam("Simple");
                ChFlag = true;
            }
        }
    }
Exemplo n.º 5
0
 public void Delete()
 {
     SaveLoadModel.Delete(Id);
     OuterGameObject.SetActive(false);
     Deleted = true;
 }