Browse Source

automated Coin-Placement works (adjustements for slalom needed)

lisa 2 years ago
parent
commit
9df13dd773

+ 6 - 9
Assets/Coin/CoinCollection.cs

@@ -1,12 +1,15 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System.Linq;
+using JetBrains.Annotations;
 using Pools;
 
+//Jeder Coin besitzt dieses Skript
+
 public class CoinCollection : MonoBehaviour
 {
-    public CoinPool coinPool;
-    public CoinCreation spawn;
+    private CoinPool coinPool;
 
     // Start is called before the first frame update
     void Start()
@@ -14,22 +17,16 @@ public class CoinCollection : MonoBehaviour
         coinPool = GameObject.FindGameObjectWithTag("CoinPool").GetComponent<CoinPool>();
     }
 
-    // Update is called once per frame
-    void Update()
-    {
-
-    }
-
     //Keep count of collisions with player
     private void OnTriggerEnter(Collider other)
     {
         Debug.Log("Coin Hit!");
         if (other.gameObject.CompareTag("bike"))
         {
-            Debug.Log("Collecting Coin");
             // Increase Hit Counter
             var bike = other.gameObject;
             bike.GetComponent<PlayerStats>().IncreaseCoinCounter();
+            //Returning Coin to Pool
             coinPool.ReturnToPool(gameObject);
         }
     }

+ 52 - 32
Assets/Coin/CoinCreation.cs

@@ -6,6 +6,7 @@ using JetBrains.Annotations;
 using Pools;
 using Roads;
 
+//Kreuzungen und Slalom-Referenzpunkte für die Route
 [Serializable]
 public struct RoutePoint
 {
@@ -18,60 +19,79 @@ public struct RoutePoint
 
 public class CoinCreation : MonoBehaviour
 {
-    public int stepsize;
+    public float stepsize = 10; //TODO welcher Wert ist hier passend?
     public CoinPool coinPool;
     public List<RoutePoint> points = new List<RoutePoint>();
     int pointIndex = 0;
     private Vector3 coin_position;
     private GameObject coin;
+    RoutePoint start_point;
+    RoutePoint end_point;
 
     private void Start()
     {
         PlaceCoins();
     }
 
-    int points_size = points.Count;
+    int points_size = 30; //needs to be changed if Route changes!
+
+
+    // Wird von CoinUpdate aufgerufen, das in jeder Kreuzung der Route enthalten ist
     public void PlaceCoins()
     {
         if ((pointIndex + 1) < points_size) // Check: sind noch mindestens 2 Punkte in der Liste?
         {
-            //Abstand zwischen den Coins berechnen
+            do
+            {
+                //Abstand zwischen den Coins berechnen (Orientiert an Tills-Code-Beispiel)
 
-            RoutePoint start_point = points[pointIndex];
-            start_point.x = start_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten 
+                start_point = points[pointIndex];
+                start_point.x = start_point.x + 190f; //190 = offset wegen relativen Kreuzungskoordinaten aus Hierachie
 
-            pointIndex++;
+                pointIndex++; //Index für nächsten Punkt aus Liste holen
 
-            RoutePoint end_point = points[pointIndex];
-            end_point.x = end_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
+                end_point = points[pointIndex];
+                end_point.x = end_point.x + 190f; //190 = offset wegen relativen Kreuzungskoordinaten aus Hierachie
 
-            float distance_x = System.Math.Abs(start_point.x - end_point.x);
-            float distance_z = System.Math.Abs(start_point.z - end_point.z);
+                float distance_x = System.Math.Abs(start_point.x - end_point.x);
+                float distance_z = System.Math.Abs(start_point.z - end_point.z);
 
-            float space_x = 0; //default
-            float space_z = 0; //default
-            if (distance_x > 0) // wenn entlang der x Richung verteilt wird
-            {
-                space_x = distance_x / stepsize;
-            }
-            if (distance_z > 0) // wenn entlang der z Richung verteilt wird
-            {
-                space_z = distance_z / stepsize;
-            }
+                float space_x = 0; //default
+                float space_z = 0; //default
 
+                if (start_point.slalom || (start_point.slalom && end_point.slalom))
+                {
+                    //TODO Was muss beim schiefen verteilen für den Slalom angepasst werden? z.B. stepsize?
+                    Debug.Log("Coin-Creation: Place Coins for Slalom.");
+                }
+                if (distance_x > 0) // wenn entlang der x Richung verteilt wird
+                {
+                    space_x = distance_x / stepsize;
+                    Debug.Log("Coin-Creation: Place Coins along x axis.");
+                }
+                if (distance_z > 0) // wenn entlang der z Richung verteilt wird
+                {
+                    space_z = distance_z / stepsize;
+                    Debug.Log("Coin-Creation: Place Coins along z axis.");
+                }
 
-            for (int i = 0; i > stepsize; ++i)
-            {
-                //position berechnen
-                coin_position.x = start_point.x + i * space_x;
-                coin_position.y = 0.5f;
-                coin_position.z = start_point.z + i * space_z;
-
-                //Coin erstellen
-                coin = coinPool.GetItem();
-                coin.transform.position = coin_position;
-                coin.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
-            }
+                for (int i = 0; i < stepsize; ++i)
+                {
+                    //Coin-Position berechnen
+                    coin_position.x = start_point.x + i * space_x;
+                    coin_position.y = 0.5f;
+                    coin_position.z = start_point.z + i * space_z;
+
+                    //Coin erstellen
+                    coin = coinPool.GetItem();
+                    coin.transform.position = coin_position;
+                    coin.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
+
+                    if (((i + 1) == stepsize) && (coin != null)) { Debug.Log("CoinCreation: Coin placement finished."); }
+                }
+
+            } while (end_point.slalom); //Da diese Funktion nur von Kreuzungen und nicht von Slalom-Referenzpunkten aufgerufen wird
+            // muss hier eine Schleife über die einzelnen Slalom-Abschnitte gemacht werden
         }
         else
         {

+ 1 - 3
Assets/Coin/CoinUpdate.cs

@@ -3,8 +3,7 @@ using System.Collections.Generic;
 using UnityEngine;
 using Pools;
 
-//Jede Kreuzung die eine Richtungsänderung der Route hervorruft braucht dieses Skript 
-//(jedoch nicht die slalom referenzpunkte)
+//Jede Kreuzung die eine Richtungsänderung der Route hervorruft braucht dieses Skript (jedoch nicht die Slalomreferenzpunkte)
 
 public class CoinUpdate : MonoBehaviour
 {
@@ -21,7 +20,6 @@ public class CoinUpdate : MonoBehaviour
     {
         if (other.gameObject.CompareTag("bike"))
         {
-            Debug.Log("New Coins Coming!");
             coinCreator.PlaceCoins();
         }
     }

File diff suppressed because it is too large
+ 300 - 505
Assets/Scenes/MainScene.unity


+ 2 - 1
Assets/Scripts/Pools/CoinPool.cs

@@ -5,7 +5,7 @@ namespace Pools
 {
     public class CoinPool : MonoBehaviour
     {
-        public int initialSize = 10;
+        public int initialSize = 100;
         public int amountIncrease = 5;
         public GameObject prefab;
         private HashSet<GameObject> active;
@@ -55,6 +55,7 @@ namespace Pools
             {
                 item.SetActive(false);
                 inactive.Enqueue(item);
+                Debug.Log("CoinPool: Coin returned to Pool :)");
             }
         }
     }

Some files were not shown because too many files changed in this diff