Exemplo n.º 1
0
    void Awake()
    {
        //Check if instance already exists
        if (instance == null)
        {
            //if not, set instance to this
            instance = this;
        }

        //If instance already exists and it's not this:
        else if (instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }


        GameObject[] allObjectTaggedWall = GameObject.FindGameObjectsWithTag("Wall");
        foreach (GameObject obj in allObjectTaggedWall)
        {
            obj.layer = 16;
        }

        b_GlobalSkidMark = true;
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        if (champManager == null)
        {
            champManager = GameObject.Find("championshipManager").GetComponent <championshipM>();
        }


        if (championshipM.instance.currentSelectedChampionship <= 2)
        {
            currentstartValue = 0;
            InitChampionshipWhenScenStart(championshipM.instance.currentSelectedChampionship);
            eventSystem.SetSelectedGameObject(slot_01[championshipM.instance.currentSelectedChampionship]);
            objSelector[championshipM.instance.currentSelectedChampionship].SetActive(true);
            if (lastChampionship.activeSelf)
            {
                lastChampionship.SetActive(false);
            }
        }
        else if (championshipM.instance.currentSelectedChampionship > 2)
        {
            currentstartValue = championshipM.instance.currentSelectedChampionship - 2;
            InitChampionshipWhenScenStart(championshipM.instance.currentSelectedChampionship);
            eventSystem.SetSelectedGameObject(slot_01[2]);
            objSelector[2].SetActive(true);
        }

        if (nextChampionship.activeSelf && championshipM.instance.champInventory.listOfChampionship.Count < 3)
        {
            nextChampionship.SetActive(false);
        }

        //Debug.Log("Champ: " + championshipM.instance.currentSelectedChampionship + " : modulo : " + championshipM.instance.currentSelectedChampionship % 3);
    }
Exemplo n.º 3
0
    public void SelectANewChampionship(int slotValue)
    {
        currentSelectedChampionship = currentstartValue + slotValue;
        if (champManager == null)
        {
            champManager = GameObject.Find("championshipManager").GetComponent <championshipM>();
        }

        Debug.Log(currentSelectedChampionship);

        if (champManager.listChampionshipState[currentSelectedChampionship] == true)
        {
            champManager.currentSelectedChampionship = currentSelectedChampionship;
            MCR_RememberChampionship(slotValue);
            Grp_YesNo_Start.SetActive(true);
            eventSystem.SetSelectedGameObject(btn_Validate);
            audioClick.Play();
            Debug.Log("Championship can be played");
        }
        else
        {
            Debug.Log("Championship can't be played");
            audioWrong.Play();
        }
    }
Exemplo n.º 4
0
    //--> Championship Part
    public void MCR_NextTrackOrRestartChampionship()
    {
        if (objStamp_01.MCR_CheckIfAnimationEnded())
        {
            b_btn_NextTrack = true; // Championship Mode: Player press the button next track

            //-> Find the position of all the cars even if they have finnish the race
            for (var i = 0; i < lapCounter.raceFinished.Count; i++)    // Force  raceFinished to true for all the cars
            {
                lapCounter.raceFinished[i] = true;
            }

            int numberOfCarThatHaveFinishTheRace = listScore.Count;

            for (var i = numberOfCarThatHaveFinishTheRace; i < lapCounter.carController.Count; i++)
            {
                for (var j = 0; j < lapCounter.carController.Count; j++)
                {
                    if (lapCounter.carPosition[j] == i + 1)
                    {
                        //Debug.Log("Pos: " + (i + 1).ToString() + " : " + lapCounter.carController[j].name);
                        MCR_InstantiateScorePrefab(j);
                    }
                }
            }


            championshipM championshipManager = GameObject.Find("championshipManager").GetComponent <championshipM>();
            championshipManager.MCR_CalculateResult(listCarPosition, listPoints);
        }
    }
Exemplo n.º 5
0
    public void MCR_checkIfNewChampionshipNeedToBeUnlocked(List <int> carName, List <int> carPoints)
    {
        championshipM championshipManager = GameObject.Find("championshipManager").GetComponent <championshipM>();

        //-> championship is finished

        /* Debug.Log("currentTrackInTheList :  " + championshipManager.currentTrackInTheList +
         *         "Number of tracks :  " + (championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].scenesName.Count - 1).ToString() +
         *         "currentSelectedChampionship :  " + championshipManager.currentSelectedChampionship +
         *         "Number champ :  " + (championshipManager.champInventory.listOfChampionship.Count - 1).ToString());*/
        if (championshipManager.currentTrackInTheList == championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].scenesName.Count &&
            championshipManager.currentSelectedChampionship < championshipManager.champInventory.listOfChampionship.Count - 1)
        {
            if (!championshipManager.listChampionshipState[championshipManager.currentSelectedChampionship + 1]) // This championship was never won
            {
                if (PlayerPrefs.GetInt("HowManyPlayers") == 1)                                                   // --> Player 1
                {
                    if (carName[0] == 0)
                    {
                        Debug.Log("New Championship Available");
                        if (grp_Medal)
                        {
                            grp_Medal.SetActive(true);
                        }
                        championshipManager.listChampionshipState[championshipManager.currentSelectedChampionship + 1] = true;
                        championshipManager.MCR_Save_ChampionshipData();
                        championshipManager.MCR_UnlockTrackInArcadeAndTimeTrialMode(championshipManager.currentSelectedChampionship + 1);
                    }
                    else
                    {
                        Debug.Log("New Championship not Available");
                    }
                }
                else if (PlayerPrefs.GetInt("HowManyPlayers") == 2)// --> Player 2
                {
                    if (carName[0] == 0 || carName[0] == 1)
                    {
                        Debug.Log("New Championship Available");
                        if (grp_Medal)
                        {
                            grp_Medal.SetActive(true);
                        }
                        championshipManager.listChampionshipState[championshipManager.currentSelectedChampionship + 1] = true;
                        championshipManager.MCR_Save_ChampionshipData();
                        championshipManager.MCR_UnlockTrackInArcadeAndTimeTrialMode(championshipManager.currentSelectedChampionship + 1);
                    }
                    else
                    {
                        Debug.Log("New Championship not Available");
                    }
                }
            }
        }
        else
        {
            Debug.Log("No more Championship not Available");
        }
    }
Exemplo n.º 6
0
    public void MCR_LoadFirstChampionshipTrack()
    {
        if (champManager == null)
        {
            champManager = GameObject.Find("championshipManager").GetComponent <championshipM>();
        }


        champManager.MCR_LoadASceneWhenPlayIsPressed_MainMenu();
    }
Exemplo n.º 7
0
    public void MCR_UpdateNextTrackSprite()
    {
        championshipM championshipManager = GameObject.Find("championshipManager").GetComponent <championshipM>();

        if (championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].scenesSprite[championshipManager.currentTrackInTheList])
        {
            trackSprite.sprite       = championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].scenesSprite[championshipManager.currentTrackInTheList];
            trackName.text           = championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].TracksName[championshipManager.currentTrackInTheList];
            trackPositionInList.text = "Track " +
                                       (championshipManager.currentTrackInTheList + 1).ToString() +
                                       "/" +
                                       championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].TracksName.Count;
        }
    }
Exemplo n.º 8
0
    public void MCR_RestartChampionship()
    {
        championshipM championshipManager = GameObject.Find("championshipManager").GetComponent <championshipM>();

        championshipManager.MCR_Init_Championship();
    }
Exemplo n.º 9
0
    //--> Display championship in the UI Menu
    private void InitChampionship(int startValue)
    {
        if (currentstartValue + 3 < _championshipInventory.listOfChampionship.Count)
        {
            nextChampionship.SetActive(true);
        }
        else
        {
            nextChampionship.SetActive(false);
            eventSystem.SetSelectedGameObject(newSelectedGameObject_02);
        }

        if (currentstartValue == 0)
        {
            lastChampionship.SetActive(false);
            eventSystem.SetSelectedGameObject(newSelectedGameObject_01);
        }
        else
        {
            lastChampionship.SetActive(true);
        }

        champManager = GameObject.Find("championshipManager").GetComponent <championshipM>();

        //Debug.Log("Start value: " + startValue);

        for (var i = startValue; i < 3 + startValue; i++)
        {
            if (i < _championshipInventory.listOfChampionship.Count)
            {
                if (!slot_01[i - startValue].gameObject.activeSelf)
                {
                    slot_01[i - startValue].gameObject.SetActive(true);
                }

                slot_01[i - startValue].GetComponent <RectTransform>().localScale =
                    new Vector3(_championshipInventory.listOfChampionship[i].championshipIconSize.x,
                                _championshipInventory.listOfChampionship[i].championshipIconSize.y,
                                1);

                slot_01[i - startValue].GetComponent <Image>().sprite = _championshipInventory.listOfChampionship[i].championshipIconOff;

                slot_01[i - startValue].GetComponent <Image>().sprite = _championshipInventory.listOfChampionship[i].championshipIconOn;

                _Text[i - startValue].text = _championshipInventory.listOfChampionship[i].championshipName;

                string sTrack = moreThanOneTrack;
                if (_championshipInventory.listOfChampionship[i].TracksName.Count <= 1)
                {
                    sTrack = onlyOneTrack;
                }

                listTextTrackNumberInTheChamp[i - startValue].text = (_championshipInventory.listOfChampionship[i].TracksName.Count).ToString() + " " + sTrack;


                if (champManager.listChampionshipState[i])
                {
                    listPadlock[i - startValue].SetActive(false);
                }
                else
                {
                    listPadlock[i - startValue].SetActive(true);
                }
            }
            else
            {
                _Text[i - startValue].text = "";
                slot_01[i - startValue].gameObject.SetActive(false);
                listTextTrackNumberInTheChamp[i - startValue].text = "";
                listPadlock[i - startValue].SetActive(false);
            }
        }
    }
Exemplo n.º 10
0
    public void MCR_NextTrackOrRestartChampionship_Part2(List <int> carName, List <int> carPoints)
    {
        objNextPage.SetActive(false);

        b_btn_NextTrack = true;
        EventSystem eventSystem = GameObject.Find("EventSystem").GetComponent <EventSystem>();



        championshipM championshipManager = GameObject.Find("championshipManager").GetComponent <championshipM>();

        // Championship continue
        if (championshipManager.currentTrackInTheList < championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].scenesName.Count - 1)
        {
            objNextTrack.SetActive(true);
            championshipManager.currentTrackInTheList++;
            txt_ScreenTitle.text = s_NewTitleGlobalresult;
            if (objStamp_02)
            {
                objStamp_02.gameObject.SetActive(true);
                objStamp_02.AP_LogoAnimation();
            }
            updateSpriteScale.MCR_UpdateNextTrackSprite();
            //Debug.Log("Next Page");
            eventSystem.SetSelectedGameObject(btn_NextTrack.gameObject);
            changeBtnNavigation.MCR_NewButtonNavigation(btn_MainMenu, btn_NextTrack, "Right");
        }
        // End of the championship
        else
        {
            objRestartChampionship.SetActive(true);
            championshipManager.currentTrackInTheList++;
            txt_ScreenTitle.text = s_NewTitleFinalResult;
            if (objStamp_03)
            {
                objStamp_03.gameObject.SetActive(true);
                objStamp_03.AP_LogoAnimation();
            }
            updateSpriteScale.MCR_UpdateTrackSprite();
            eventSystem.SetSelectedGameObject(btn_MainMenu.gameObject);
            //Debug.Log("Next Track");
            changeBtnNavigation.MCR_NewButtonNavigation(btn_MainMenu, btn_RestartChampionship, "Right");
        }


        objTxt_Time.SetActive(false);


        //Update Score List
        for (var i = 0; i < listScore.Count; i++)
        {
            listScore[i].GetChild(0).gameObject.GetComponent <Text>().text = (i + 1).ToString();

            if (carName[i] == 0 &&
                PlayerPrefs.GetInt("HowManyPlayers") == 1)
            {                                           // --> Player 1
                listScore[i].GetChild(1).gameObject.GetComponent <Text>().text = stringForPlayerText + 1;
            }
            else if (
                (carName[i] == 0 || carName[i] == 1) &&
                PlayerPrefs.GetInt("HowManyPlayers") == 2)
            {                                           // --> Player 2
                if (carName[i] == 0)
                {
                    listScore[i].GetChild(1).gameObject.GetComponent <Text>().text = stringForPlayerText + 1;
                }
                if (carName[i] == 1)
                {
                    listScore[i].GetChild(1).gameObject.GetComponent <Text>().text = stringForPlayerText + 2;
                }
            }
            else
            {
                if (useCarName)
                {
                    listScore[i].GetChild(1).gameObject.GetComponent <Text>().text = lapCounter.carController[carName[i]].name;                                    // display name
                }
                else
                {
                    listScore[i].GetChild(1).gameObject.GetComponent <Text>().text = stringForCPUText + " " + (carName[i] + 1).ToString();
                }
            }

            listScore[i].GetChild(2).gameObject.SetActive(false);
            listScore[i].GetChild(3).gameObject.GetComponent <Text>().text = carPoints[i].ToString();
        }

        MCR_checkIfNewChampionshipNeedToBeUnlocked(carName, carPoints);
    }
Exemplo n.º 11
0
    IEnumerator I_InitGame()
    {
        #region
        Debug.Log(
            "Game Mode : " + PlayerPrefs.GetString("Which_GameMode") +
            "\nHowManyPlayers : " + PlayerPrefs.GetInt("HowManyPlayers") +
            "\nDifficulty : " + PlayerPrefs.GetInt("DifficultyChoise") +
            "\nCar 01 : " + PlayerPrefs.GetInt("Player_0_CarLastSelection") +
            "\nCar 02 : " + PlayerPrefs.GetInt("Player_1_CarLastSelection") +
            "\nCar 03 : " + PlayerPrefs.GetInt("Player_2_CarLastSelection") +
            "\nCar 03 : " + PlayerPrefs.GetInt("Player_3_CarLastSelection"));

// --> Find car on scene
        GameObject[] arrCars = GameObject.FindGameObjectsWithTag("Car");

        foreach (GameObject carFind in arrCars)                                                                                                                                         // if there are cars on scene delete them before creating the needed car for this race
        {
            if (carFind.GetComponent <CarController> ())
            {
                carFind.gameObject.SetActive(false);
                Destroy(carFind);
            }
        }

        if (PlayerPrefs.GetString("Which_GameMode") == "Championship")   // Championship: Select AI difficulty for current track
        {
            championshipM championshipManager = GameObject.Find("championshipManager").GetComponent <championshipM>();
            int           newDifficulty       = championshipManager.champInventory.listOfChampionship[championshipManager.currentSelectedChampionship].AI_Difficulty[championshipManager.currentTrackInTheList];
            PlayerPrefs.SetInt("DifficultyChoise", newDifficulty);
        }

        if (PlayerPrefs.GetString("Which_GameMode") == "Arcade" || PlayerPrefs.GetString("Which_GameMode") == "Championship")           // Arcade or Championship mode is selected
        {
            for (var i = 0; i < howManyCarsInRace; i++)
            {
                GameObject instance = null;
                if (i < inventoryItemCar.inventoryItem.Count)
                {
                    instance = Instantiate(inventoryItemCar.inventoryItem [i].Cars [PlayerPrefs.GetInt("Player_" + i + "_CarLastSelection")]);
                }
                //instance = Instantiate(inventoryItemCar.inventoryItem[i].Cars[0]);
                else
                {
                    instance = Instantiate(inventoryItemCar.inventoryItem[0].Cars[0]);
                }

                instance.name = instance.name.Replace("(Clone)", "");

                GameObject tmpPosition = GameObject.Find("Start_Position_0" + (i + 1));

                if (tmpPosition)
                {
                    // if (i < 4)
                    instance.GetComponent <CarController> ().playerNumber = i + 1;                                                                                      // Select the player number
                    // else
                    //    instance.GetComponent<CarController>().playerNumber = 3;                                // Select the player number

                    if (i == 0)
                    {
                        instance.GetComponent <CarAI> ().enabled = false;                                                                                               // Car 1 control by Player 1
                    }
                    if (i == 1 && PlayerPrefs.GetInt("HowManyPlayers") == 2)
                    {
                        instance.GetComponent <CarAI> ().enabled = false;                                                                                                       // Car 2 control by Player 2
                        if (Player2Position)
                        {
                            Player2Position.SetActive(true);
                        }
                        if (Player2PositionPart2)
                        {
                            Player2PositionPart2.SetActive(true);
                        }
                        if (Player2LapCounter)
                        {
                            Player2LapCounter.SetActive(true);
                        }
                    }

                    if (i == 1 && PlayerPrefs.GetInt("HowManyPlayers") == 1)
                    {
                        instance.GetComponent <CarAI> ().enabled = true;                                                                                                        // Car 2 control by CPU
                        if (Player2Position)
                        {
                            Player2Position.SetActive(false);
                        }
                        if (Player2PositionPart2)
                        {
                            Player2PositionPart2.SetActive(false);
                        }
                        if (Player2LapCounter)
                        {
                            Player2LapCounter.SetActive(false);
                        }
                    }

                    if (i > 1)
                    {
                        instance.GetComponent <CarAI> ().enabled = true;                                                                                                // Car 3 and 4 control by CPU
                    }
                    if (tmpPosition)
                    {
                        instance.transform.position = new Vector3(tmpPosition.transform.position.x,
                                                                  tmpPosition.transform.position.y + .15f, tmpPosition.transform.position.z);
                        instance.transform.eulerAngles = tmpPosition.transform.eulerAngles;
                    }
                    while (!instance)
                    {
                    }
                }
            }
        }
        else if (PlayerPrefs.GetString("Which_GameMode") == "TimeTrial")                                                                                        // Time Trial is selected

        {
            GameObject instance = Instantiate(inventoryItemCar.inventoryItem [0].Cars [PlayerPrefs.GetInt("Player_0_CarLastSelection")]);
            instance.name = instance.name.Replace("(Clone)", "");
            GameObject tmpPosition = GameObject.Find("Start_Position_04");
            instance.GetComponent <CarController> ().playerNumber = 1;                                                                                                  // Select the player number
            instance.GetComponent <CarAI> ().enabled = false;                                                                                                           // Car 1 control by Player 1
            if (tmpPosition)
            {
                instance.transform.position = new Vector3(tmpPosition.transform.position.x,
                                                          tmpPosition.transform.position.y + .15f, tmpPosition.transform.position.z);
                instance.transform.eulerAngles = tmpPosition.transform.eulerAngles;
            }
            while (!instance)
            {
            }

            if (Player1Position)
            {
                Player1Position.SetActive(false);
            }
            if (Player1PositionPart2)
            {
                Player1PositionPart2.SetActive(false);
            }
            if (Player2Position)
            {
                Player2Position.SetActive(false);
            }
            if (Player2PositionPart2)
            {
                Player2PositionPart2.SetActive(false);
            }

            if (Player2LapCounter)
            {
                Player2LapCounter.SetActive(false);
            }
        }

        CreateCarList();                                                                                                                                                                                        // Create car list
        //if(lapcounter)lapcounter.InitCar ();																					// Init Lap counter

        if (countdown && b_UseCountdown)
        {
            countdown.b_ActivateCountdown = true;
        }                                                                                                                                               // Start countdown if needed

        if (list_Cars [1] != null && cam_P2 && list_Cars [1].gameObject.GetComponent <CarAI> ().enabled == false)
        {
            //cam_P2.gameObject.SetActive (true);
            //cam_P2.InitCamera(list_Cars [1],false);
            InitSplitScreenPart1();
        }

        if (list_Cars [0] != null && cam_P1)
        {
            if (list_Cars [1] != null && list_Cars [1].gameObject.GetComponent <CarAI> ().enabled == false)
            {
                InitSplitScreenPart2();
            }
            else
            {
                cam_P1.InitCamera(list_Cars [0], false);                                                                                                                                // Single Camera
                if (obj_LineSplitScreen_Part_01)
                {
                    obj_LineSplitScreen_Part_01.SetActive(false);
                }
                if (obj_LineSplitScreen_Part_02)
                {
                    obj_LineSplitScreen_Part_02.SetActive(false);
                }
            }
        }

        if (canvas_MainMenu &&
            inventoryItemList.inventoryItem[0].b_TestMode == false
            /*&& PlayerPrefs.GetInt ("TestMode") == 0 */
            && !b_TuningZone)
        {
            canvas_MainMenu.GoToOtherPageWithHisNumber(5);                                                                                                                      // Display Pause_Page
        }
        b_initDone = true;
        return(null);

        #endregion
    }