コード例 #1
0
    public void AddComment(string from, string text)
    {
        commentN++;
        commentsNumber.text = "" + commentN;
        float height = 0;
        float last   = 0;

        foreach (SocialComment child in commentsContent.GetComponentsInChildren <SocialComment>(false))
        {
            RectTransform rctT = child.GetComponent <RectTransform>();
            height += rctT.sizeDelta.y;
            last    = rctT.sizeDelta.y;
        }

        GameObject    comment = Instantiate(commentPrefab, commentsContent, false);
        SocialComment sc      = comment.GetComponent <SocialComment>();

        sc.textPrefab = textTemplate;
        sc.SetAuthorAndComment(from, text);
        comment.transform.localScale    = new Vector3(1, 1, 1);
        commentsContent.sizeDelta       = new Vector2(commentsContent.sizeDelta.x, commentsContent.sizeDelta.y + last);
        comment.transform.localPosition = new Vector2(comment.transform.localPosition.x, comment.transform.localPosition.y - height);
        computer.AddTmpComment(comment);
    }