Advertisement
shadowplaycoding

P022_SolarSystem

Jun 29th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.95 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class SolarSystem : MonoBehaviour {
  6.  
  7.     public static SolarSystem SolarSystemInstance;
  8.  
  9.     public Button galaxyViewButton;
  10.     public Button buildShipButton;
  11.  
  12.     public Vector3 starPosition { get; set; }
  13.  
  14.     public GameObject OrbitSpritePrefab;
  15.  
  16.     FleetManager fleetManager;
  17.  
  18.     public float solarSystemZoom = 100;
  19.     float storeMaxZoom = 0;
  20.  
  21.     public Material starOwnedMaterial;
  22.     public Material planetColonisedMaterial;
  23.  
  24.     void OnEnable()
  25.     {
  26.         SolarSystemInstance = this;
  27.         galaxyViewButton.interactable = false;
  28.         buildShipButton.interactable = false;
  29.  
  30.         fleetManager = GameObject.Find("Fleets").GetComponent<FleetManager>();
  31.     }
  32.  
  33.     // Use this for initialization
  34.     void Start () {
  35.    
  36.     }
  37.    
  38.     // Update is called once per frame
  39.     void Update () {
  40.  
  41.         Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
  42.         RaycastHit hit = new RaycastHit();
  43.  
  44.         if (Physics.Raycast(mouseRay, out hit))
  45.         {
  46.             Galaxy.GalaxyInstance.MoveSelectionIcon(hit);
  47.  
  48.             if (Input.GetMouseButtonDown(0) && Galaxy.GalaxyInstance.galaxyView == true)
  49.             {
  50.                 Star star = Galaxy.GalaxyInstance.ReturnStarFromGameObject(hit.transform.gameObject);
  51.                 starPosition = hit.transform.position;
  52.                 Debug.Log("This Star is Called: " + star.starName + "\n" + "It Has " + star.numberOfPlanets + " Planets");
  53.  
  54.                 Galaxy.GalaxyInstance.DestroyGalaxy();
  55.                 CreateSolarSystem(star);
  56.             }
  57.         }
  58.         else
  59.         {
  60.             Galaxy.GalaxyInstance.selectionIcon.SetActive(false);
  61.         }
  62.  
  63.     }
  64.  
  65.     // This method creates the solar system view after a star is clicked on in the galaxy view
  66.     public void CreateSolarSystem(Star star)
  67.     {
  68.         CameraController.cameraController.ResetCamera();
  69.  
  70.         Galaxy.GalaxyInstance.selectionIcon.SetActive(false);
  71.  
  72.         Random.InitState(Galaxy.GalaxyInstance.seedNumber);
  73.  
  74.         Galaxy.GalaxyInstance.galaxyView = false;
  75.  
  76.         GameObject starGO = SpaceObjects.CreateSphereObject(star.starName, Vector3.zero, this.transform);
  77.  
  78.         if (star.starOwned == true)
  79.         {
  80.             starGO.GetComponent<MeshRenderer>().material = starOwnedMaterial;
  81.         }
  82.  
  83.         for (int i = 0; i < star.planetList.Count; i++)
  84.         {
  85.             Planet planet = star.planetList[i];
  86.  
  87.             Vector3 planetPos = PositionMath.PlanetPosition(i);
  88.  
  89.             GameObject planetGO = SpaceObjects.CreateSphereObject(planet.planetName, planetPos, this.transform);
  90.  
  91.             if (planet.planetColonised == true)
  92.             {
  93.                 planetGO.GetComponent<MeshRenderer>().material = planetColonisedMaterial;
  94.             }
  95.  
  96.             GameObject orbit = SpaceObjects.CreateOrbitPath(OrbitSpritePrefab, planet.planetName + " Orbit", i + 1, this.transform);
  97.         }
  98.  
  99.         galaxyViewButton.interactable = true;
  100.         buildShipButton.interactable = true;
  101.  
  102.         storeMaxZoom = CameraController.cameraController.maxZoom;
  103.         CameraController.cameraController.maxZoom = solarSystemZoom;
  104.  
  105.         fleetManager.EnableFleets();
  106.  
  107.     }
  108.  
  109.     public void DestroySolarSystem()
  110.     {
  111.         while (transform.childCount > 0)
  112.         {
  113.             Transform go = transform.GetChild(0);
  114.             go.SetParent(null);
  115.             Destroy(go.gameObject);
  116.         }
  117.  
  118.         CameraController.cameraController.MoveTo(starPosition);
  119.         galaxyViewButton.interactable = false;
  120.         buildShipButton.interactable = false;
  121.  
  122.         CameraController.cameraController.maxZoom = storeMaxZoom;
  123.  
  124.         GUIManagementScript.GUIManagerInstance.namePlates.Clear();
  125.  
  126.     }
  127.  
  128.     /*
  129.    Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  130.    Removing this comment forfits any rights given to the user under licensing.
  131.    */
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement