private void HandleGeneralUpdate(int index, DemoCoder decoder)
 {
     if (index == 0)
     {
         Henge henge = GameObject.FindObjectOfType <Henge>();
         henge.SetRuneState(decoder.GetPortalRunes(index, henge.getSize()));
         henge.transform.position = decoder.GetPosition(index);
         henge.transform.rotation = decoder.GetRotation(index);
     }
     else
     {
         GameObject instance;
         int        id = decoder.GetID(index);
         networkedObjects.TryGetValue(id, out instance);
         EnemyHealth eh = instance.GetComponent <EnemyHealth>();
         if (eh != null)
         {
             //keeps track of networked and local at the same time
             int currentHealth   = eh.GetHealth();
             int networkedHealth = decoder.GetEnemyHealth(index) - eh.transientHealthLoss;
             //don't reset transient, since this may still need to be transmitted
             eh.SetHealth(Math.Min(currentHealth, networkedHealth));
         }
         else
         {
             Debug.LogError("Couldn't find enemy health tracking from network id" + id);
         }
         instance.transform.position = decoder.GetPosition(index);
         instance.transform.rotation = decoder.GetRotation(index);
     }
 }
Beispiel #2
0
    /*
     * private float getFramerate() {
     * //OLD Framerate calculation
     * frameTimes.Enqueue(Time.time);
     * float firstFrame = frameTimes.Peek();
     * float framerate = 0;
     *
     * changeFramerateString(String.Format("Framerate:\t{0:0}fps\nNetwork:\t{1:0}ms", framerate, latency));
     *
     * if (frameTimes.Count > FrameQueueSize) {
     *      framerate = (frameTimes.Count) / (Time.time - firstFrame);
     *      frameTimes.Dequeue();
     * }
     * return framerate;
     * }*/

    // Update is called once per frame
    void Update()
    {
        //Arrays of strings displayed as debug information
        String[] psDebug = new String[4];               //performance stats debug
        String[] gsDebug = new String[4];               //game state debug

        deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;

        if (fpsDelay > 0)
        {
            fpsDelay -= Time.deltaTime;
            return;
        }

        //deltaTime = Time.deltaTime;
        float msec = deltaTime * 1000.0f;
        float fps  = (1.0f / deltaTime);

        if (fps > fpsmax)
        {
            fpsmax = fps;
        }
        if (fps < fpsmin)
        {
            fpsmin = fps;
        }

        frametimetotal += deltaTime;
        frametimecount++;
        fpsavg = (frametimecount / frametimetotal);

        if (frametimecount > 64000)
        {
            //reset?
        }

        psDebug[0] = String.Format("{0,-12}{1:0.0} ms ({2:0} fps)", "Framerate:", msec, fps);
        //psDebug[1] = String.Format("{0}\t{1})", frametimetotal, frametimecount);
        psDebug[1] = String.Format("{0,-12}{1:0.0}/{2:0.0}/{3:0.0}", "Min/Avg/Max:", fpsmin, fpsavg, fpsmax);
        psDebug[2] = String.Format("{0,-12}{1}", "Network:", networkStatus);
        psDebug[3] = String.Format("{0,-12}{1}", "GameState:", gameManager.GetGameState().ToString());


        //Update Player health, Rune completion, Allies, Enemies debug text
        //Apart from player health, probably do not want to be doing these calculations every frame
        //Consider updating those every x seconds
        String ph = String.Format("{0:0}%", ((float)playerHealth.currentHealth / (float)playerHealth.maxHealth) * 100.0f);
        //String rs = String.Format("{0:0}%", (henge.getActiveRunes() / henge.getSize()) * 100);
        String rs      = henge.getActiveRunes() + "/" + henge.getSize();
        int    allies  = FindObjectsOfType <Eyeball>().Length + 1;
        int    enemies = FindObjectsOfType <EnemyHealth>().Length;

        gsDebug[0] = String.Format("Player:{0,5}", ph);
        gsDebug[1] = String.Format("Henge:{0,5}", rs);
        gsDebug[2] = String.Format("Allies:{0,5}", allies);
        gsDebug[3] = String.Format("Enemies:{0,5}", enemies);

        changeFramerateString(psDebug[0] + "\n" + psDebug[1] + "\n" + psDebug[2] + "\n" + psDebug[3]);
        changeGameStatusString(gsDebug[0] + "\n" + gsDebug[1] + "\n" + gsDebug[2] + "\n" + gsDebug[3]);



        //Debug text for engine, ARKit positions and rotations
        Vector3 enginePosition = ARManager.getUnityCameraPosition();
        Vector4 ARKitPosition  = ARManager.getARKitPosition();
        //Quaternion engineRotation = ARManager.getUnityCameraRotation (); //UnityARMatrixOps.GetRotation (UnityARSessionNativeInterface.lastTransform);
        //Quaternion ARKitRotation = ARManager.getARKitRotation ();
        Vector3    engineRotation   = ARManager.getUnityCameraRotation().eulerAngles;
        Vector3    ARKitRotation    = ARManager.getARKitRotation().eulerAngles;
        Vector3    cparentPosition  = ARManager.m_camera.gameObject.transform.parent.transform.position;
        Quaternion cparentRotation  = ARManager.m_camera.gameObject.transform.parent.transform.rotation;
        Vector3    cparentRotationE = ARManager.m_camera.gameObject.transform.parent.transform.rotation.eulerAngles;

        /*
         * positionARKitText.text = "pos: {" + Math.Round(ARKitPosition.x, 2) + ", " + Math.Round(ARKitPosition.y, 2) + ", " + Math.Round(ARKitPosition.z, 2) + "}";
         * rotationARKitText.text = "rot: {" + Math.Round(ARKitRotation.x, 2) + ", " + Math.Round(ARKitRotation.y, 2) + ", " + Math.Round(ARKitRotation.z, 2) + "}";
         * positionEngineText.text = "pos: {" + Math.Round(enginePosition.x, 2) + ", " + Math.Round(enginePosition.y, 2) + ", " + Math.Round(enginePosition.z, 2) + "}";
         * rotationEngineText.text = "rot: {" + Math.Round(engineRotation.x, 2) + ", " + Math.Round(engineRotation.y, 2) + ", " + Math.Round(engineRotation.z, 2) + "}";
         */

        Vector3 offsetPos = tPos - ARManager.gameObject.transform.position;
        Vector3 offsetRot = (tRot * Quaternion.Inverse(ARManager.gameObject.transform.rotation)).eulerAngles;

        positionARKitText.text   = String.Format("pos: ({0:0.0}, {1:0.0}, {2:0.0})", ARKitPosition.x, ARKitPosition.y, ARKitPosition.z);
        rotationARKitText.text   = String.Format("rot: ({0:000}, {1:000}, {2:000})", ARKitRotation.x, ARKitRotation.y, ARKitRotation.z);
        positionEngineText.text  = String.Format("pos: ({0:0.0}, {1:0.0}, {2:0.0})", enginePosition.x, enginePosition.y, enginePosition.z);
        rotationEngineText.text  = String.Format("rot: ({0:000}, {1:000}, {2:000})", engineRotation.x, engineRotation.y, engineRotation.z);
        positionCParentText.text = String.Format("pos: ({0:0.0}, {1:0.0}, {2:0.0})", cparentPosition.x, cparentPosition.y, cparentPosition.z) +
                                   String.Format("\nfP: ({0:0.0}, {1:0.0}, {2:0.0})", offsetPos.x, offsetPos.y, offsetPos.z);
        rotationCParentText.text = String.Format("rot: ({0:000}, {1:000}, {2:000})", cparentRotationE.x, cparentRotationE.y, cparentRotationE.z) +
                                   String.Format("\nofR: ({0:0.0}, {1:0.0}, {2:0.0})", offsetRot.x, offsetRot.y, offsetRot.z);
    }