public void PuzzletConnectionStateChanged(PuzzletConnection.State lastState, PuzzletConnection.State state)
    {
        Debug.Log("PuzzletConnection last state: " + lastState + ". New state: " + state);

        interactionTimeoutPrompt.SetActive(false);

        bool showNewState = true;

        //hiding searching/connecting loop
        if (lastState == PuzzletConnection.State.Handshaking && state == PuzzletConnection.State.Disconnected)
        {
            ++handshakeRepeats;
        }

        if (handshakeRepeats > 0)
        {
            if (state == PuzzletConnection.State.Handshaking || state == PuzzletConnection.State.Disconnected)
            {
                showNewState = false;
            }
            else
            {
                handshakeRepeats = 0;
                handshakeRepeatText.SetActive(false);
            }

            if (handshakeRepeats > handshakeRepeatsToHide)
            {
                handshakeRepeatText.SetActive(true);
            }
        }

        //checking if no tray found in a reasonable time frame (see also Update)
                #if !(UNITY_STANDALONE || UNITY_EDITOR)
        if (state == PuzzletConnection.State.Disconnected)
        {
            noTrayFoundTime = 0;
        }
        else
        {
            TrayFound();
        }
                #endif

        //enabling/disabling the display
        StopAllCoroutines();

        if (state == PuzzletConnection.State.Connected)
        {
            firmwareVersionText.text = PuzzletUtility.FirmwareString().Substring(0, 5);

            StartCoroutine(this.Disable());
        }
        else
        {
            root.SetActive(true);
            rootAnim.SetActive(true);
        }

        //updating contents of display
        if (showNewState)
        {
            for (int a = 0; a < texts.Length; ++a)
            {
                texts[a].SetActive(false);
            }

            texts[(int)state].SetActive(true);

            string triggerName = "NO_TRIGGER";

                        #if UNITY_STANDALONE || UNITY_EDITOR
            if (state == PuzzletConnection.State.Disconnected)
            {
                triggerName = "ConnectUSB";
            }
            else if (state == PuzzletConnection.State.Handshaking)
            {
                triggerName = "ConnectingUSB";
            }
            else if (state == PuzzletConnection.State.Connected)
            {
                triggerName = "ConnectedUSB";
            }
                        #else
            if (state == PuzzletConnection.State.Disconnected)
            {
                triggerName = "ConnectBluetooth";
            }
            else if (state == PuzzletConnection.State.Handshaking)
            {
                triggerName = "ConnectingBluetooth";
            }
            else if (state == PuzzletConnection.State.Connected)
            {
                triggerName = "ConnectedBluetooth";
            }
                        #endif

            /*if(state == PuzzletConnection.State.Disconnected)
             *      triggerName = "ConnectBluetooth";
             * else if (state == PuzzletConnection.State.Handshaking)
             *      triggerName = "ConnectingBluetooth";
             * else if(state == PuzzletConnection.State.Connected)
             *      triggerName = "ConnectedBluetooth";*/

            Debug.Log("Connection Status Animation Triggered: " + triggerName);
            anim.SetTrigger(triggerName);
        }

        //text in/out
        if (state == PuzzletConnection.State.Connected)
        {
            textAnim.SetTrigger("ScaleOut");
        }
        else
        {
            textAnim.SetTrigger("ScaleIn");
        }

        tooFarTimes = 0;
    }
Ejemplo n.º 2
0
    IEnumerator CheckConnection()
    {
        //hold on the company logo for at least 2.5 seconds
        yield return(new WaitForSeconds(2.5f));

        //for the next 7.5 seconds, skip to the title as soon as a connection is found
        for (int ii = 0; ii < 75; ii++)
        {
            yield return(new WaitForSeconds(.1f));

            if (PuzzletConnection.Connected)
            {
                break;
            }
        }

        if (!PuzzletConnection.Connected)
        {
            ConnectionAnim.SetBool("Invisible", false);
            ConnectionAnim.SetBool("ConnectionEstablished", false);


            //wait for a connection or a command to jump to the demo
            while (!PuzzletConnection.Connected)
            {
                yield return(new WaitForSeconds(.1f));
            }
        }

        //turn the connection error off and go to the title screen
        bool requiredVersion = PuzzletUtility.CheckFirmwareVersion();
        bool upToDateVersion = true;

        if (latestVersions != null && !PuzzletUtility.CheckFirmwareVersion(latestVersions[PuzzletConnection.HardwareVersion]))
        {
            upToDateVersion = false;
        }

        ConnectionAnim.SetBool("Invisible", false);
        ConnectionAnim.SetBool("RequiredVersion", requiredVersion);
        ConnectionAnim.SetBool("UpToDate", upToDateVersion);
        ConnectionAnim.SetBool("ConnectionEstablished", true);
        Debug.Log(string.Format("Required: {0}, Up To Date: {1}", requiredVersion, upToDateVersion));
        Debug.Log(string.Format("Required Verson: {0}, Current Version: {1}", PuzzletUtility.RequiredFirmwareString(), PuzzletUtility.FirmwareString()));

        yield return(new WaitForSeconds(.5f));

#if UNITY_WEBPLAYER
        //if it's a webplayer, wait until the next scene is loaded
        while (!Application.CanStreamedLevelBeLoaded(LevelValues.TitleScreen))
        {
            yield return(new WaitForSeconds(.1f));
        }
#endif
        if (requiredVersion && upToDateVersion)
        {
            Application.LoadLevel(1);             //always load second level, since this connection screen should always be first
        }
        else
        {
            StartCoroutine(CheckConnection());
        }
    }