private List <Post> GeneratePosts(ScenarioEnding type) { var selectedPosts = new List <Post>(4); var neutralPosts = 2; var topScenarioCount = 2; var typePosts = posts.Where(post => post.Type == type).ToList(); // Load the two top scenarios var topScenarios = manager.TopScenarios(topScenarioCount); if (topScenarios.Count < topScenarioCount) { neutralPosts += topScenarioCount - topScenarios.Count; } foreach (var scenario in topScenarios) { // Load all posts registered to this scenario var scenarioPostList = typePosts.Where(post => post.scenario == scenario).ToList(); // If there are any, select one random one to return if (scenarioPostList.Count > 0) { selectedPosts.Add(scenarioPostList[UnityEngine.Random.Range(0, scenarioPostList.Count - 1)]); } // If there are none, tell to load one extra post from neutral else { neutralPosts++; } } // Select all neutral posts, i.e. the posts that do not belong to the top 2 scenarios // var neutralPostList = posts.Where(post => !topScenarios.Contains(post.scenario)).ToList(); // FIXME This messes up (might be fixed 2020-03-26) var neutralPostList = typePosts.Where(post => !selectedPosts.Contains(post)).ToList(); // If there are not enough posts to pool from, just return as many as possible if (neutralPosts > neutralPostList.Count) { neutralPosts = neutralPostList.Count; } // If there are no posts left to pool from, simply skip the rest and return if (neutralPosts == 0) { return(selectedPosts); } // Generate random indexes var randIndexes = Random.UniqueIntegers(0, neutralPostList.Count, neutralPosts); // Select posts to return based on the indexes selectedPosts.AddRange(randIndexes.Select(i => neutralPostList[i])); return(selectedPosts); }
private void CreateButtons(ScenarioEnding ending) { var posts = GameManager.Instance.PostPool.GetPosts(ending); // Instantiate the four buttons foreach (var t in posts) { var button = Instantiate(buttonPrefab, buttonGroup, false); // Assign a post to each button // Technically not necessary as this can also be implicitly assigned in the listener on the next line button.Post = t; // Assign a listener to this button that will set this post as the selected post button.ButtonComponent.onClick.AddListener(() => SelectedPost = button.Post); buttons.Add(button); } }
public List <Post> GetPosts(ScenarioEnding scenario) { return(nextPosts[scenario]); }
private static string ToDisplayName(this ScenarioEnding s) { return(Regex.Replace(s.ToString(), @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0")); }
public string GetEndingMessage(ScenarioEnding ending) { return(endingMessages[(int)ending]); }
public BackgroundObject GetEndBackground(ScenarioEnding ending) { return(endBackgrounds[(int)ending]); }
public BackgroundObject GetMidwayBackground(ScenarioEnding ending) { return(midwayBackgrounds[(int)ending]); }