Advertisement
shadowplaycoding

P021_SolarSystem

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