Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        playerBody.GetComponent <Rigidbody2D>();

        controller       = GameObject.FindGameObjectWithTag("Ardunity").GetComponent <ArdunityApp>();
        controllerX      = GameObject.FindGameObjectWithTag("PlayerX").GetComponent <AnalogInput>();
        controllerButton = GameObject.FindGameObjectWithTag("PlayerButton").GetComponent <DigitalInput>();

        canJump = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            for (int i = 0; i < totalCamera.Count; i++)
            {
                totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
            }
            camChoice = false;
            theCanvasManager.SetCanvasActive(false);

            return;
        }

        if (!initRM)
        {
            controller  = GameObject.FindGameObjectWithTag("Ardunity").GetComponent <ArdunityApp>();
            controllerX = GameObject.FindGameObjectWithTag("CamX").GetComponent <AnalogInput>();
            controllerY = GameObject.FindGameObjectWithTag("CamY").GetComponent <AnalogInput>();
            controllerZ = GameObject.FindGameObjectWithTag("Zoom").GetComponent <AnalogInput>();
            trapButton  = GameObject.FindGameObjectWithTag("TrapButton").GetComponent <DigitalInput>();
            leftButton  = GameObject.FindGameObjectWithTag("LeftArrow").GetComponent <DigitalInput>();
            rightButton = GameObject.FindGameObjectWithTag("RightArrow").GetComponent <DigitalInput>();
            //camRoomName = "Room1";
            //trapSelect = 1;
            LoadProperties();
        }

        GameObject.FindGameObjectsWithTag("RunnerOne")[1].GetComponentInChildren <SkinnedMeshRenderer>().material = run2mat;

        //theCanvasManager.PrintCode(theRoomManager.ObjectiveLength());
        //theCanvasManager.PrintCode(theRoomManager.ObjectiveLength());

        //for deactivating traps :)
        switch (GameObject.Find(networkTrapStr).GetComponent <TrapForNetwork>().trapToGoAway)
        {
        case 1:
            R1currentObjective = GameObject.Find(O1).GetComponentInChildren <Objective>();

            break;

        case 2:
            R1currentObjective = GameObject.Find(O2).GetComponentInChildren <Objective>();

            break;

        case 3:
            R1currentObjective = GameObject.Find(O3).GetComponentInChildren <Objective>();

            break;

        case 4:
            R1currentObjective = GameObject.Find(O4).GetComponentInChildren <Objective>();

            break;

        case 5:
            R1currentObjective = GameObject.Find(O5).GetComponentInChildren <Objective>();

            break;

        case 6:
            R1currentObjective = GameObject.Find(O6).GetComponentInChildren <Objective>();

            break;

        case 7:
            R1currentObjective = GameObject.Find(O7).GetComponentInChildren <Objective>();

            break;

        default:
            //swing and a miss
            break;
        }

        switch (GameObject.Find(networkTrapStr).GetComponent <TrapForNetwork>().otherTrapToGoAway)
        {
        case 1:
            R2currentObjective = GameObject.Find(O1).GetComponentInChildren <Objective>();

            break;

        case 2:
            R2currentObjective = GameObject.Find(O2).GetComponentInChildren <Objective>();

            break;

        case 3:
            R2currentObjective = GameObject.Find(O3).GetComponentInChildren <Objective>();

            break;

        case 4:
            R2currentObjective = GameObject.Find(O4).GetComponentInChildren <Objective>();

            break;

        case 5:
            R2currentObjective = GameObject.Find(O5).GetComponentInChildren <Objective>();

            break;

        case 6:
            R2currentObjective = GameObject.Find(O6).GetComponentInChildren <Objective>();

            break;

        case 7:
            R2currentObjective = GameObject.Find(O7).GetComponentInChildren <Objective>();

            break;

        default:
            //swing and a miss
            break;
        }



        if (controller.connected)
        {
            if (controllerX.Value < .49f || controllerX.Value > .51f)
            {
                cameraLook.x = (controllerX.Value - .5f) * 2f;
            }
            else
            {
                cameraLook.x = 0;
            }

            if (controllerY.Value < .48f || controllerY.Value > .52f)
            {
                cameraLook.y = (controllerY.Value - .5f) * 2f;
            }
            else
            {
                cameraLook.y = 0;
            }

            if (controllerZ.Value < .48f || controllerZ.Value > .52f)
            {
                zAxis = (controllerZ.Value - .5f) * 2f;
            }
            else
            {
                zAxis = 0;
            }

            if (trapButton.Value == true)
            {
                trapPress = true;
            }
            if (leftButton.Value == true)
            {
                leftPress = true;
            }
            if (rightButton.Value == true)
            {
                rightPress = true;
            }
        }
        else
        {
            if (XBoxInput.getConnected())
            {
                cameraLook.x = XBoxInput.getLeftStickXAxis();
                cameraLook.y = XBoxInput.getLeftStickYAxis() * -1;

                zAxis = XBoxInput.getRightStickYAxis() * -1f;

                if (XBoxInput.getButtonA())
                {
                    trapPress = true;
                }
                if (XBoxInput.getButtonLB())
                {
                    leftPress = true;
                }
                if (XBoxInput.getButtonRB())
                {
                    rightPress = true;
                }
            }
            else
            {
                cameraLook.x += Input.GetAxis(mouseX);
                cameraLook.y += Input.GetAxis(mouseY);
            }
        }

        //clamp the camera's y rotation to prevent weird camera angles
        cameraLook.y = Mathf.Clamp(cameraLook.y, CAM_Y_MIN, CAM_Y_MAX);
        //cameraLook.x = Mathf.Clamp(cameraLook.x, CAM_X_MIN, CAM_X_MAX);

        //Debug.Log(totalCamera.Count);
        //array will be way more useful for this stuff later on

        //https://answers.unity.com/questions/615771/how-to-check-if-click-mouse-on-object.html
        //to activate trap
        if (Input.GetMouseButtonDown(0) || (trapPress && !trapButton.Value))
        {
            trapPress = false;
            clickRay  = totalCamera[currentCamera].GetComponentInChildren <Camera>().ViewportPointToRay(viewportCenter);
            //print(clickRay + " other ver " + totalCamera[currentCamera].GetComponentInChildren<Camera>().ViewportPointToRay(viewportCenter));

            if (Physics.Raycast(clickRay, out clickHit))
            {
                if (clickHit.transform.CompareTag(treasureStr))
                {
                    //atm, the overseer can only have 5 active traps at a time
                    //CmdObjectiveTrap(clickHit.collider.gameObject.name);
                    clickHit.collider.gameObject.GetComponent <Treasure>().TreasureOnClick(theRoomManager.theImages, gameObject.GetComponent <OverSeerControl>(), theRoomManager);//, this.gameObject.GetComponent<OverSeerControl>());
                }
                else if (clickHit.transform.CompareTag(securityStr))
                {
                    //Debug.Log(camRoomName);
                    //Debug.Log(trapSelect);
                    clickHit.collider.gameObject.GetComponent <TrapDoor>().OnSecurityClick(gameObject);
                }
            }
        }

        for (int i = 0; i < totalCamera.Count; i++)
        {
            findFOV(i);

            if (Input.GetKeyUp(KeyCode.LeftArrow) || (leftPress && leftButton.Value == false))
            {
                if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                {
                    leftPress    = false;
                    cameraLook.x = 0;
                    cameraLook.y = 0;
                    //totalCamera[i].GetComponentInChildren<Camera>().enabled = false;
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(cameraLook.y, ogRotation[i].y + cameraLook.x, 0);

                    if (totalCamera[i] == totalCamera[0])
                    {
                        trapSelect = 15;
                        totalCamera[totalCamera.Count - 1].GetComponentInChildren <Camera>().enabled = true;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
                        currentCamera = 14;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }
                    else
                    {
                        trapSelect--;
                        totalCamera[i - 1].GetComponentInChildren <Camera>().enabled = true;
                        currentCamera = i - 1;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }

                    //totalCamera[i].GetComponentInChildren<Camera>().enabled = false;
                }
                theCanvasManager.UpdateCanvasCamera(totalCamera[i].GetComponentInChildren <Camera>());
            }

            if (Input.GetKeyUp(KeyCode.RightArrow) || (rightPress && rightButton.Value == false))
            {
                if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                {
                    rightPress   = false;
                    cameraLook.x = 0;
                    cameraLook.y = 0;
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(cameraLook.y, ogRotation[i].y + cameraLook.x, 0);
                    if (totalCamera[i] == totalCamera[totalCamera.Count - 1])
                    {
                        trapSelect = 1;
                        totalCamera[0].GetComponentInChildren <Camera>().enabled = true;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
                        currentCamera = 0;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }
                    else
                    {
                        trapSelect++;
                        totalCamera[i + 1].GetComponentInChildren <Camera>().enabled = true;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled     = false;
                        currentCamera = i + 1;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }
                }
                theCanvasManager.UpdateCanvasCamera(totalCamera[i].GetComponentInChildren <Camera>());
            }

            if (controller.connected || XBoxInput.getConnected())
            {
                if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                {
                    float temp = totalCamera[i].GetComponentInChildren <Camera>().fieldOfView;

                    if (temp >= 30 && temp <= 70)
                    {
                        temp -= zAxis * zoomSpeed * Time.deltaTime;
                    }
                    if (temp > 70)
                    {
                        temp = 70;
                    }
                    if (temp < 30)
                    {
                        temp = 30;
                    }

                    totalCamera[i].GetComponentInChildren <Camera>().fieldOfView = temp;
                }
            }
            else
            {
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                    {
                        float temp = totalCamera[i].GetComponentInChildren <Camera>().fieldOfView;

                        if (temp > 30)
                        {
                            temp -= zoomSpeed * Time.deltaTime;
                        }

                        totalCamera[i].GetComponentInChildren <Camera>().fieldOfView = temp;
                    }
                }


                if (Input.GetKey(KeyCode.DownArrow))
                {
                    if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                    {
                        float temp = totalCamera[i].GetComponentInChildren <Camera>().fieldOfView;

                        if (temp < 70)
                        {
                            temp += zoomSpeed * Time.deltaTime;
                        }

                        totalCamera[i].GetComponentInChildren <Camera>().fieldOfView = temp;
                    }
                }
            }

            if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
            {
                if (controller.connected || XBoxInput.getConnected())
                {
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(Mathf.Clamp(totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles.x, 1, 85) + cameraLook.y, Mathf.Clamp(totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles.y, 0, 359) + cameraLook.x, 0);
                }
                else
                {
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(-cameraLook.y, ogRotation[i].y + cameraLook.x, 0);
                }
                Vector3 psoition = totalCamera[i].transform.position;
                SoundManager.setListenerPos(psoition.x, psoition.y, psoition.z);
                SoundManager.setListenerVel(0f, 0f, 0f);
                Vector3 cast = totalCamera[i].GetComponentInChildren <Camera>().ViewportPointToRay(viewportCenter).direction;
                SoundManager.setListenerForward(cast.x, cast.y, cast.z);
            }
        }


        //EVENT CONSOLE BULLSHIT
        //	to send stuff on the canvas queue

        //theCanvasManager.T1.text ="r1="+GameObject.FindGameObjectsWithTag("RunnerOne").Length.ToString();
        //theCanvasManager.T2.text ="r2=" + GameObject.FindGameObjectsWithTag("RunnerTwo").Length.ToString();


        //print(eventConsole.repetitiveshit());

        //theCanvasManager.T3.text = eventConsole.repetitiveshit();

        if (run1 == null || run2 == null)
        {
            theCanvasManager.T3.text = "SOMETHINGS NULL BITCHHHHH";
            theCanvasManager.T4.text = "r1=" + GameObject.FindGameObjectsWithTag("RunnerOne").Length.ToString();
            theCanvasManager.T5.text = "r2=" + GameObject.FindGameObjectsWithTag("RunnerTwo").Length.ToString();
        }
        else
        {
            //theCanvasManager.T4.text = "gets to this point";
            //if (OverID == 1)
            //{
            //	theCanvasManager.T4.text = "run2 cur " + run2.currstate.ToString();
            //	theCanvasManager.T5.text = "run1 cur " + run1.currstate.ToString();

            //}
            //else if (OverID == 2)
            //{
            //	theCanvasManager.T4.text = "run2 cur " + run2.currstate.ToString();
            //	theCanvasManager.T5.text = "run1 cur " + run1.currstate.ToString();

            //}

            if (run1.currstate != 0 || run2.currstate != 0)
            {
                theCanvasManager.newConsoleMessage(eventConsole.repetitiveshit());
                print("it gets to this point FUUUCk");
                print(run1.currstate.ToString());
                theCanvasManager.T5.text = "d " + eventConsole.repetitiveshit();
                run1.currstate           = 0;
                run2.currstate           = 0;
            }
        }

        theCanvasManager.consoleMessages();

        //theCanvasManager.T5.text = "gets to this point";



        //Debug.Log(OverID);

        camRoomName = roomStr + trapSelect.ToString();
    }