123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Linq;
- using JetBrains.Annotations;
- using Pools;
- using Roads;
- //Kreuzungen und Slalom-Referenzpunkte für die Route
- [Serializable]
- public struct RoutePoint
- {
- //Point position
- public string name;
- public float x;
- public float z;
- public bool slalom;
- }
- public class CoinCreation : MonoBehaviour
- {
- 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 = 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?
- {
- do
- {
- //Abstand zwischen den Coins berechnen (Orientiert an Tills-Code-Beispiel)
- start_point = points[pointIndex];
- start_point.x = start_point.x + 190f; //190 = offset wegen relativen Kreuzungskoordinaten aus Hierachie
- pointIndex++; //Index für nächsten Punkt aus Liste holen
- 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 space_x = 0; //default
- float space_z = 0; //default
- Vector3 rotationVector = new Vector3(0f, 0f, 0f);
- 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.");
- /*
- space_x = distance_x / stepsize;
- space_z = distance_z / stepsize;
- rotationVector = new Vector3(0f, 90f, 90f);
- */
- }
- 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.");
- rotationVector = new Vector3(0f, 0f, 90f);
- }
- 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.");
- rotationVector = new Vector3(0f, 90f, 90f);
- }
- for (int i = 0; i < stepsize; ++i)
- {
- //Coin-Position berechnen
- if (start_point.x - end_point.x > 0)
- {
- coin_position.x = start_point.x - i * space_x;
- }
- if (start_point.x - end_point.x <= 0)
- {
- coin_position.x = start_point.x + i * space_x;
- }
- if (start_point.z - end_point.z > 0)
- {
- coin_position.z = start_point.z - i * space_z;
- }
- if (start_point.z - end_point.z <= 0)
- {
- coin_position.z = start_point.z + i * space_z;
- }
- coin_position.y = 0.5f;
- //Coin erstellen
- coin = coinPool.GetItem();
- coin.transform.position = coin_position;
- coin.transform.rotation = Quaternion.Euler(rotationVector);
- 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
- {
- Debug.Log("The End of the Route is near, so no new coins needed!");
- }
- }
- }
|