Advertisement
shadowplaycoding

P030_GUIManagementScript

Jul 20th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class GUIManagementScript : MonoBehaviour {
  7.  
  8.     public static GUIManagementScript GUIManagerInstance;
  9.  
  10.     public List<GameObject> namePlates;
  11.  
  12.     public GameObject planetPanel;
  13.     public GameObject starBasePanel;
  14.  
  15.     GameObject content;
  16.  
  17.     void OnEnable()
  18.     {
  19.         GUIManagerInstance = this;
  20.         namePlates = new List<GameObject>();
  21.     }
  22.  
  23.     void Awake()
  24.     {
  25.         content = starBasePanel.GetComponentInChildren<VerticalLayoutGroup>().gameObject;
  26.     }
  27.  
  28.     // Use this for initialization
  29.     void Start () {
  30.        
  31.     }
  32.    
  33.     // Update is called once per frame
  34.     void Update () {
  35.  
  36.         if(namePlates.Count > 0)
  37.         {
  38.             if (CameraController.cameraController.zoomLevel < 0.4)
  39.             {
  40.                 for (int i = 0; i < namePlates.Count; i++)
  41.                 {
  42.                     namePlates[i].transform.LookAt(Camera.main.transform);
  43.                     float rotY = namePlates[i].transform.localEulerAngles.y + 180f;
  44.                     namePlates[i].transform.localEulerAngles = new Vector3(
  45.                         -namePlates[i].transform.localEulerAngles.x,
  46.                         rotY,
  47.                         -namePlates[i].transform.localEulerAngles.z);
  48.                 }
  49.             }
  50.         }
  51.  
  52.     }
  53.  
  54.     public void UpdateShipProductionUI()
  55.     {
  56.         Planet planet = SolarSystem.SolarSystemInstance.currentPlanet;
  57.  
  58.         Debug.Log(planet);
  59.  
  60.         float totalProduction = 0;
  61.  
  62.         //Debug.ClearDeveloperConsole();
  63.  
  64.         if (planet.production > 0)
  65.         {
  66.             for (int i = 0; i < content.transform.childCount; i++)
  67.             {
  68.                 Text[] texts = content.transform.GetChild(i).GetComponentsInChildren<Text>();
  69.  
  70.                 Ship ship = planet.starBase.buildCue[i];
  71.  
  72.                 int numberOfTurns = Mathf.CeilToInt(((ship.productionValue - planet.starBase.currentProduction) + totalProduction) / planet.production);
  73.  
  74.                 texts[texts.Length - 1].text = numberOfTurns.ToString();
  75.  
  76.                 totalProduction += ship.productionValue;
  77.             }
  78.         }
  79.     }
  80.  
  81.     public void RemoveButtonFromCue()
  82.     {
  83.         Transform topButton = content.transform.GetChild(0);
  84.         topButton.transform.SetParent(null);
  85.         Destroy(topButton.gameObject); 
  86.     }
  87.  
  88.     /*
  89.     Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  90.     Removing this comment forfits any rights given to the user under licensing.
  91.     */
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement