111 lines
3.8 KiB
C#
111 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GalaxyUI : MonoBehaviour
|
|
{
|
|
|
|
public GameObject galaxyPrefab; // Prefab des Galaxy-Objekts
|
|
int numberOfGalaxies = GameUI.PlayersNumber; // Anzahl der zu erstellenden Galaxien
|
|
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];
|
|
|
|
public float Industry;
|
|
public float Wealth;
|
|
public float Science;
|
|
public float Food;
|
|
public float MilitaryPower;
|
|
public float Population;
|
|
public float ActualFood;
|
|
public Text[] texts; // Array der Text-Objekte
|
|
private float[] Array = new float[7];
|
|
|
|
void Start()
|
|
{
|
|
Vector3 centerPosition = canvas.transform.position; // Position des Hauptobjekts
|
|
|
|
for (int i = 0; i < numberOfGalaxies; i++)
|
|
{
|
|
// Erzeuge ein neues GameObject aus dem Prefab
|
|
SolarSystems[i] = Instantiate(galaxyPrefab);
|
|
|
|
// Setze das Canvas als Elternobjekt
|
|
SolarSystems[i].transform.SetParent(canvas.transform, false);
|
|
|
|
// Berechne den Winkel basierend auf der Anzahl der Galaxien
|
|
float angle = i * (360f / numberOfGalaxies);
|
|
|
|
// Berechne die Position basierend auf dem Winkel und dem Abstand vom Zentrum
|
|
float xPos = centerPosition.x + (distanceFromCenter * 3) * Mathf.Cos(Mathf.Deg2Rad * angle);
|
|
float yPos = centerPosition.y + distanceFromCenter * Mathf.Sin(Mathf.Deg2Rad * angle);
|
|
|
|
// Setze die Position des Galaxy-Objekts
|
|
SolarSystemPositions[i] = new Vector3(xPos, yPos, centerPosition.z);
|
|
SolarSystems[i].transform.position = new Vector3(xPos, yPos, centerPosition.z);
|
|
}
|
|
}
|
|
|
|
public void HidetSolarSystems()
|
|
{
|
|
for (int i = 0; i < numberOfGalaxies; i++)
|
|
{
|
|
SolarSystems[i].transform.position = new Vector3(10000, 0, 0);
|
|
}
|
|
}
|
|
|
|
public void ResetSolarSystemPositions()
|
|
{
|
|
for (int i = 0; i < numberOfGalaxies; i++)
|
|
{
|
|
SolarSystems[i].transform.position = new Vector3(SolarSystemPositions[i].x, SolarSystemPositions[i].y, SolarSystemPositions[i].z);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Array[0] = Industry;
|
|
Array[1] = Wealth;
|
|
Array[2] = Science;
|
|
Array[3] = Food;
|
|
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];
|
|
|
|
if (temp / 1000000 >= 1)
|
|
{
|
|
temp /= 1000000;
|
|
texts[i].text = ((int)temp).ToString() + " M";
|
|
}
|
|
else if (temp / 1000 >= 1)
|
|
{
|
|
temp /= 1000;
|
|
texts[i].text = ((int)temp).ToString() + " K";
|
|
}
|
|
else
|
|
{
|
|
texts[i].text = Array[i].ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|