public void ProcessSpeechToTextSnippet(SpeechToTextSnippet newText)
        {
            if (GameStateManager.IsAlive)
            {
                if (!GameStateManager.Instance.isAssetImportFinished)
                {
                    return;
                }
            }

            if (!clientIDs.Contains(newText.target))
            {
                Debug.LogWarning("No client Found, Can't render text");
                return;
            }

            switch (newText.stringType)
            {
            case (int)STRINGTYPE.TUTORIAL:
                break;

            case (int)STRINGTYPE.SPEECH_TO_TEXT:
                //Get client index for text look up to use for displaying
                var    clientIndex = avatarIndexFromClientId[newText.target];
                string foo         = SplitWordsByLength(newText.text, maxWordsPerBubble);
                StartCoroutine(SetTextTimer(clientIndex, foo, secondsPerWord * Mathf.Log(newText.text.Length)));
                break;

            case (int)STRINGTYPE.CLIENT_NAME:

                clientIndex = avatarIndexFromClientId[newText.target];
                clientUsernameDisplays[clientIndex].text = newText.text;
                break;
            }
        }
        public void AddNewClient(int clientID, bool isMainPlayer = false)
        {
            if (clientID == NetworkUpdateHandler.Instance.client_id && !isMainPlayer)
            {
                Debug.LogError($"AddNewClient was requested for own client ID ({clientID}) when isMainPlayer was false. Skipping.");

                return;
            }

            if (GameStateManager.IsAlive && !GameStateManager.Instance.isAvatarLoadingFinished)
            {
                return;
            }

            //setup newclient
            if (clientIDs.Contains(clientID))
            {
                return;
            }

            clientIDs.Add(clientID);

            string nameLabel = NetworkUpdateHandler.Instance.GetPlayerNameFromClientID(clientID);

            if (clientIDs.Count >= clientReserveCount)
            {
                Debug.LogWarning("REACHED MAX CLIENTS IN GAME - ADD TO CLIENT RESERVE COUNT FOR MORE USERS");

                return;
            }

            //go through all available slots
            for (int i = 0; i < clientReserveCount - 1; i++)
            {
                //skip avatars that are already on, and your reserved spot
                if (gameObjects[i].activeInHierarchy || mainClientIndex == i)
                {
                    continue;
                }

                AvatarEntityGroup avatarEntityGroup = gameObjects[i].GetComponentInChildren <AvatarEntityGroup>();
                avatarEntityGroup.clientID = clientID;

                // entityManager.AddComponentData(avatarEntityGroup.rootEntity, new NetworkEntityIdentificationComponentData {clientID = clientID });

                if (!avatarEntityGroupFromClientId.ContainsKey(clientID))
                {
                    avatarEntityGroupFromClientId.Add(clientID, avatarEntityGroup);
                }
                else
                {
                    avatarEntityGroupFromClientId[clientID] = avatarEntityGroup;
                }

                if (!avatarIndexFromClientId.ContainsKey(clientID))
                {
                    avatarIndexFromClientId.Add(clientID, i);
                }
                else
                {
                    avatarIndexFromClientId[clientID] = i;
                }

                if (!usernameFromClientId.ContainsKey(clientID))
                {
                    usernameFromClientId.Add(clientID, nameLabel);
                }
                else
                {
                    usernameFromClientId[clientID] = nameLabel;
                }

                //create main ui tag
                if (!UIManager.IsAlive)
                {
                    Debug.LogWarning("AddNewClient: UIManager.IsAlive was false");
                }
                else
                {
                    UIManager.Instance.clientTagSetup.CreateTextFromString(nameLabel, clientID);
                }

                //select how to handle avatars
                if (isMainPlayer)
                {
                    gameObjects[i].SetActive(false);

                    mainClientIndex = i;

                    var temp = avatarEntityGroupFromClientId[clientID].transform;

                    var ROT = entityManager.GetComponentData <Rotation>(avatarEntityGroupFromClientId[clientID].rootEntity).Value.value;//.entity_data.rot;

                    //To prevent offset issues when working with editor
#if UNITY_WEBGL && !UNITY_EDITOR || TESTING_BEFORE_BUILDING
                    mainPlayer.transform.position = temp.position;

                    mainPlayer.transform.rotation = new Quaternion(ROT.x, ROT.y, ROT.z, ROT.w);

                    handsParent.transform.position = temp.position;

                    handsParent.transform.rotation = new Quaternion(ROT.x, ROT.y, ROT.z, ROT.w);
#endif
                    //Turn Off Dummy
                    var parObject = temp.parent.parent.gameObject;

                    parObject.name = "Main_Client";
                }
                else
                {
                    gameObjects[i].SetActive(true);

                    //setAnimatorReferences what I use to reference other peoples hands
                    int idForLeftHand  = (clientID * 100) + (2);
                    int idForRightHand = (clientID * 100) + (3);

                    if (!animatorFromClientId.ContainsKey(idForLeftHand))
                    {
                        animatorFromClientId.Add(idForLeftHand, avatarEntityGroupFromClientId[clientID].avatarComponent_hand_L.GetComponent <Animator>());
                        animatorFromClientId.Add(idForRightHand, avatarEntityGroupFromClientId[clientID].avatarComponent_hand_R.GetComponent <Animator>());
                    }
                    else
                    {
                        animatorFromClientId[idForLeftHand]  = avatarEntityGroupFromClientId[clientID].avatarComponent_hand_L.GetComponent <Animator>();
                        animatorFromClientId[idForRightHand] = avatarEntityGroupFromClientId[clientID].avatarComponent_hand_R.GetComponent <Animator>();
                    }

                    //set text label
                    SpeechToTextSnippet newText = new SpeechToTextSnippet
                    {
                        stringType = (int)STRINGTYPE.CLIENT_NAME,
                        target     = clientID,//clientIDToAvatarIndex[clientID],
                        text       = nameLabel,
                    };

                    ProcessSpeechToTextSnippet(newText);
                }
                break;
            }
        }
        public void AddNewClient2(int clientID)
        {
            if (GameStateManager.IsAlive && !GameStateManager.Instance.isAvatarLoadingFinished)
            {
                return;
            }

            //setup newclient
            if (clientIDs.Contains(clientID))
            {
                return;
            }

            clientIDs.Add(clientID);

            string nameLabel = NetworkUpdateHandler.Instance.GetPlayerNameFromClientID(clientID);

            // Skip avatars that are already on, and your own client's spot. We need this loop because
            // if someone in the middle of the list disconnected, we should reuse their avatar index.
            for (int i = 0; i < clientReserveCount; i += 1)
            {
                if (!gameObjects[i].activeInHierarchy && mainClientIndex != i)
                {
                    nextAvailableSlot = i;

                    break;
                }
            }

            InitializeAvatar(clientID);

            if (!usernameFromClientId.ContainsKey(clientID))
            {
                usernameFromClientId.Add(clientID, nameLabel);
            }
            else
            {
                usernameFromClientId[clientID] = nameLabel;
            }

            DisplayClientIsConnected(nameLabel, clientID);

            gameObjects[nextAvailableSlot].SetActive(true);

            //setAnimatorReferences what I use to reference other peoples hands
            int idForLeftHand  = (clientID * 100) + (2);
            int idForRightHand = (clientID * 100) + (3);

            if (!animatorFromClientId.ContainsKey(idForLeftHand))
            {
                animatorFromClientId.Add(idForLeftHand, avatarEntityGroupFromClientId[clientID].avatarComponent_hand_L.GetComponent <Animator>());
                animatorFromClientId.Add(idForRightHand, avatarEntityGroupFromClientId[clientID].avatarComponent_hand_R.GetComponent <Animator>());
            }
            else
            {
                animatorFromClientId[idForLeftHand]  = avatarEntityGroupFromClientId[clientID].avatarComponent_hand_L.GetComponent <Animator>();
                animatorFromClientId[idForRightHand] = avatarEntityGroupFromClientId[clientID].avatarComponent_hand_R.GetComponent <Animator>();
            }

            //set text label
            SpeechToTextSnippet newText = new SpeechToTextSnippet
            {
                stringType = (int)STRINGTYPE.CLIENT_NAME,
                target     = clientID,//clientIDToAvatarIndex[clientID],
                text       = nameLabel,
            };

            ProcessSpeechToTextSnippet(newText);

            nextAvailableSlot += 1;
        }