Advertisement
shadowplaycoding

P014_SolarSystem

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