using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Assets.Scripts { public class QuestLog : MonoBehaviour { public Dictionary> quests; public GameObject content; public Scrollbar scrollBar; System.Random rand = new System.Random(); public GameObject quest; public Texture finished; public GameObject uiHandler; // Start is called before the first frame update void Start() { quests = new Dictionary>(); quests.Add("main", new List()); GameObject newQuest = Instantiate(quest); newQuest.transform.SetParent(content.transform, false); FindQuest main = new FindQuest(newQuest); main.generateCityQuest(); quests["main"].Add(main); for (int i = 0; i < 20; i++) { addQuest(); } } // Update is called once per frame void Update() { } public void updateQuests(string key, object obj, int amount) { foreach (Quest quest in quests[key]) { quest.update(obj, amount); } } public void addQuest() { GameObject newQuest = Instantiate(quest); newQuest.transform.SetParent(content.transform, false); int index = rand.Next(4); string type = ""; Quest questItem; switch (index) { case 0: type = "collect"; questItem = new CollectQuest(newQuest); break; case 1: type = "kill"; questItem = new KillQuest(newQuest); break; case 2: type = "find"; questItem = new FindQuest(newQuest); break; /*case 3: type = "craft"; break;*/ case 3: type = "explore"; questItem = new ExploreQuest(newQuest); break; default: questItem = new Quest(newQuest); break; } if (!quests.ContainsKey(type)) { quests.Add(type, new List()); } quests[type].Add(questItem); } public void showQuests() { content.GetComponent().sizeDelta = new Vector2(0, 10); float y = -37.5f; foreach (string key in quests.Keys) { foreach (Quest quest in quests[key]) { quest.show(y); y = y - 75; content.GetComponent().sizeDelta = new Vector2(0, content.GetComponent().sizeDelta.y + 75); } } scrollBar.value = 0; content.transform.localPosition = new Vector3(0,0,0); } } }