예제 #1
0
    public void CreatePostInMainPage(string npcName, Sprite post, string text, int time)
    {
        //instantiate new post object
        var newPost = Instantiate(PosturePostPrefabNew, new Vector3(0, 0, 0), Quaternion.identity);

        //set parent(probably a better way to do
        newPost.transform.SetParent(postParent.transform);
        newPost.transform.localScale = Vector3.one;

        //set entry time
        newPost.GetComponent <EntryTime>().time = time;

        //move to the first of the list
        postList.Add(newPost);
        FinalCameraController.resetPostOrder();

        //Get profile and image
        var profile = newPost.transform.Find("Profile").gameObject.GetComponent <Image>();

        var profileName = profile.gameObject.GetComponentInChildren <Text>();

        //change sprite to the right ins photo

        //get the post text
        newPost.transform.Find("Post").gameObject.GetComponent <Image>().sprite = post;
        var textList = newPost.transform.Find("Post").gameObject.GetComponentsInChildren <Text>();


        //create comments
        var newComment = Instantiate(commentPrefab, new Vector3(0, 0, 0), Quaternion.identity, newPost.transform.Find("Comments"));

        //set parent(probably a better way to do
//        newComment.transform.parent = toothpastePost.transform.Find("Comments");

        newComment.transform.localPosition = new Vector3(0f, 0f, 0);

        //get the text child
        var CommentText = newComment.GetComponentInChildren <TextMeshProUGUI>();

        //get the comment profile
        var ProfileImage = newComment.GetComponent <Image>();

//        //todo: comments need to appear after sometime
//        CommentText.text = "That RV looks amazing. I'm gonna get one for myself.";
//        ProfileImage.sprite = allProfile["nico"];

        //change the post text
        if (npcName == "nico")
        {
            profile.sprite   = allProfile["nico"];
            textList[0].text =
                "<b>Nico</b> " + text;
            textList[1].text = "Today";


            //set profile and user name in main page
            profileName.text = "Nico";
            //个位数为1
            //之前已经有三个p: 1, 11, 21
//            newPost.GetComponent<EntryTime>().time = time;
        }
        else if (npcName == "ojisan")
        {
            profile.sprite   = allProfile["ojisan"];
            textList[0].text =
                "<b>Ojisan</b> " + text;
            textList[1].text = "Today";

            //set profile and user name in main page
            profileName.text = "Alex";
        }
    }