From 399d0f56aaf19f57e16d9ab84d35055f7d45c6aa Mon Sep 17 00:00:00 2001
From: unknown <john.schihada@hotmail.com>
Date: Sat, 29 Feb 2020 18:18:29 +0100
Subject: [PATCH] Fixed typing-bug of TaskCharakter

---
 Assets/Graphics.meta                          |  8 ---
 .../Character_Animations/CharacterDialog.cs   | 60 +++++++++++++++----
 .../TaskCharakterAnimation.cs                 | 17 ++++++
 Assets/InventoryStuff/Inventory.meta          |  8 ---
 ...easant_01_e_Animator Controller.controller | 36 +----------
 Assets/Scenes.meta                            |  8 ---
 6 files changed, 69 insertions(+), 68 deletions(-)
 delete mode 100644 Assets/Graphics.meta
 delete mode 100644 Assets/InventoryStuff/Inventory.meta
 delete mode 100644 Assets/Scenes.meta

diff --git a/Assets/Graphics.meta b/Assets/Graphics.meta
deleted file mode 100644
index 2f27852d..00000000
--- a/Assets/Graphics.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: eec83b50c1e0c604aa91430f72c8dbb0
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 
diff --git a/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs b/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs
index 9007d687..928f988a 100644
--- a/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs
+++ b/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs
@@ -9,9 +9,12 @@ public class CharacterDialog : MonoBehaviour
     public TextMeshPro textDisplay;
     public TextMeshPro textHint;
     public string[] sentences;
-    private int index;
+    private int sentenceIndex;
+    private int letterIndex = 0;
+    private bool typingActive = false;
     //speed for typing the Text
     public float typingSpeed;
+    private float timer = 0;
 
     //Only reset once after Player is out of range of the TaskCharacter
     private bool textReseted = true;
@@ -23,12 +26,15 @@ void Start()
     {
         CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence);
         //Type first sentence
-        StartCoroutine(Type());
+        typingActive = true;
+        TypeFkt();
 
     }
 
     private void Update()
     {
+        TypeFkt();
+
         if(!pushoutSucceeded && Input.GetKeyDown(KeyCode.Return) && TaskCharakterAnimation.getPlayerInTalkingZone())
         {
             //Type Next sentence if player is in the talkinZone around the TaskCharacter AND the player typed the return-Key
@@ -43,20 +49,48 @@ private void Update()
 
     //Type a sentence slowly
     IEnumerator Type() {
-        foreach (char letter in sentences[index].ToCharArray()) {
+        foreach (char letter in sentences[sentenceIndex].ToCharArray()) {
             textDisplay.text += letter;
             yield return new WaitForSeconds(typingSpeed);
         }
     }
 
+    public void TypeFkt() {
+        if (typingActive)
+        {
+            if (this.timer >= this.typingSpeed)
+            {
+                if (letterIndex < sentences[sentenceIndex].Length)
+                {
+                    textDisplay.text += sentences[sentenceIndex].ToCharArray()[letterIndex];
+                    letterIndex++;
+                }
+                else
+                {
+                    this.typingActive = false;
+                    letterIndex = 0;
+                }
+
+                this.timer = 0;
+            }
+            else
+            {
+                this.timer += Time.deltaTime;
+            }
+        }
+    }
+
 
     public void NextSentence() {
         //-2 because the last sentence is only for SucceededPushout-Purposes
-        if (index < sentences.Length - 2)
+        if (sentenceIndex < sentences.Length - 2)
         {
-            index++;
+            sentenceIndex++;
+            letterIndex = 0;
+            typingActive = true;
+            timer = 0;
             textDisplay.text = "";
-            StartCoroutine(Type());
+            TypeFkt();
             textReseted = false;
         }
         else {
@@ -65,21 +99,27 @@ public void NextSentence() {
     }
 
     public void ResetSentence() {
-        index = 0;
+        sentenceIndex = 0;
+        letterIndex = 0;
+        typingActive = true;
+        timer = 0;
         textDisplay.text = "";
         //Type first sentence again
-        StartCoroutine(Type());
+        TypeFkt();
         textReseted = true;
     }
 
     public void PushoutSucceededSentence(Fact startFact) {
         textDisplay.text = "";
         //Last Sentence is the Pushout-Sentence
-        index = sentences.Length - 1;
+        sentenceIndex = sentences.Length - 1;
+        letterIndex = 0;
+        typingActive = true;
+        timer = 0;
         pushoutSucceeded = true;
         //Disable Hint With Enter-Key for Talking
         textHint.GetComponent<MeshRenderer>().enabled = false;
         //Type final message
-        StartCoroutine(Type());
+        TypeFkt();
     }
 }
diff --git a/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs b/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs
index de2542fe..0c3cec17 100644
--- a/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs
+++ b/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs
@@ -64,6 +64,11 @@ void Update()
         else {
             //disable enter-key for talking
             setPlayerInTalkingZone(false);
+            //Change to walking State after Talking Zone so that player can stay inside the radiusAroundObject
+            rotate = false;
+            this.timer = 0;
+            //Change boolean for switching to Walking-State in AnimationController
+            anim.SetBool("standing", false);
         }
 
         //Calculate distance from tree, so that the TaskCharacter only walks in a specific radius around the tree
@@ -142,6 +147,18 @@ public void stopHappy(Fact startFact) {
         //Set Variable in animationController to change the state
         anim.SetBool("solved", false);
         happy = false;
+        resetToStart();
+    }
+
+    public void resetToStart() {
+        //On Reset: Player must go into walking state, because it could be that after the happy/running-animation the player is 
+        //out of radius and rotates -> AnimationController StateMachine always changes into walking-state after hyppAnimation
+        walking = true;
+        standing = false;
+        rotate = true;
+        nextRotation = 0;
+        rotationUnits = 0;
+        playerInTalkingZone = false;
     }
 
     //Static Method for CharacterDialog
diff --git a/Assets/InventoryStuff/Inventory.meta b/Assets/InventoryStuff/Inventory.meta
deleted file mode 100644
index 9818e1d1..00000000
--- a/Assets/InventoryStuff/Inventory.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: b543d9677cbde534ab69c0a229bfdb06
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 
diff --git a/Assets/Polytope Studio/Lowpoly Medieval Characters/Sources/Animations/Anim_controllers/PT_Medieval_Peasant_01_e_Animator Controller.controller b/Assets/Polytope Studio/Lowpoly Medieval Characters/Sources/Animations/Anim_controllers/PT_Medieval_Peasant_01_e_Animator Controller.controller
index 8a86e008..cd62b77b 100644
--- a/Assets/Polytope Studio/Lowpoly Medieval Characters/Sources/Animations/Anim_controllers/PT_Medieval_Peasant_01_e_Animator Controller.controller	
+++ b/Assets/Polytope Studio/Lowpoly Medieval Characters/Sources/Animations/Anim_controllers/PT_Medieval_Peasant_01_e_Animator Controller.controller	
@@ -14,13 +14,13 @@ AnimatorController:
     m_DefaultFloat: 0
     m_DefaultInt: 0
     m_DefaultBool: 0
-    m_Controller: {fileID: 0}
+    m_Controller: {fileID: 9100000}
   - m_Name: solved
     m_Type: 4
     m_DefaultFloat: 0
     m_DefaultInt: 0
     m_DefaultBool: 0
-    m_Controller: {fileID: 0}
+    m_Controller: {fileID: 9100000}
   m_AnimatorLayers:
   - serializedVersion: 5
     m_Name: Base Layer
@@ -55,9 +55,6 @@ AnimatorStateTransition:
   m_PrefabAsset: {fileID: 0}
   m_Name: 
   m_Conditions:
-  - m_ConditionMode: 2
-    m_ConditionEvent: standing
-    m_EventTreshold: 0
   - m_ConditionMode: 2
     m_ConditionEvent: solved
     m_EventTreshold: 0
@@ -100,34 +97,6 @@ AnimatorStateTransition:
   m_InterruptionSource: 0
   m_OrderedInterruption: 1
   m_CanTransitionToSelf: 1
---- !u!1101 &1101526424927387364
-AnimatorStateTransition:
-  m_ObjectHideFlags: 1
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_Name: 
-  m_Conditions:
-  - m_ConditionMode: 1
-    m_ConditionEvent: standing
-    m_EventTreshold: 0
-  - m_ConditionMode: 2
-    m_ConditionEvent: solved
-    m_EventTreshold: 0
-  m_DstStateMachine: {fileID: 0}
-  m_DstState: {fileID: 1102119675311824806}
-  m_Solo: 0
-  m_Mute: 0
-  m_IsExit: 0
-  serializedVersion: 3
-  m_TransitionDuration: 0
-  m_TransitionOffset: 0
-  m_ExitTime: 3
-  m_HasExitTime: 0
-  m_HasFixedDuration: 1
-  m_InterruptionSource: 0
-  m_OrderedInterruption: 1
-  m_CanTransitionToSelf: 1
 --- !u!1101 &1101676305976220748
 AnimatorStateTransition:
   m_ObjectHideFlags: 1
@@ -271,7 +240,6 @@ AnimatorState:
   m_CycleOffset: 0
   m_Transitions:
   - {fileID: 1101065367606003302}
-  - {fileID: 1101526424927387364}
   m_StateMachineBehaviours: []
   m_Position: {x: 50, y: 50, z: 0}
   m_IKOnFeet: 0
diff --git a/Assets/Scenes.meta b/Assets/Scenes.meta
deleted file mode 100644
index 157e8818..00000000
--- a/Assets/Scenes.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: ac72be71662640f4ab0aaf102090fb95
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 
-- 
GitLab