Files
project1_Space4x/Assets/GalaxyUI.cs
2023-07-02 14:25:11 +02:00

114 lines
3.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GalaxyUI : MonoBehaviour
{
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;
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 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 < numberOfSolarSystem; i++)
{
// Setze das Canvas als Elternobjekt
GameManager.SolarSystems[i].transform.SetParent(canvas.transform, false);
// Berechne den Winkel basierend auf der Anzahl der Galaxien
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);
float yPos = centerPosition.y + distanceFromCenter * Mathf.Sin(Mathf.Deg2Rad * angle);
// Setze die Position des Galaxy-Objekts
SolarSystemPositions[i] = new Vector3(xPos, yPos, centerPosition.z);
GameManager.SolarSystems[i].transform.position = new Vector3(xPos, yPos, centerPosition.z);
}
}
public void HideSolarSystems()
{
for (int i = 0; i < numberOfSolarSystem; i++)
{
GameManager.SolarSystems[i].transform.position = new Vector3(10000, 0, 0);
}
}
public void ResetSolarSystemPositions()
{
for (int i = 0; i < numberOfSolarSystem; i++)
{
GameManager.SolarSystems[i].transform.position = new Vector3(SolarSystemPositions[i].x, SolarSystemPositions[i].y, SolarSystemPositions[i].z);
}
}
// 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;
Array[3] = Food;
Array[4] = MilitaryPower;
Array[5] = Population;
Array[6] = ActualFood;
for (int i = 0; i < 7; i++)
{
int temp = Array[i];
if (temp / 1000000 >= 1)
{
temp /= 1000000;
texts[i].text = temp.ToString() + " M";
}
else if (temp / 1000 >= 1)
{
temp /= 1000;
texts[i].text = temp.ToString() + " K";
}
else
{
texts[i].text = Array[i].ToString();
}
}
}
}