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

222 lines
5.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SolarSystemManager : MonoBehaviour
{
public GameObject[] objectsToDeactivate;
public GameObject[] objectsToActivate;
public GameObject[] Planets;
public int Industry;
public int Wealth;
public int Science;
public int Food;
public int MilitaryPower;
public int Population;
public int ActualFood;
public GameObject canvas; // Referenz auf das Canvas-Objekt
public Text[] texts; // Array der Text-Objekte
private int[] Array = new int[7];
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < objectsToDeactivate.Length; i++)
{
objectsToDeactivate[i].SetActive(false); // deactivate the game object
}
for (int i = 0; i < objectsToActivate.Length; i++)
{
objectsToActivate[i].SetActive(true); // activate the game object
}
Array[0] = Industry;
Array[1] = Wealth;
Array[2] = Science;
Array[3] = Food;
Array[4] = MilitaryPower;
Array[5] = Population;
Array[6] = ActualFood;
}
public void SetPositionCenter()
{
transform.position = canvas.transform.position; // Position des Hauptobjekts
}
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 < 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();
}
}
}
// Get Methodes, so it will search in all the planets in the solar system to get recours
public int GetFood(int id)
{
int food = 0;
if (Planets != null) {
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
food += Planets[i].GetComponent<PlanetUI>().food;
}
}
}
return food;
}
public int GetScience(int id)
{
int science = 0;
if (Planets != null) {
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
science += Planets[i].GetComponent<PlanetUI>().science;
}
}
}
return science;
}
public int GetPower(int id)
{
int power = 0;
if (Planets != null) {
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
power += Planets[i].GetComponent<PlanetUI>().power;
}
}
}
return power;
}
public int GetMoney(int id)
{
int money = 0;
if (Planets != null) {
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
money += Planets[i].GetComponent<PlanetUI>().money;
}
}
}
return money;
}
public int GetIndustrialCapacity(int id)
{
int industrialCapacity = 0;
if (Planets != null) {
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
industrialCapacity += Planets[i].GetComponent<PlanetUI>().industrialCapacity;
}
}
}
return industrialCapacity;
}
public int GetPopulation(int id)
{
int population = 0;
if (Planets != null)
{
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
population += Planets[i].GetComponent<PlanetUI>().population;
}
}
}
return population;
}
public int GetActualFood(int id)
{
int actualFood = 0;
if(Planets != null) {
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
actualFood += Planets[i].GetComponent<PlanetUI>().actualFood;
}
}
}
return actualFood;
}
public void UpdateFood(int id , int FoodLvlScience)
{
if (Planets != null)
{
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].GetComponent<PlanetUI>().PlayerID == id)
{
Planets[i].GetComponent<PlanetUI>().UpdateFood(FoodLvlScience);
}
}
}
}
public void SetIDPlanet(int PlayerID, int PlanetID)
{
Planets[PlanetID].GetComponent<PlanetUI>().PlayerID = PlayerID;
}
}