Exemplo n.º 1
0
    private void InitializeGame()
    {
        var playerInfo = networkHandler.GetMyInfo();
        int playerID   = int.Parse(Network.player.ToString());

        GameObject PlayerDino    = (GameObject)Network.Instantiate((GameObject)Resources.Load(playerInfo.dinoName), spawnPoint[playerID].transform.position, Quaternion.LookRotation(spawnPoint[playerID].transform.forward), playerID);
        var        PlayerControl = PlayerDino.GetComponent <UserControl>();

        PlayerControl.InitAsPlayer();

        MainCameraFollow.target = PlayerDino.transform;

        if (Network.isServer)
        {
            //load environment objects (pickups, turrets, train)
            GameObject[] turretSpawnPoints = GameObject.FindGameObjectsWithTag("TurretSpawn");
            foreach (var unit in turretSpawnPoints)
            {
                Network.Instantiate((GameObject)Resources.Load("Turret02"), unit.transform.position, Quaternion.LookRotation(unit.transform.forward), playerID);
            }

            GameObject[] pickupSpawnPoints = GameObject.FindGameObjectsWithTag("PickUpSpawn");
            foreach (var unit in pickupSpawnPoints)
            {
                Network.Instantiate((GameObject)Resources.Load("PickUpItem"), unit.transform.position, Quaternion.LookRotation(unit.transform.forward), playerID);
            }

            int i = 0;
            i += networkHandler.playerInformation.Count;

            for (; i < NetworkGameHandler.MAX_PLAYERS; i++)
            {
                GameObject AiDino = (GameObject)Network.Instantiate((GameObject)Resources.Load(menuControl.dinos[Random.Range(0, 5)]), spawnPoint[i].transform.position, Quaternion.LookRotation(spawnPoint[i].transform.forward), playerID);
                PlayerControl = AiDino.GetComponent <UserControl> ();
                PlayerControl.InitAsAi();
            }
        }

        var myInfo = networkHandler.GetMyInfo();

        myInfo.readyState = "GameReady";
        networkHandler.UpdatePlayerInformation(myInfo);
        var hud = Camera.main.GetComponentInChildren <HUDScript> ();

        hud.enabled = true;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        raceDinos     = dinoTrackingScript.GetDinoArray();
        currentLaps   = dinoTrackingScript.GetCurrentLaps();
        racePositions = dinoTrackingScript.GetCurrentPositions();
        totalDist     = dinoTrackingScript.GetDistance();
        maxDistance   = dinoTrackingScript.maxDistance;

        xMulti = Screen.width / 100.0f;
        yMulti = Screen.height / 100.0f;

        /*lapObjs[0].guiTexture.pixelInset = ResizeRect(new Rect(80, 5, 5, 5));
        *  lapObjs[1].guiTexture.pixelInset = ResizeRect(new Rect(86, 6, 1, 3));
        *  lapObjs[2].guiTexture.pixelInset = ResizeRect(new Rect(88, 6, 1, 3));
        *  lapObjs[3].guiTexture.pixelInset = ResizeRect(new Rect(90, 6, 1, 3));*/

        /*lapObjs[0].guiText.pixelOffset = ResizeVec2(new Vector2(95, 5));
         * lapObjs[1].guiText.pixelOffset = ResizeVec2(new Vector2(90, 7));
         * lapObjs[2].guiText.pixelOffset = ResizeVec2(new Vector2(92, 7));
         * lapObjs[3].guiText.pixelOffset = ResizeVec2(new Vector2(93, 7));
         *
         * lapObjs[0].guiText.fontSize = (int)(4.0f * yMulti);
         * lapObjs[1].guiText.fontSize = (int)(6.0f * yMulti);
         * lapObjs[2].guiText.fontSize = (int)(6.0f * yMulti);
         * lapObjs[3].guiText.fontSize = (int)(6.0f * yMulti);
         *
         * lapObjs[1].guiText.text = currentLaps[dinoTrackingScript.playerNum].ToString();
         * lapObjs[3].guiText.text = dinoTrackingScript.maxLap.ToString();*/

        /*lapObjs[1].guiTexture.texture = numGfx[currentLaps[dinoTrackingScript.playerNum]];
         * lapObjs[3].guiTexture.texture = numGfx[dinoTrackingScript.maxLap];*/

        pauseMenuObjs[5].guiText.fontSize = (int)((xMulti + yMulti) * 1);
        pauseMenuObjs[6].guiText.fontSize = (int)((xMulti + yMulti) * 1);
        pauseMenuObjs[7].guiText.fontSize = (int)((xMulti + yMulti) * 1);
        pauseMenuObjs[8].guiText.fontSize = (int)((xMulti + yMulti) * 1);


        healthDangerObj.guiTexture.pixelInset = ResizeRect(new Rect(0, 0, 100, 100));

        pauseMenuPos[0]     = ResizeRect(new Rect(0, 0, 100, 100));
        pauseMenuPos[1]     = ResizeRect(new Rect(24.5f, 69, 21, 5));
        pauseMenuPos[2]     = ResizeRect(new Rect(24.5f, 56, 21, 5));
        pauseMenuPos[3]     = ResizeRect(new Rect(24.5f, 43.5f, 21, 5));
        pauseMenuPos[4]     = ResizeRect(new Rect(24.5f, 30, 21, 5));
        pauseMenuTextPos[0] = ResizeVec2(new Vector2(26, 73));
        pauseMenuTextPos[1] = ResizeVec2(new Vector2(26, 60));
        pauseMenuTextPos[2] = ResizeVec2(new Vector2(26, 47.5f));
        pauseMenuTextPos[3] = ResizeVec2(new Vector2(30.5f, 34));

        pauseMenuObjs[0].guiTexture.pixelInset = pauseMenuPos[0];
        pauseMenuObjs[1].guiTexture.pixelInset = pauseMenuPos[1];
        pauseMenuObjs[2].guiTexture.pixelInset = pauseMenuPos[2];
        pauseMenuObjs[3].guiTexture.pixelInset = pauseMenuPos[3];
        pauseMenuObjs[4].guiTexture.pixelInset = pauseMenuPos[4];
        pauseMenuObjs[5].guiText.pixelOffset   = pauseMenuTextPos[0];
        pauseMenuObjs[6].guiText.pixelOffset   = pauseMenuTextPos[1];
        pauseMenuObjs[7].guiText.pixelOffset   = pauseMenuTextPos[2];
        pauseMenuObjs[8].guiText.pixelOffset   = pauseMenuTextPos[3];


        if (Input.GetMouseButtonDown(0))
        {
            if (isPaused == true && pauseMenuPos[1].Contains(Input.mousePosition))
            {
                Time.timeScale = 1;

                TurnOnOffMenu();
            }
            else if (isPaused == true && pauseMenuPos[4].Contains(Input.mousePosition))
            {
                Time.timeScale = 1;

                var myInfo = networkHandler.GetMyInfo();
                myInfo.readyState = "LobbyReady";
                networkHandler.UpdatePlayerInformation(myInfo);

                menuScript.enabled = true;

                menuScript.fadeAction = menuScript.LeaveGame;

                menuScript.afterFadeAction = null;

                StartCoroutine(menuScript.TransitionFade());

                //Application.LoadLevel("Menu");
            }
        }

        /*healthPos  = ResizeRect(new Rect(20, 80, 100, 100));
         * healthGrp.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(healthPos.x, healthPos.y, 20));
         * healthGrp.transform.localRotation = Camera.main.transform.rotation;
         * healthCover.guiTexture.pixelInset = ResizeRect(new Rect(1, 75, 30, 15));
         *
         * dinoIcon.guiTexture.pixelInset = ResizeRect(new Rect(2.5f, 82.5f, 7, 13));*/

        items[0].guiTexture.pixelInset = ResizeRect(new Rect(55.8f, 82.8f, 6.65f, 12.2f));
        items[1].guiTexture.pixelInset = ResizeRect(new Rect(63, 82.8f, 6.65f, 12.3f));
        items[2].guiTexture.pixelInset = ResizeRect(new Rect(70.1f, 82.8f, 6.65f, 12.3f));
        items[3].guiTexture.pixelInset = ResizeRect(new Rect(77.3f, 82.8f, 6.65f, 12.3f));

        lapPos[0] = ResizeRect(new Rect(7, 21, 10, 10));
        lapPos[1] = ResizeRect(new Rect(7, 43, 10, 10));
        lapPos[2] = ResizeRect(new Rect(7, 67, 10, 10));
        lapPos[3] = ResizeRect(new Rect(7, 90, 10, 10));

        progressObjs[0].guiTexture.pixelInset = ResizeRect(new Rect(1, 20, 10, 70));

        /*progressObjs[1].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 2)), 0);
        *  progressObjs[2].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 2)), 1);
        *  progressObjs[3].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 2)), 2);
        *  progressObjs[3].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 2)), 3);*/

        healthPercent.guiText.pixelOffset = ResizeVec2(new Vector2(80, 75.5f));
        healthPercent.guiText.fontSize    = (int)((xMulti + yMulti) * 1);

        //healthGrpBar.guiTexture.pixelInset = ResizeRect(new Rect(67,75, 19.5f, 5));
        healthGrpBorder.guiTexture.pixelInset       = ResizeRect(new Rect(55, 60, 45, 40));
        healthGrpLeftTrigger.guiTexture.pixelInset  = ResizeRect(new Rect(57.5f, 86.8f, 3, 5));
        healthGrpRightTrigger.guiTexture.pixelInset = ResizeRect(new Rect(64.7f, 86.8f, 3, 5));

        if (!hasFinished)
        {
            finishObj.guiTexture.pixelInset      = ResizeRect(new Rect(150, 10, 90, 90));
            finishPlaceObj.guiTexture.pixelInset = ResizeRect(new Rect(-80, 30, 50, 60));
        }

        if (raceDinos[dinoTrackingScript.playerNum] != null)
        {
            SetPlayerHealth(ResizeRect(new Rect(67, 76, 19.5f, 4f)), dinoTrackingScript.playerNum);
        }

        if (raceDinos[0] != null)
        {
            if (dinoTrackingScript.playerNum != 0)
            {
                progressObjs[1].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 1)), 0);
                AttachHealth(0);
            }
            else
            {
                progressObjs[1].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 4, 3)), 0);
            }
            //mapPosObjs[0].guiTexture.pixelInset = SetMapPosition(mapInfo.StartPointPos, raceDinos[0]);
        }
        if (raceDinos[1] != null)
        {
            if (dinoTrackingScript.playerNum != 1)
            {
                progressObjs[2].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 1)), 1);
                AttachHealth(1);
            }
            else
            {
                progressObjs[2].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 4, 3)), 1);
            }
            //mapPosObjs[1].guiTexture.pixelInset = SetMapPosition(mapInfo.StartPointPos, raceDinos[1]);
        }
        if (raceDinos[2] != null)
        {
            if (dinoTrackingScript.playerNum != 2)
            {
                progressObjs[3].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 1)), 2);
                AttachHealth(2);
            }
            else
            {
                progressObjs[3].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 4, 3)), 2);
            }
            //mapPosObjs[2].guiTexture.pixelInset = SetMapPosition(mapInfo.StartPointPos, raceDinos[2]);
        }
        if (raceDinos[3] != null)
        {
            if (dinoTrackingScript.playerNum != 3)
            {
                progressObjs[4].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 3, 1)), 3);
                AttachHealth(3);
            }
            else
            {
                progressObjs[4].guiTexture.pixelInset = CalculateProgPos(ResizeRect(new Rect(6, 0, 4, 3)), 3);
            }
            //mapPosObjs[3].guiTexture.pixelInset = SetMapPosition(mapInfo.StartPointPos, raceDinos[3]);
        }

        //mapObj.guiTexture.pixelInset = ResizeRect(mapInfo.MapPos);

        /*Debug.Log(positionObjs.guiTexture.texture);
         * Debug.Log(dinoTrackingScript.playerNum);
         * Debug.Log(racePositions[dinoTrackingScript.playerNum] - 1);
         * Debug.Log(hudGfx[racePositions[dinoTrackingScript.playerNum] - 1]);*/
        //if((racePositions[dinoTrackingScript.playerNum] - 1) != null)
        if (hudGfx[racePositions[dinoTrackingScript.playerNum] - 1] != null)
        {
            positionObj.guiText.pixelOffset = ResizeVec2(new Vector2(92, 89));
            positionObj.guiText.fontSize    = (int)((xMulti + yMulti) * 4);
            positionObj.guiText.text        = racePositions[dinoTrackingScript.playerNum].ToString();

            positionPlaceObj.guiText.pixelOffset = ResizeVec2(new Vector2(92, 88));
            positionPlaceObj.guiText.fontSize    = (int)((xMulti + yMulti) * 1.5f);

            switch (racePositions[dinoTrackingScript.playerNum])
            {
            case 1:
                positionPlaceObj.guiText.text = "st";
                break;

            case 2:
                positionPlaceObj.guiText.text = "nd";
                break;

            case 3:
                positionPlaceObj.guiText.text = "rd";
                break;

            case 4:
                positionPlaceObj.guiText.text = "th";
                break;
            }
        }


        if (Input.GetKeyDown(KeyCode.Escape) && menuScript.singlePlayer == true)
        {
            if (isPaused == false)
            {
                Debug.Log("pause activated");
                Time.timeScale = 0;
            }
            else
            {
                Time.timeScale = 1;
            }

            TurnOnOffMenu();
        }
    }