Example #1
0
        /// <summary>
        /// コメントのuGUI表示用関数
        /// </summary>
        /// <param name="comment">Comment.</param>
        public void CommentUpdate(CommentParts comment)
        {
            GameObject go = Instantiate(commentPrefab);

            go.transform.SetParent(contentParent.transform);
            go.GetComponent <Comment>().SetComment(comment, particleList);

            queue.Enqueue(go);

            this.CommentDequeue();

            //スクロールビューの一番下に強制移動
            scrollRect.verticalNormalizedPosition = 0;
        }
Example #2
0
        /// <summary>
        /// youtubeライブのコメント表示
        /// </summary>
        /// <param name="comment">Comment.</param>
        public void SetComment(CommentParts comment, List <CommentParticle> particleList)
        {
            foreach (var particle in particleList)
            {
                if (particle.func(comment.displayMessage))
                {
                    particle.action();
                }
            }

            //uGUIのScaleを明示して大きさを固定
            this.gameObject.transform.localScale = Vector3.one;

            this.displayName.text    = comment.displayName;
            this.displayMessage.text = comment.displayMessage;
        }
Example #3
0
        /// <summary>
        /// Youtubeライブのコメントを取得するコルーチン
        /// </summary>
        /// <returns>The comment.</returns>
        private IEnumerator GetComment()
        {
            //コルーチンが2つ以上にならないように止める
            StopCoroutine(this.InvokeWait());

            var commentURI = youtubeAPIbase + chatURIUp + chatId + pagetoken + nextPageTokenstr + chatURIbottom2 + apikey;

            Debug.Log("CommentURI : " + commentURI);

            UnityWebRequest connectCommentRequest = UnityWebRequest.Get(commentURI);

            yield return(connectCommentRequest.SendWebRequest());

            if (connectCommentRequest.isHttpError || connectCommentRequest.isNetworkError)
            {
                Debug.LogError(connectCommentRequest.error);
            }
            else
            {
                string[] jsonData = connectCommentRequest.downloadHandler.text.Split(splitString, StringSplitOptions.None);

                CommentParts comment = new CommentParts();
                foreach (var json in jsonData)
                {
                    StringFormatter.TextOutput(json);
                    if (json.IndexOf("nextPageToken") > 0)
                    {
                        string newToken = StringFormatter.GetFormattedString(deleteString, json);

                        Debug.Log("newToken : " + newToken);
                        Debug.Log("nextPageTokenstr : " + nextPageTokenstr);
                        if (nextPageTokenstr == newToken)
                        {
                            Debug.Log("Same Token.");
                        }
                        else
                        {
                            nextPageTokenstr = newToken;
                            Debug.Log("Change Token.");
                            continue;
                        }
                    }

                    if (json.IndexOf("displayMessage") > 0)
                    {
                        comment.displayMessage = StringFormatter.GetFormattedString(deleteString, json);
                        Debug.Log("displayMessage : " + comment.displayMessage);
                    }
                    if (json.IndexOf("displayName") > 0)
                    {
                        comment.displayName = StringFormatter.GetFormattedString(deleteString, json);
                        Debug.Log("displayName : " + comment.displayName);
                    }

                    if (comment.displayName != null && comment.displayMessage != null)
                    {
                        commentManager.GetComponent <CommentManager>().CommentUpdate(comment);
                        comment = new CommentParts();
                        yield return(null);
                    }
                }
                StartCoroutine(this.InvokeWait());
            }
        }