public override void OnScreenEnter() { base.OnScreenEnter(); // Find references scrollViewContent = transform.Find("Scroll View/Viewport/Content").gameObject; IGPost.postPrefab = scrollViewContent.transform.Find("tpl_ig_post").gameObject; // Give posts a ref back to the controller IGPost.controller = this; // Hide post template IGPost.postPrefab.SetActive(false); /* * Seed initial posts */ posts = new List <IGPost>(); for (lastPost = 0; lastPost < INITIAL_POST_NUM; lastPost++) { IGPost post = makeRandomPost(lastPost); posts.Add(post); attachPost(post); } }
public void postClicked(IGPost post) { // TODO: Better score system if (post.Score == 1) { AddScore(100); numGood += 1; FindObjectOfType <feedbackOnMouse>().PunchPositiveFeedback("+++ Social"); } else { SubstractScore(50); numGood -= 1; FindObjectOfType <feedbackOnMouse>().PunchPositiveFeedback("--- Social"); } //attachPost(makeRandomPost(++lastPost)); if (numGood >= NUM_TO_WIN) { exitMinigame(); } }
public static IGPost make(int number, string username, int likes, string text, Sprite image, Sprite avatar, int score) { GameObject go = Instantiate(postPrefab, new Vector3(0, 0, 0), Quaternion.identity); IGPost post = go.GetComponent <IGPost>(); post.likeBtn = go.transform.Find("btn_like").GetComponent <Button>(); post.Number = number; post.Username = username; post.Likes = likes; post.Text = text; post.Image = image; post.Avatar = avatar; post.Score = score; // We're cloning from a hidden template, so make yourself visible go.SetActive(true); // Update values post.update(); return(post); }
public IGPost makeRandomPost(int number) { bool good = Random.Range(0, 3) < 2; return(IGPost.make(number, pickRandom(good ? usernames_good : usernames_bad), Random.Range(0, 99999999), pickRandom(texts), pickRandom(images), pickRandom(avatars), good ? +1 : -1)); }
void attachPost(IGPost post) { post.gameObject.transform.SetParent(scrollViewContent.transform, false); scrollViewContent.GetComponent <RectTransform>().sizeDelta = scrollViewContent.GetComponent <RectTransform>().sizeDelta + new Vector2(0, IGPost.HEIGHT); }