Added first steps to new questing system, v1.4.0
This commit is contained in:
96
Assets/Scripts/QuestLog.cs
Normal file
96
Assets/Scripts/QuestLog.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class QuestLog : MonoBehaviour
|
||||
{
|
||||
public Dictionary<string, List<Quest>> 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<string, List<Quest>>();
|
||||
quests.Add("main", new List<Quest>());
|
||||
GameObject newQuest = Instantiate(quest);
|
||||
newQuest.transform.SetParent(content.transform, false);
|
||||
quests["main"].Add(new Quest("main", newQuest));
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
addQuest();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void updateQuests()
|
||||
{
|
||||
foreach (string key in quests.Keys)
|
||||
{
|
||||
foreach (Quest quest in quests[key])
|
||||
{
|
||||
quest.update(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addQuest()
|
||||
{
|
||||
int index = rand.Next(4);
|
||||
string type = "";
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
type = "collect";
|
||||
break;
|
||||
case 1:
|
||||
type = "find";
|
||||
break;
|
||||
case 2:
|
||||
type = "kill";
|
||||
break;
|
||||
case 3:
|
||||
type = "craft";
|
||||
break;
|
||||
}
|
||||
if (!quests.ContainsKey(type))
|
||||
{
|
||||
quests.Add(type, new List<Quest>());
|
||||
}
|
||||
GameObject newQuest = Instantiate(quest);
|
||||
newQuest.transform.SetParent(content.transform, false);
|
||||
quests[type].Add(new Quest(type, newQuest));
|
||||
}
|
||||
|
||||
public void showQuests()
|
||||
{
|
||||
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 10);
|
||||
updateQuests();
|
||||
float y = -37.5f;
|
||||
foreach (string key in quests.Keys)
|
||||
{
|
||||
foreach (Quest quest in quests[key])
|
||||
{
|
||||
quest.show(y);
|
||||
y = y - 75;
|
||||
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, content.GetComponent<RectTransform>().sizeDelta.y + 75);
|
||||
}
|
||||
}
|
||||
scrollBar.value = 0;
|
||||
content.transform.localPosition = new Vector3(0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user