Пример #1
0
    void Update()
    {
        UpdateSerial();

        if (state >= STATE_SATELLITE_LOCKED)
        {
            updatePotReadings();
            updatePotVisuals();
            updateSelection();
            calculateReactorLoad();
            calculateCooling();
        }

        //test

        /*if(Input.GetKeyUp(KeyCode.R)){
         *      Application.LoadLevel(Application.loadedLevel);
         * }*/

        if (state == STATE_COUNTDOWN)
        {
            if (doorOpen)
            {
                showLowBattery();
                state = STATE_LOWBATTERY;
            }
        }
        else if (state == STATE_LOWBATTERY)
        {
            if (!batteryInstalled)
            {
                fadeToBlack();
                state = STATE_NOBATTERY;
            }
        }
        else if (state == STATE_NOBATTERY)
        {
            if (batteryInstalled)
            {
                fadeFromBlack();
                if (!batteryCharged)
                {
                    state = STATE_LOWBATTERY;
                }
                else
                {
                    state = STATE_UNLOCK_SCREEN;
                    unlockPanel.SetActive(true);

                    //unlockPanel.transform.Translate(0f, -500f,0f);
                    //unlockPanel.GetComponent<videoAnim> ().enabled = true;
                    unlockPanel.GetComponent <DOTweenAnimation> ().DOPlayBackwards();
                    //unlockPanel.GetComponent<videoAnim>().start();
                    StartCoroutine("PlayUnlockInitAnimation", 1f);

                    lowBatteryIcon.SetActive(false);
                    //GameObject.Find ("LowBatteryIcon").GetComponent<DOTweenAnimation> ().DOPlayBackwards ();
                }
            }
        }
        else if (state == STATE_UNLOCK_SCREEN)
        {
            unlockObject.updateButtons(keyStates);
            if (!standaloneDebug)
            {
                codeEnteredCorrect = unlockObject.checkComplete();
            }
            if (codeEnteredCorrect)
            {
                //unlockPanel.SetActive(true);
                SerialComm.WriteToArduino("#C");                  //CODE CORRECT COMMAND

                unlockPanel.GetComponent <DOTweenAnimation> ().DOPlayForward();
                StartCoroutine("DisableUnlockPanel", 1f);
                state = STATE_SATELLITE_DISCONNECTED_SCREEN;
                //StartCoroutine("delayedShowMessageBox",1f);
                DOTween.PlayBackwards("SatelliteSearchTextFade");

                StartCoroutine("delayedShowRadar", 2f);
                //satellite.transform.localScale = new Vector3(0,0,0);
                satellite.GetComponent <DOTweenAnimation> ().DOPlayBackwards();
            }
        }
        else if (state == STATE_SATELLITE_DISCONNECTED_SCREEN)
        {
            if (standaloneDebug)
            {
                joystickX = Input.GetKey(KeyCode.RightArrow).GetHashCode() + Input.GetKey(KeyCode.LeftArrow).GetHashCode() * -1;
                joystickY = Input.GetKey(KeyCode.UpArrow).GetHashCode() + Input.GetKey(KeyCode.DownArrow).GetHashCode() * -1;
            }

            radarController.velocity.x = joystickX * 10;            //+= (joystickX*10-radarController.velocity.x)*0.9f;
            radarController.velocity.y = joystickY * 10;


            if (radarController.progress > 0.7f && radarController.progress < 0.95f)
            {
                Vector3 tempVec = satellite.transform.localScale;
                tempVec.x = tempVec.y = tempVec.z = (radarController.progress - 0.7f) / 0.3f * satelliteInitialScale;
                satellite.transform.localScale = tempVec;
            }
            else if (radarController.progress > 0.95f)
            {
                state = STATE_SATELLITE_LOCKED;
                SerialComm.WriteToArduino("#S");                  //SATELLITE LOCKED COMMAND
                radarController.locked         = true;
                satellite.transform.localScale = new Vector3(satelliteInitialScale, satelliteInitialScale, satelliteInitialScale);
                //satellite.GetComponent<DOTweenAnimation>().DOPlayForward();
                //DOTween.PlayForward ("satelliteShow");
                DOTween.PlayForward("SatelliteSearchTextFade");
                if (!windowGrid.enabled)
                {
                    windowGrid.enabled = true;
                }
            }
        }
        else if (state == STATE_SATELLITE_LOCKED)
        {
            if (usbDriveConnected)
            {
                state = STATE_HACKING;
                hackWindow.SetActive(true);
                progressBar.SetActive(true);
                DOTween.PlayBackwards("progressBarHide");
                DOTween.PlayBackwards("hackWindowHide");
                progressBarController.setTitle("Hacking satellite...", "Взлом спутника...");
            }
        }
        else if (state == STATE_HACKING)
        {
            if (progressBarController.progress < 0.32)
            {
                progressBarController.progress += UnityEngine.Random.value * 0.005f;
            }
            else if (progressBarController.progress < 1)
            {
                if (!satSerialOk && !inputBox.activeSelf)
                {
                    inputBox.SetActive(true);
                    inputBox.GetComponent <DOTweenAnimation> ().DOPlayBackwards();
                    inputController.createInputBox("Input satellite serial #");
                    //StartCoroutine("delayedShowMessageBox",1f);
                }


                if (satSerialOk)
                {
                    progressBarController.progress += UnityEngine.Random.value * 0.005f;
                }
                else
                {
                    if (inputController.inputString.Length == satSerial.Length)
                    {
                        if (inputController.inputString == satSerial)
                        {
                            satSerialOk = true;
                            //remove inputbox
                            inputBox.GetComponent <DOTweenAnimation> ().DOPlayForward();
                            StartCoroutine("delayedDisableInputBox", 1f);
                        }
                        else
                        {
                            //replace title with "try again" and clear input field
                            inputController.changeTitle("Try again", true);
                            inputController.clear();
                        }
                    }
                }
            }
            else
            {
                timerController.paused = true;

                //AudioController.Play("SatelliteRollback");

                //Перекрасить спутник в красный
                foreach (Transform child in satellite.transform)
                {
                    child.gameObject.GetComponent <Renderer> ().material = satelliteRed;
                }
                state = STATE_HACKED;
                StartCoroutine("delayedStartSatReboot");
                DOTween.PlayForward("progressBarHide");
                DOTween.PlayForward("hackWindowHide");
                progressBarController.progress = 0;
                GameObject.Find("HackingVideo").GetComponent <videoAnim> ().pause();
                //TEST OVERHEAT FROM FLASH DRIVE
                if (!overheatSent)
                {
                    SerialComm.WriteToArduino("#E");
                    mainCamera.GetComponent <CameraFilterPack_FX_Glitch1> ().enabled     = true;
                    mainCamera.GetComponent <CameraFilterPack_TV_BrokenGlass> ().enabled = true;
                    overheatSent = true;
                }
            }
        }
        else if (state == STATE_HACKED)
        {
            progressBarController.progress = 1 - timerController.timeLeft() / timeStamp;
        }
    }