4 Commits 5fddb2e4b9 ... 574420529f

Author SHA1 Message Date
  lisa 574420529f Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/lisa.gasche/HoHCI-BikeSteering 2 years ago
  lisa 42e86f11e0 automated Coin Placement (untested) part 2 2 years ago
  lisa 244d913724 automated Coin Placement (untested) 2 years ago
  lisa 499dd9aa4c errors fixed 2 years ago

+ 8 - 0
Assets/Coin.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: cc9aacf25a3ec0244b59ad0d0b83146d
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 6 - 4
Assets/Coin/CoinCollection.cs

@@ -1,10 +1,13 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using Pools;
 
 public class CoinCollection : MonoBehaviour
 {
-    public GameObject coinPool;
+    public CoinPool coinPool;
+    public CoinCreation spawn;
+
     // Start is called before the first frame update
     void Start()
     {
@@ -14,9 +17,9 @@ public class CoinCollection : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-        
+
     }
-    
+
     //Keep count of collisions with player
     private void OnTriggerEnter(Collider other)
     {
@@ -27,7 +30,6 @@ public class CoinCollection : MonoBehaviour
             // Increase Hit Counter
             var bike = other.gameObject;
             bike.GetComponent<PlayerStats>().IncreaseCoinCounter();
-
             coinPool.ReturnToPool(gameObject);
         }
     }

+ 73 - 0
Assets/Coin/CoinCreation.cs

@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+using System.Linq;
+using JetBrains.Annotations;
+using Pools;
+using Roads;
+
+[Serializable]
+public struct RoutePoint
+{
+    //Point position
+    public string name;
+    public float x;
+    public float z;
+    public bool slalom;
+}
+
+public class CoinCreation : MonoBehaviour
+{
+    public int stepsize;
+    public CoinPool coinPool;
+    public List<RoutePoint> points = new List<RoutePoint>();
+    int pointIndex = 0;
+    private Vector3 coin_position;
+    private GameObject coin;
+
+    private void Start()
+    {
+        PlaceCoins();
+    }
+
+    public void PlaceCoins()
+    {
+        //Abstand zwischen den Coins berechnen
+
+        RoutePoint start_point = points[pointIndex];
+        start_point.x = start_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten 
+
+        pointIndex++;
+
+        RoutePoint end_point = points[pointIndex];
+        end_point.x = end_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
+
+        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;
+        }
+
+
+        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);
+        }
+    }
+}

+ 11 - 0
Assets/Coin/CoinCreation.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 82e8d665ae879914eb9366d6565125fb
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 28 - 0
Assets/Coin/CoinUpdate.cs

@@ -0,0 +1,28 @@
+using System.Collections;
+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)
+
+public class CoinUpdate : MonoBehaviour
+{
+    public CoinCreation coinCreator;
+
+    // Start is called before the first frame update
+    void Start()
+    {
+        coinCreator = GameObject.FindGameObjectWithTag("Route").GetComponent<CoinCreation>();
+    }
+
+    //Keep count of collisions with player
+    private void OnTriggerEnter(Collider other)
+    {
+        if (other.gameObject.CompareTag("bike"))
+        {
+            Debug.Log("New Coins Coming!");
+            coinCreator.PlaceCoins();
+        }
+    }
+}

+ 11 - 0
Assets/Coin/CoinUpdate.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 49ae0bf5cdc1fa349adc6dd13fcf63c5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

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


+ 61 - 0
Assets/Scripts/Pools/CoinPool.cs

@@ -0,0 +1,61 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+namespace Pools
+{
+    public class CoinPool : MonoBehaviour
+    {
+        public int initialSize = 10;
+        public int amountIncrease = 5;
+        public GameObject prefab;
+        private HashSet<GameObject> active;
+
+        private Queue<GameObject> inactive;
+
+        private void Awake()
+        {
+            active = new HashSet<GameObject>();
+            inactive = new Queue<GameObject>();
+            IncreasePool(initialSize);
+        }
+
+        private void IncreasePool(int amount)
+        {
+            for (var i = 0; i < amount; i++)
+            {
+                var item = Instantiate(prefab, transform);
+                item.SetActive(false);
+                inactive.Enqueue(item);
+            }
+        }
+
+
+        public GameObject GetItem()
+        {
+            GameObject item;
+            if (inactive.Count > 0)
+            {
+                item = inactive.Dequeue();
+            }
+            else
+            {
+                IncreasePool(amountIncrease);
+                item = inactive.Dequeue();
+            }
+
+            item.transform.SetPositionAndRotation(Vector3.zero, Quaternion.Euler(Vector3.zero));
+            item.SetActive(true);
+            active.Add(item);
+            return item;
+        }
+
+        public void ReturnToPool(GameObject item)
+        {
+            if (active.Remove(item))
+            {
+                item.SetActive(false);
+                inactive.Enqueue(item);
+            }
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Pools/CoinPool.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1be5f90cb5908824e97b8a762c04c3ba
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
ProjectSettings/TagManager.asset

@@ -12,6 +12,7 @@ TagManager:
   - street_uneven
   - HMDTracker
   - CoinPool
+  - Route
   layers:
   - Default
   - TransparentFX

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