Browse Source

Playback with functions DONE

Furkan Karakocaoglu 1 year ago
parent
commit
f52e4806e1

+ 5 - 0
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/General/PlaybackController.cs

@@ -54,4 +54,9 @@ public class PlaybackController : MonoBehaviour
             }
         }
     }
+    
+    public void OnValueChanged(float value)
+    {
+        // This Method is not needed, bc the value is taken from the slider directly.
+    }
 }

+ 6 - 1
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/ReadWrite/ReadFromCSV.cs

@@ -24,7 +24,12 @@ public class ReadFromCSV : MonoBehaviour
         }
     }
 
-    //Reads from csv files
+    /// <summary>
+    /// Reads from the given path the csv file
+    /// </summary>
+    /// <param name="path">The path were the csv file is located</param>
+    /// <returns>A matrix of tuples with the following order in the tuple: time; Position; Rotation; Speed</returns>
+    /// <exception cref="ApplicationException"></exception>
     public Tuple<List<float>, List<Vector3>, List<Quaternion>, List<float>>[][] ReadFromCSVFile(string path)
     {
         if(!File.Exists(path)) return null;

+ 68 - 3
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/WanderingAI/WalkLerpPlayback.cs

@@ -1,4 +1,5 @@
 using UnityEngine;
+using UnityEngine.UI;
 using UnityEngine.AI;
 using System.Collections.Generic;
 using System.IO;
@@ -23,10 +24,15 @@ public class WalkLerpPlayback : MonoBehaviour
     private Animator[][] humansA;
 
     // Playback variables
+    private int[] maxIJ;
     private int indexChangeRate;
     [HideInInspector]
     public bool rewind, pause, play; //PlaybackController
 
+    // Slider Settings
+    public Slider slider;
+    private float prevSliderValue;
+
     private void Start()
     {
         // Get information from InstatiatePrefab
@@ -55,8 +61,22 @@ public class WalkLerpPlayback : MonoBehaviour
             }
         }
 
+        // Set the Slider settings
+        if (slider == null)
+        {
+            Debug.Log("No Slider instance attached");
+            return;
+        }
+        maxIJ = GetHumanWithLongestScreenTime();
+        float maxTime = (float) Math.Round(timePosRotList[maxIJ[0]][maxIJ[1]].Item1[timePosRotList[maxIJ[0]][maxIJ[1]].Item1.Count - 1], 2);
+        slider.minValue = 0;
+        slider.maxValue =  (maxTime / Time.deltaTime);
+        slider.wholeNumbers = true;
+        prevSliderValue = slider.value;
+        
         SetTransform(currentStartPoint);
         currentStartPoint++;
+        slider.value = currentStartPoint;
         startTime = Time.time;
     }
 
@@ -68,21 +88,45 @@ public class WalkLerpPlayback : MonoBehaviour
             indexChangeRate = 1;
         if (rewind)
             indexChangeRate = -1;
-   
+
         if (play || rewind)
         {
-            if ((currentStartPoint + indexChangeRate) < timePosRotList[0][0].Item2.Count && (currentStartPoint + indexChangeRate) >= 0)
+            if ((currentStartPoint + indexChangeRate) < timePosRotList[maxIJ[0]][maxIJ[1]].Item2.Count && (currentStartPoint + indexChangeRate) >= 0)
             {
-                currentStartPoint += indexChangeRate;
+                if(slider.value - prevSliderValue == -1 || slider.value - prevSliderValue == 0 || slider.value - prevSliderValue == 1) // rewind || play
+                {
+                    prevSliderValue = slider.value;
+                    currentStartPoint += indexChangeRate;
+                    slider.value = currentStartPoint;
+                }
+                else
+                {
+                    prevSliderValue = slider.value;
+                    currentStartPoint = (int) slider.value;
+                }
                 SetTransform(currentStartPoint);
             }
+            else if(slider.value - prevSliderValue != -1|| slider.value - prevSliderValue != 0 || slider.value - prevSliderValue != 1)
+            {
+                currentStartPoint = (int) slider.value;
+            }
         }
         else
         {
+            // upper else-Statement only for pause
+            if (slider.value - prevSliderValue != 0)
+            {
+                //prevSliderValue = slider.value;
+                currentStartPoint = (int) slider.value;
+            }
+
             for (int i = 0; i < humansGO.Length; ++i)
             {
                 for (int j = 0; j < humansGO[i].Length; ++j)
                 {
+                    humansGO[i][j].transform.position = timePosRotList[i][j].Item2[currentStartPoint]; // First entry of Position
+                    humansGO[i][j].transform.rotation = timePosRotList[i][j].Item3[currentStartPoint]; // First entry of Rotation
+
                     humansA[i][j].SetBool("isWalking", false);
                 }
             }
@@ -128,4 +172,25 @@ public class WalkLerpPlayback : MonoBehaviour
             }
         }
     }
+
+    private int[] GetHumanWithLongestScreenTime()
+    {
+        int[] maxIJ = new int[2] { 0, 0 };
+        float currentMaxTime = 0;
+
+        for (int i = 0; i < humansGO.Length; ++i)
+        {
+            for (int j = 0; j < humansGO[i].Length; ++j)
+            {
+                if(currentMaxTime < timePosRotList[i][j].Item1.Count)
+                {
+                    currentMaxTime = timePosRotList[i][j].Item1.Count;
+                    maxIJ[0] = i;
+                    maxIJ[1] = j;
+                }
+            }
+        }
+                
+        return maxIJ;
+    }
 }

+ 22 - 8
testumgebung/CrowdModelling/Assets/Scenes/Origin_OnlyYears.unity

@@ -1000,7 +1000,7 @@ RectTransform:
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 1, y: 1}
   m_AnchoredPosition: {x: 0, y: 0}
-  m_SizeDelta: {x: -30, y: 0}
+  m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!1001 &123222036
 PrefabInstance:
@@ -3898,6 +3898,7 @@ MonoBehaviour:
   rewind: 0
   pause: 0
   play: 0
+  slider: {fileID: 0}
 --- !u!114 &421502122
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -10860,6 +10861,7 @@ MonoBehaviour:
   rewind: 0
   pause: 0
   play: 0
+  slider: {fileID: 0}
 --- !u!114 &946692992
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -15910,7 +15912,7 @@ MonoBehaviour:
     m_Right: 0
     m_Top: 0
     m_Bottom: 0
-  m_ChildAlignment: 0
+  m_ChildAlignment: 4
   m_Spacing: 0
   m_ChildForceExpandWidth: 1
   m_ChildForceExpandHeight: 1
@@ -17279,7 +17281,7 @@ GameObject:
   - component: {fileID: 1594303656}
   - component: {fileID: 1594303657}
   - component: {fileID: 1594303658}
-  m_Layer: 5
+  m_Layer: 16
   m_Name: Slider
   m_TagString: Untagged
   m_Icon: {fileID: 0}
@@ -17353,11 +17355,22 @@ MonoBehaviour:
   m_Direction: 0
   m_MinValue: 0
   m_MaxValue: 1
-  m_WholeNumbers: 0
+  m_WholeNumbers: 1
   m_Value: 0
   m_OnValueChanged:
     m_PersistentCalls:
-      m_Calls: []
+      m_Calls:
+      - m_Target: {fileID: 1295373006}
+        m_MethodName: OnValueChanged
+        m_Mode: 0
+        m_Arguments:
+          m_ObjectArgument: {fileID: 0}
+          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
+          m_IntArgument: 0
+          m_FloatArgument: 0
+          m_StringArgument: 
+          m_BoolArgument: 0
+        m_CallState: 2
 --- !u!95 &1594303657
 Animator:
   serializedVersion: 3
@@ -19798,7 +19811,7 @@ RectTransform:
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
   m_AnchoredPosition: {x: 0, y: 0}
-  m_SizeDelta: {x: 20, y: 0}
+  m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1774966633
 MonoBehaviour:
@@ -22423,6 +22436,7 @@ MonoBehaviour:
   rewind: 0
   pause: 0
   play: 0
+  slider: {fileID: 1594303656}
 --- !u!114 &2070248957
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -22849,8 +22863,8 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0.25}
   m_AnchorMax: {x: 1, y: 0.75}
-  m_AnchoredPosition: {x: -5, y: 0}
-  m_SizeDelta: {x: -30, y: 0}
+  m_AnchoredPosition: {x: 0, y: 0}
+  m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!1 &2136514433
 GameObject:

+ 1 - 1
testumgebung/CrowdModelling/ProjectSettings/TagManager.asset

@@ -24,7 +24,7 @@ TagManager:
   - Waypoint
   - Floor
   - MarketStall
-  - 
+  - Slider
   - 
   - 
   -