示例#1
0
 /// <summary> Refresh information texts. </summary>
 private void RefreshInfoTexts()
 {
     mainInfoText.text =
         "controller count: " + NRInput.GetAvailableControllersCount().ToString() + "\n"
         + "type: " + NRInput.GetControllerType().ToString() + "\n"
         + "current debug hand: " + m_CurrentDebugHand.ToString() + "\n"
         + "position available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION).ToString() + "\n"
         + "rotation available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ROTATION).ToString() + "\n"
         + "gyro available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_GYRO).ToString() + "\n"
         + "accel available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ACCEL).ToString() + "\n"
         + "mag available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_MAG).ToString() + "\n"
         + "battery available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_BATTERY).ToString() + "\n"
         + "vibration available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_HAPTIC_VIBRATE).ToString() + "\n"
         + "rotation: " + NRInput.GetRotation(m_CurrentDebugHand).ToString("F3") + "\n"
         + "position: " + NRInput.GetPosition(m_CurrentDebugHand).ToString("F3") + "\n"
         + "touch: " + NRInput.GetTouch(m_CurrentDebugHand).ToString("F3") + "\n"
         + "trigger button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.TRIGGER).ToString() + "\n"
         + "home button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.HOME).ToString() + "\n"
         + "app button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.APP).ToString() + "\n"
         + "grip button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.GRIP).ToString() + "\n"
         + "touchpad button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.TOUCHPAD_BUTTON).ToString() + "\n"
         + "gyro: " + NRInput.GetGyro(m_CurrentDebugHand).ToString("F3") + "\n"
         + "accel: " + NRInput.GetAccel(m_CurrentDebugHand).ToString("F3") + "\n"
         + "mag: " + NRInput.GetMag(m_CurrentDebugHand).ToString("F3") + "\n"
         + "battery: " + NRInput.GetControllerBattery(m_CurrentDebugHand);
     extraInfoText.text = m_ExtraInfoStr;
     //Debug.Log("istouching:" + NRInput.IsTouching() + " value:" + NRInput.GetTouch(m_CurrentDebugHand).ToString("F3"));
     PrintInputState();
 }
示例#2
0
 private void RefreshInfoTexts()
 {
     mainInfoText.text =
         "controller count: " + NRInput.GetAvailableControllersCount().ToString() + "\n"
         + "type: " + NRInput.GetControllerType().ToString() + "\n"
         + "domain hand: " + NRInput.DomainHand.ToString() + "\n"
         + "position available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION).ToString() + "\n"
         + "rotation available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ROTATION).ToString() + "\n"
         + "gyro available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_GYRO).ToString() + "\n"
         + "accel available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ACCEL).ToString() + "\n"
         + "mag available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_MAG).ToString() + "\n"
         + "battery available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_BATTERY).ToString() + "\n"
         + "vibration available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_HAPTIC_VIBRATE).ToString() + "\n"
         + "rotation: " + NRInput.GetRotation().ToString("F3") + "\n"
         + "position: " + NRInput.GetPosition().ToString("F3") + "\n"
         + "touch: " + NRInput.GetTouch().ToString("F3") + "\n"
         + "trigger, home, app: " + NRInput.GetButton(ControllerButton.TRIGGER).ToString() + NRInput.GetButton(ControllerButton.HOME).ToString() + NRInput.GetButton(ControllerButton.APP).ToString() + "\n"
         + "gyro: " + NRInput.GetGyro().ToString("F3") + "\n"
         + "accel: " + NRInput.GetAccel().ToString("F3") + "\n"
         + "mag: " + NRInput.GetMag().ToString("F3") + "\n"
         + "battery: " + NRInput.GetControllerBattery();
     extraInfoText.text = m_ExtraInfoStr;
 }
示例#3
0
 /// <summary> Updates this object. </summary>
 void Update()
 {
     //get controller rotation, and set the value to the cube transform
     transform.rotation = NRInput.GetRotation();
 }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if (staticStuff.score > 0)
        {
            score            += staticStuff.score * 10;
            staticStuff.score = 0;
        }

        if (staticStuff.ammo > 0)
        {
            bullets         += staticStuff.ammo * 10;
            staticStuff.ammo = 0;
        }
        if (staticStuff.carHealth < 0)
        {
            staticStuff.carHealth = 0;
        }
        // Update the score
        if (reloading > 0)
        {
            text.text = "Score : " + score + "\nHealth : " + Math.Round(staticStuff.carHealth, 1) + "\nAmmo : Reloading/" + bullets;
        }
        else
        {
            text.text = "Score : " + score + "\nHealth : " + Math.Round(staticStuff.carHealth, 1) + "\nAmmo : " + clip + "/" + bullets;
        }

        if (staticStuff.gameOver)
        {
            if (countdown > 0)
            {
                countdown--;
            }
            text.text    = "";
            endText.text = "Game Over!\nScore:" + score + "\nRestarting in " + Math.Ceiling((double)(countdown / 100) + 1) + "...";
            if (countdown <= 0)
            {
                staticStuff.carHealth = staticStuff.maxCarHealth;
                staticStuff.score     = 0;
                staticStuff.ammo      = 0;
                staticStuff.zombieNum = 0;
                staticStuff.gameOver  = false;
                countdown             = 300;
                clip    = 10;
                bullets = 20;
                //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); This works on laptop but crashed on nreal
            }
        }
        else
        {
            endText.text = "";
        }

        if (staticStuff.carHealth <= 0)
        {
            staticStuff.gameOver = true;
        }

        // Check for an update on the car locations
        int recHostId;
        int recConnectionId;
        int recChannelId;

        byte[]           recBuffer  = new byte[1350];
        int              bufferSize = 1350;
        int              dataSize;
        byte             error;
        NetworkEventType recNetworkEvent = NetworkTransport.Receive(out recHostId, out recConnectionId, out recChannelId, recBuffer, bufferSize, out dataSize, out error);

        //output.text = output.text + "" + recNetworkEvent;
        switch (recNetworkEvent)
        {
        case NetworkEventType.Nothing:
            break;

        case NetworkEventType.ConnectEvent:
            Debug.Log("incoming connection event received");
            //output.text = output.text + "connectEventReceived";
            break;

        case NetworkEventType.DataEvent:
            Stream          stream    = new MemoryStream(recBuffer);
            BinaryFormatter formatter = new BinaryFormatter();
            string          message   = formatter.Deserialize(stream) as string;

            // Parse the updated locations into the Info struct format and process it
            Info inf = JsonUtility.FromJson <Info>(message);
            updateCars(inf);
            //output.text = output.text + "car update received";
            break;

        case NetworkEventType.DisconnectEvent:
            Debug.Log("remote client event disconnected");
            break;
        }

        // Spawn coins with a wait period in between
        coinWaited++;
        if (coinWaited > coinWait)
        {
            coinWaited = 0;
            //GameObject newCoin = Instantiate(coin, new Vector3(UnityEngine.Random.Range(-width, width), 0.2f, 15), transform.rotation);
        }

        /*
         * if (staticStuff.carHealth < 50 && windowCracks.transform.position.y > 50)
         * {
         *  windowCracks.transform.position -= new Vector3(0, windowCracks.transform.position.y - 0.75f, 0);
         * }
         *
         * if (staticStuff.carHealth > 50 && windowCracks.transform.position.y < 50)
         * {
         *  windowCracks.transform.position += new Vector3(0, 100, 0);
         * }
         */
        float newC = (float)(1 - Math.Round(staticStuff.carHealth / 100, 1));

        cracks.SetTextureScale("_MainTex", new Vector2(newC, newC));


        spawnTimer++;
        if (spawnTimer > spawnWait && staticStuff.zombieNum < maxZombies && !staticStuff.gameOver && spawnZs)
        {
            spawnTimer = 0;
            GameObject newZombie = Instantiate(zombie, new Vector3(0, 0.1f, 20), Quaternion.identity);
            newZombie.transform.RotateAround(center.transform.position, Vector3.up, UnityEngine.Random.Range(0, 360));
            newZombie.GetComponent <zombie>().car    = car;
            newZombie.GetComponent <zombie>().target = center;
            Vector3 targetDir = newZombie.transform.position - car.transform.position;
            float   angle     = Vector3.Angle(targetDir, car.transform.forward);
            Debug.Log("Created with angle : " + angle);
            if (angle > allowedAngle)
            {
                Destroy(newZombie);
                spawnTimer = spawnWait + 1;
            }
            else
            {
                staticStuff.zombieNum++;
            }
        }

        if (controllerMode)
        {
            //gun.transform.position = NRInput.GetPosition() + new Vector3(0,1,0);
            gun.transform.rotation = NRInput.GetRotation();
        }

        if ((Input.GetKeyDown(KeyCode.E) || NRInput.GetButtonDown(ControllerButton.TRIGGER)) && clip > 0 && !staticStuff.gameOver)
        {
            Vector3 newRot = cam.transform.eulerAngles;

            //newRot.x += 90;
            //Debug.Log(newRot);
            //newRot.y += 90;
            //newRot.z += 90;
            Quaternion newRotQ   = new Quaternion(newRot.x, newRot.y, newRot.z, cam.transform.localRotation.w);//.normalized;
            GameObject newBullet = Instantiate(bullet, bulletSpawn.transform.position, newRotQ);
            //newBullet.transform.parent = bulletSpawn.transform;
            //newBullet.transform.rotation = newRotQ;
            //newBullet.transform.GetChild(0).GetComponent<bullet>().rot = cam.transform.rotation;
            if (controllerMode)
            {
                newBullet.GetComponent <bullet>().rot = gun.transform.rotation;
            }
            else
            {
                newBullet.GetComponent <bullet>().rot = cam.transform.rotation;
            }
            clip--;
        }

        buTiWaited++;
        if (buTiWaited > bulletTrickleTime)
        {
            buTiWaited = 0;
            bullets++;
        }

        if (clip <= 0 && reloading <= 0)
        {
            reloading = 100;
        }

        if (reloading > 0 && bullets > 0)
        {
            reloading--;
        }

        if (reloading <= 0 && clip == 0)
        {
            if (bullets < 10)
            {
                clip     = bullets;
                bullets -= clip;
            }
            if (bullets >= 10)
            {
                clip     = 10;
                bullets -= 10;
            }
        }
    }