|
@@ -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
|
|
|
{
|