Galaxy Anpassen
This commit is contained in:
@@ -6,37 +6,39 @@ using UnityEngine.UI;
|
||||
public class GalaxyUI : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject galaxyPrefab; // Prefab des Galaxy-Objekts
|
||||
int numberOfGalaxies = GameUI.PlayersNumber; // Anzahl der zu erstellenden Galaxien
|
||||
|
||||
int numberOfSolarSystem; // Anzahl der zu erstellenden Solarsystem
|
||||
public float distanceFromCenter; // Abstand der Galaxien vom Hauptobjekt
|
||||
public GameObject canvas; // Referenz auf das Canvas-Objekt
|
||||
private GameObject[] SolarSystems = new GameObject[12];
|
||||
private Vector3[] SolarSystemPositions = new Vector3[12];
|
||||
|
||||
//private GameObject[] SolarSystems = new GameObject[12];
|
||||
private Vector3[] SolarSystemPositions;
|
||||
|
||||
|
||||
public float Industry;
|
||||
public float Wealth;
|
||||
public float Science;
|
||||
public float Food;
|
||||
public float MilitaryPower;
|
||||
public float Population;
|
||||
public float ActualFood;
|
||||
public int Industry;
|
||||
public int Wealth;
|
||||
public int Science;
|
||||
public int Food;
|
||||
public int MilitaryPower;
|
||||
public int Population;
|
||||
public int ActualFood;
|
||||
public Text[] texts; // Array der Text-Objekte
|
||||
private float[] Array = new float[7];
|
||||
private int[] Array = new int[7];
|
||||
|
||||
void Start()
|
||||
{
|
||||
numberOfSolarSystem = GameUI.PlayersNumber; // Anzahl der zu erstellenden Solarsystem
|
||||
SolarSystemPositions = new Vector3[numberOfSolarSystem];
|
||||
Vector3 centerPosition = canvas.transform.position; // Position des Hauptobjekts
|
||||
|
||||
for (int i = 0; i < numberOfGalaxies; i++)
|
||||
for (int i = 0; i < numberOfSolarSystem; i++)
|
||||
{
|
||||
// Erzeuge ein neues GameObject aus dem Prefab
|
||||
SolarSystems[i] = Instantiate(galaxyPrefab);
|
||||
|
||||
|
||||
// Setze das Canvas als Elternobjekt
|
||||
SolarSystems[i].transform.SetParent(canvas.transform, false);
|
||||
GameManager.SolarSystems[i].transform.SetParent(canvas.transform, false);
|
||||
|
||||
// Berechne den Winkel basierend auf der Anzahl der Galaxien
|
||||
float angle = i * (360f / numberOfGalaxies);
|
||||
float angle = i * (360f / numberOfSolarSystem);
|
||||
|
||||
// Berechne die Position basierend auf dem Winkel und dem Abstand vom Zentrum
|
||||
float xPos = centerPosition.x + (distanceFromCenter * 3) * Mathf.Cos(Mathf.Deg2Rad * angle);
|
||||
@@ -44,23 +46,23 @@ public class GalaxyUI : MonoBehaviour
|
||||
|
||||
// Setze die Position des Galaxy-Objekts
|
||||
SolarSystemPositions[i] = new Vector3(xPos, yPos, centerPosition.z);
|
||||
SolarSystems[i].transform.position = new Vector3(xPos, yPos, centerPosition.z);
|
||||
GameManager.SolarSystems[i].transform.position = new Vector3(xPos, yPos, centerPosition.z);
|
||||
}
|
||||
}
|
||||
|
||||
public void HidetSolarSystems()
|
||||
public void HideSolarSystems()
|
||||
{
|
||||
for (int i = 0; i < numberOfGalaxies; i++)
|
||||
for (int i = 0; i < numberOfSolarSystem; i++)
|
||||
{
|
||||
SolarSystems[i].transform.position = new Vector3(10000, 0, 0);
|
||||
GameManager.SolarSystems[i].transform.position = new Vector3(10000, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetSolarSystemPositions()
|
||||
{
|
||||
for (int i = 0; i < numberOfGalaxies; i++)
|
||||
for (int i = 0; i < numberOfSolarSystem; i++)
|
||||
{
|
||||
SolarSystems[i].transform.position = new Vector3(SolarSystemPositions[i].x, SolarSystemPositions[i].y, SolarSystemPositions[i].z);
|
||||
GameManager.SolarSystems[i].transform.position = new Vector3(SolarSystemPositions[i].x, SolarSystemPositions[i].y, SolarSystemPositions[i].z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +71,18 @@ public class GalaxyUI : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
|
||||
Industry = GameManager.playerManagers[0]._playerAttributes.industrialCapacity;
|
||||
Wealth = GameManager.playerManagers[0]._playerAttributes.money;
|
||||
Science = GameManager.playerManagers[0]._playerAttributes.science;
|
||||
Food = GameManager.playerManagers[0]._playerAttributes.food;
|
||||
MilitaryPower = GameManager.playerManagers[0]._playerAttributes.power;
|
||||
Population = GameManager.playerManagers[0]._playerAttributes.population;
|
||||
ActualFood = GameManager.playerManagers[0]._playerAttributes.actualFood;
|
||||
|
||||
|
||||
Array[0] = Industry;
|
||||
Array[1] = Wealth;
|
||||
Array[2] = Science;
|
||||
@@ -76,30 +90,19 @@ public class GalaxyUI : MonoBehaviour
|
||||
Array[4] = MilitaryPower;
|
||||
Array[5] = Population;
|
||||
Array[6] = ActualFood;
|
||||
for (int i = 0; i < numberOfGalaxies; i++)
|
||||
{
|
||||
Industry += SolarSystems[i].GetComponent<SolarSystemManager>().Industry;
|
||||
Wealth += SolarSystems[i].GetComponent<SolarSystemManager>().Wealth;
|
||||
Science += SolarSystems[i].GetComponent<SolarSystemManager>().Science;
|
||||
Food += SolarSystems[i].GetComponent<SolarSystemManager>().Food;
|
||||
MilitaryPower += SolarSystems[i].GetComponent<SolarSystemManager>().MilitaryPower;
|
||||
Population += SolarSystems[i].GetComponent<SolarSystemManager>().Population;
|
||||
ActualFood += SolarSystems[i].GetComponent<SolarSystemManager>().ActualFood;
|
||||
|
||||
}
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
float temp = Array[i];
|
||||
int temp = Array[i];
|
||||
|
||||
if (temp / 1000000 >= 1)
|
||||
{
|
||||
temp /= 1000000;
|
||||
texts[i].text = ((int)temp).ToString() + " M";
|
||||
texts[i].text = temp.ToString() + " M";
|
||||
}
|
||||
else if (temp / 1000 >= 1)
|
||||
{
|
||||
temp /= 1000;
|
||||
texts[i].text = ((int)temp).ToString() + " K";
|
||||
texts[i].text = temp.ToString() + " K";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user