Example #1
0
    private IEnumerator Start()
    {
        m_Reticle.Show();

        DontDestroyOnLoad(VRTracker.instance);
        bool assignationSuccess = false;

        //Disable by default the spectator mode on mobile device
                #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
        VRTracker.instance.isSpectator = false;
                #endif

        //Check if spectator mode is activated
        if (!VRTracker.instance.isSpectator)
        {
            m_SliderCroup.hideSpectatorMode();
            if (VRTracker.instance.autoAssignation)
            {
                VRTrackerTag[] tags = VRTracker.instance.gameObject.GetComponentsInChildren <VRTrackerTag> ();
                while (tags.Length != VRTracker.instance.tags.Count)
                {
                    //Wait for everything to be loaded correctly
                    yield return(new WaitForSeconds(1));
                }
                if (VRTrackerTagAssignment.instance.LoadAssociation())
                {
                    assignationSuccess = VRTrackerTagAssignment.instance.TryAutoAssignTag();
                    if (!assignationSuccess)
                    {
                        m_SliderCroup.hideSkipAssignationSlider();
                    }
                }
            }


            // Assign a Tag to each Prefab instance containing a Tag in VR Tracker
            if (!assignationSuccess)
            {
                // In order, fade in the UI on confirming the use of sliders, wait for the slider to be filled, then fade out the UI.
                yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeIn()));

                yield return(StartCoroutine(m_SliderCroup.WaitForBarsToFill()));

                yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeOut()));

                //Assignement step
                foreach (VRTrackerTag tag in VRTracker.instance.tags)
                {
                    bool associationFailed = true;
                    while (associationFailed)
                    {
                        // Edit shown title to the Prefab name
                        m_AssociationFader.transform.Find("CalibrationInstructions/Title").GetComponentInChildren <Text>().text = "Assign " + tag.tagType.ToString();

                        // Start assignation
                        yield return(StartCoroutine(ShowMenu(m_AssociationFader, tag)));

                        // Check if timed out and throw an error
                        if (!tag.IDisAssigned)
                        {
                            associationFailed = true;
                            yield return(StartCoroutine(ShowMenu(m_FailedCalibrationFader, m_FailedCalibrationSlider)));
                        }
                        else
                        {
                            associationFailed = false;
                            tag.AssignTag(tag.UID);
                        }
                    }
                }
            }


            VRTracker.instance.SaveAssociationTagUser();
            enablePlayerCameraForNextLevel();

            // Load the next Level (the Game !)
            yield return(StartCoroutine(m_LoadingFader.InteruptAndFadeIn()));

            if (VRTracker.instance.serverIp == "" || VRTracker.instance.serverIp == Network.player.ipAddress)
            {
                VRTracker.instance.serverIp = Network.player.ipAddress;
                VRTracker.instance.SendServerIP(VRTracker.instance.serverIp);
                VRTrackerNetwork.instance.serverBindAddress = VRTracker.instance.serverIp;
                VRTrackerNetwork.instance.StartHost();
            }
            else
            {
                VRTrackerNetwork.instance.serverBindAddress = VRTracker.instance.serverIp;
                VRTrackerNetwork.instance.serverBindToIP    = true;
                VRTrackerNetwork.instance.networkAddress    = VRTracker.instance.serverIp;
                //after binding address, start server
                VRTrackerNetwork.instance.StartClient();
            }
        }
        else
        {
            VRTracker.instance.serverIp = Network.player.ipAddress;
            VRTracker.instance.SendServerIP(VRTracker.instance.serverIp);
            //Start in spectator mode
            VRTrackerNetwork.instance.StartServer();
        }
    }
        private IEnumerator Start()
        {
            m_Reticle.Show();
            //m_Radial.Hide ();

            DontDestroyOnLoad(VRTracker.instance);
            if (VRTracker.instance.autoAssignation)
            {
                Debug.Log("Loading association");
                VRTrackerTagAssociation.instance.LoadAssociation();
            }
            if (!VRTrackerTagAssociation.instance.isAssociationLoaded)
            {
                Debug.LogWarning("hide auto assingation");
                m_SliderCroup.hideSkipAssignationSlider();
            }

            GameObject pPrefab = NetworkManager.singleton.playerPrefab;

            //Create and prepare the different prefab for assignation in the next scene
            if (pPrefab != null)
            {
                VRTrackerTag[] playerObject = pPrefab.GetComponentsInChildren <VRTrackerTag>();
                for (int i = 0; i < playerObject.Length; i++)
                {
                    //Store the different player prefab name for association
                    VRTrackerAssociation newAsso = new VRTrackerAssociation();
                    VRTrackerTagAssociation.instance.addPrefabAssociation(playerObject[i].gameObject.name, newAsso);
                }
            }

            if (VRTracker.instance.autoAssignation)
            {
                yield return(new WaitForSeconds(1));

                VRTracker.instance.assignDirectlyTags();
                if (!VRTracker.instance.assignationComplete)
                {
                    m_SliderCroup.hideSkipAssignationSlider();
                }
            }

            // In order, fade in the UI on confirming the use of sliders, wait for the slider to be filled, then fade out the UI.
            yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeIn()));

            yield return(StartCoroutine(m_SliderCroup.WaitForBarsToFill()));

            //yield return StartCoroutine(m_SliderCroup.WaitForBarsToFill());
            yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeOut()));


            // Assign a Tag to each Prefab instance containing a Tag in VR Tracker
            if (!VRTracker.instance.isAssigned())
            {
                Debug.Log("Manual assignement ");

                //Assignement step
                //foreach (VRTrackerTag tagObject in VRTracker.instance.tags)
                foreach (KeyValuePair <string, VRTrackerAssociation> prefab in VRTrackerTagAssociation.instance.prefabAssociation)
                {
                    Debug.Log("Assigning Tag to " + prefab.Key);

                    bool associationFailed = true;
                    while (associationFailed)
                    {
                        // Edit shown title to the Prefab name
                        m_AssociationFader.transform.Find("CalibrationInstructions/Title").GetComponentInChildren <Text>().text = "Assign" + prefab.Key;

                        // Start assignation
                        yield return(StartCoroutine(ShowMenu(m_AssociationFader, prefab.Value)));

                        // Check if timed out and throw an error
                        if (!prefab.Value.isIDAssigned)
                        {
                            associationFailed = true;
                            yield return(StartCoroutine(ShowMenu(m_FailedCalibrationFader, m_FailedCalibrationSlider)));
                        }
                        else
                        {
                            associationFailed = false;
                        }
                    }
                }
            }

            VRTracker.instance.saveAssociationTagUser();
            // Load the next Level (the Game !)
            enablePlayerCameraForNextLevel();
            Debug.Log("Loading next level");
            yield return(StartCoroutine(m_LoadingFader.InteruptAndFadeIn()));

            //LevelLoader.instance.LoadLevel(1);
            if (VRTracker.instance.serverIp == "")
            {
                VRTracker.instance.serverIp = Network.player.ipAddress;
                VRTracker.instance.sendServerIP(VRTracker.instance.serverIp);
                NetworkManager.singleton.serverBindAddress = VRTracker.instance.serverIp;
                #if UNITY_EDITOR || UNITY_STANDALONE
                Debug.LogWarning("Unity Editor");
                #endif

                if (VRTracker.instance.isSpectator)
                {
                    Debug.Log("Starting as Server");
                    NetworkManager.singleton.StartServer();
                }
                else
                {
                    Debug.Log("Starting as Host");
                    NetworkManager.singleton.StartHost();
                }
            }
            else
            {
                Debug.Log("Starting client");
                NetworkManager.singleton.networkAddress = VRTracker.instance.serverIp;
                NetworkManager.singleton.StartClient();

                NetworkManager.singleton.serverBindAddress = VRTracker.instance.serverIp;
                NetworkManager.singleton.serverBindToIP    = true;
                NetworkManager.singleton.networkAddress    = VRTracker.instance.serverIp;

                Debug.Log("Server Ip " + NetworkManager.singleton.serverBindAddress);
                Debug.Log("Server Port " + NetworkManager.singleton.networkPort);
                //after binding address, start server
                NetworkManager.singleton.StartClient();
            }
        }
        private IEnumerator Start()
        {
            m_Reticle.Show();
            //m_Radial.Hide ();

            DontDestroyOnLoad(VRTracker.instance);
            Debug.Log("Instance is spectator :  " + VRTracker.instance.isSpectator);
            bool assignationSuccess = false;

            if (VRTracker.instance.autoAssignation)
            {
                /*
                 * Debug.Log("Loading association");
                 * VRTrackerTagAssociation.instance.LoadAssociation();*/
                Debug.Log("Loading association");
                if (VRTrackerTagAssociation.instance.LoadAssociation())
                {
                    /*for (int i = 0; i < 3 && !VRTracker.instance.assignationComplete; i++)
                     * {
                     *  if (VRTrackerTagAssociation.instance.TryAutoAssignTag())
                     *  {
                     *      assignationSuccess = true;
                     *      break;
                     *  }
                     *
                     *  yield return new WaitForSeconds(1);
                     * }*/
                    assignationSuccess = VRTrackerTagAssociation.instance.TryAutoAssignTag();
                    if (!assignationSuccess)
                    {
                        m_SliderCroup.hideSkipAssignationSlider();
                    }
                    else
                    {
                        //TODO: Load next level directly
                        Debug.Log("Tags where associated from file successfully");
                        //LevelLoader.instance.LoadLevel(1);
                    }
                }
            }

            /*
             * if (!VRTrackerTagAssociation.instance.isAssociationLoaded)
             * {
             *  Debug.LogWarning("hide auto assingation");
             *  m_SliderCroup.hideSkipAssignationSlider();
             * }
             *
             *
             * //Retrieve the player prefab from the network manager
             * GameObject pPrefab = null;
             * if (VRTrackerNetwork.instance.playerPrefab != null)
             * {
             *  pPrefab = VRTrackerNetwork.instance.playerPrefab;
             * }
             * else
             * {
             *  Debug.Log("Player prefab is null");
             * }
             * //Create and prepare the different prefab for assignation in the next scene
             * if (pPrefab != null) {
             *                  VRTrackerTag[] playerObject = pPrefab.GetComponentsInChildren<VRTrackerTag>();
             *                  for (int i = 0; i < playerObject.Length; i++) {
             *                          //Store the different player prefab name for association
             *                          VRTrackerAssociation newAsso = new VRTrackerAssociation();
             *      VRTrackerTagAssociation.instance.AddPrefabAssociation(playerObject[i].gameObject.name, newAsso);
             *                  }
             * }
             * else
             * {
             *  Debug.LogError("No player prefab set !");
             * }
             *
             *          if (VRTracker.instance.autoAssignation)
             *          {
             *  yield return new WaitForSeconds(1);
             *                  VRTracker.instance.AssignDirectlyTags();
             *  if (!VRTracker.instance.assignationComplete)
             *  {
             *      m_SliderCroup.hideSkipAssignationSlider();
             *  }
             * }
             */
                        #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
            VRTracker.instance.isSpectator = false;
            Debug.Log("Setting spectator mode to  :  " + VRTracker.instance.isSpectator);
                        #endif

            if (!VRTracker.instance.isSpectator)
            {
                m_SliderCroup.hideSpectatorMode();
                Debug.Log("Setting spectator mode to  :  " + VRTracker.instance.isSpectator);
            }
            else
            {
                //VRTracker.instance.assignationComplete = true;
            }
            Debug.Log("Instance is spectator :  " + VRTracker.instance.isSpectator);


            // In order, fade in the UI on confirming the use of sliders, wait for the slider to be filled, then fade out the UI.
            if (!assignationSuccess)
            {
                yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeIn()));

                //yield return StartCoroutine(m_SliderCroup.WaitForBarsToFill());
                yield return(StartCoroutine(m_SliderCroup.WaitForBarsToFill()));

                yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeOut()));
            }


            // Assign a Tag to each Prefab instance containing a Tag in VR Tracker
            if (!assignationSuccess && !VRTracker.instance.isSpectator)
            {
                Debug.Log("Manual assignement ");
                //Assignement step
                foreach (VRTrackerTag tag in VRTracker.instance.tags)
                //foreach (KeyValuePair<string, VRTrackerAssociation> prefab in VRTrackerTagAssociation.instance.prefabAssociation)
                {
                    Debug.Log("Assigning Tag to " + tag);

                    bool associationFailed = true;
                    while (associationFailed)
                    {
                        // Edit shown title to the Prefab name

                        /*m_AssociationFader.transform.Find("CalibrationInstructions/Title").GetComponentInChildren<Text>().text = "Assign" + prefab.Key;
                         *
                         *
                         * // Start assignation
                         * yield return StartCoroutine(ShowMenu(m_AssociationFader, prefab.Value));
                         *
                         *                      // Check if timed out and throw an error
                         *                      if (!prefab.Value.isIDAssigned)
                         *                      {
                         *                              associationFailed = true;
                         *                              yield return StartCoroutine(ShowMenu(m_FailedCalibrationFader, m_FailedCalibrationSlider));
                         *                      }
                         *                      else
                         *                      {
                         *                              associationFailed = false;
                         *
                         *                      }
                         */

                        // Edit shown title to the Prefab name
                        m_AssociationFader.transform.Find("CalibrationInstructions/Title").GetComponentInChildren <Text>().text = "Assign " + tag.tagType.ToString();

                        // Start assignation
                        yield return(StartCoroutine(ShowMenu(m_AssociationFader, tag)));

                        // Check if timed out and throw an error
                        if (!tag.IDisAssigned)
                        {
                            associationFailed = true;
                            yield return(StartCoroutine(ShowMenu(m_FailedCalibrationFader, m_FailedCalibrationSlider)));
                        }
                        else
                        {
                            associationFailed = false;
                            tag.AssignTag(tag.UID);
                        }
                    }
                }
            }

            if (!VRTracker.instance.isSpectator)
            {
                VRTracker.instance.SaveAssociationTagUser();
                enablePlayerCameraForNextLevel();
            }
            // Load the next Level (the Game !)
            yield return(StartCoroutine(m_LoadingFader.InteruptAndFadeIn()));

            //LevelLoader.instance.LoadLevel(1);
            Debug.Log("Network Address : " + Network.player.ipAddress);
            if (VRTracker.instance.serverIp == "" || VRTracker.instance.serverIp == Network.player.ipAddress)
            {
                VRTracker.instance.serverIp = Network.player.ipAddress;
                VRTracker.instance.sendServerIP(VRTracker.instance.serverIp);
                VRTrackerNetwork.instance.serverBindAddress = VRTracker.instance.serverIp;

                if (VRTracker.instance.isSpectator)
                {
                    Debug.Log("Starting as Server");
                    VRTrackerNetwork.instance.StartServer();
                }
                else
                {
                    Debug.Log("Starting as Host");
                    VRTrackerNetwork.instance.StartHost();
                }
            }
            else
            {
                Debug.Log("Starting client");
                //VRTrackerNetwork.instance.networkAddress = VRTracker.instance.serverIp;
                //VRTrackerNetwork.instance.StartClient ();

                VRTrackerNetwork.instance.serverBindAddress = VRTracker.instance.serverIp;
                VRTrackerNetwork.instance.serverBindToIP    = true;
                VRTrackerNetwork.instance.networkAddress    = VRTracker.instance.serverIp;

                Debug.Log("Server Ip " + VRTrackerNetwork.instance.serverBindAddress);
                Debug.Log("Server Port " + VRTrackerNetwork.instance.networkPort);
                //after binding address, start server
                VRTrackerNetwork.instance.StartClient();
            }
        }