From ee7c1900a58b65946c3caf4d3b6d9a6f20b23dd0 Mon Sep 17 00:00:00 2001
From: meyerm1w <moritz.meyerhof@ruhr-uni-bochum.de>
Date: Sun, 18 Apr 2021 20:23:27 +0200
Subject: [PATCH] Added Tutorial Buttons and Controller

---
 Assets/Scenes/Tutorial.unity                  |  4 ++
 .../Scripts/UI/TutorialMessageController.cs   | 51 ++++++++++++++++---
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/Assets/Scenes/Tutorial.unity b/Assets/Scenes/Tutorial.unity
index d769246..0885ad1 100644
--- a/Assets/Scenes/Tutorial.unity
+++ b/Assets/Scenes/Tutorial.unity
@@ -681,6 +681,10 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: eff84c8212b521146a3b1f923794e0eb, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  keyTut: []
+  messagesTut: []
+  posMessages: []
+  textPrefab: {fileID: 0}
 --- !u!1001 &141107558
 PrefabInstance:
   m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/UI/TutorialMessageController.cs b/Assets/Scripts/UI/TutorialMessageController.cs
index 00b7edf..929249e 100644
--- a/Assets/Scripts/UI/TutorialMessageController.cs
+++ b/Assets/Scripts/UI/TutorialMessageController.cs
@@ -1,18 +1,57 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using UnityEngine.UI;
+
+struct TutorialObject
+{
+    public TutorialObject(string message, Vector2 vector2)
+    {
+        tutorialMessage = message;
+        messagePosition = vector2;
+    }
+
+    public string tutorialMessage;
+    public Vector2 messagePosition;
+}
 
 public class TutorialMessageController : MonoBehaviour
 {
-    // Start is called before the first frame update
-    void Start()
+    [SerializeField] List<string> keyTut;
+    [SerializeField] List<string> messagesTut;
+    [SerializeField] List<Vector2> posMessages;
+
+    [SerializeField] GameObject textPrefab;
+    GameObject activeMessage = null;
+    Dictionary<string, TutorialObject> messages = new Dictionary<string, TutorialObject>();
+
+    GameObject canvas;
+
+    private void Awake()
     {
-        
+        canvas = GetComponent<Canvas>().gameObject;
+
+        //create Dict with Structs
+        for (int i = 0; i < keyTut.Count; i++)
+        {
+            messages.Add(keyTut[i],new TutorialObject(messagesTut[i],posMessages[i]));
+        }
     }
 
-    // Update is called once per frame
-    void Update()
+    public void ActivateTutorial(string tutorialType)
     {
-        
+        if ( activeMessage != null)
+        {
+            Destroy(activeMessage);
+        }
+        if ( tutorialType == "return")
+        {
+            SceneLoader.instance.LoadScene("Forest");
+            return;
+        }
+        TutorialObject activePair = messages[tutorialType];
+        GameObject temp = Instantiate(textPrefab,activePair.messagePosition,Quaternion.identity, canvas.transform);
+        temp.GetComponent<Text>().text = activePair.tutorialMessage;
     }
+
 }
-- 
GitLab