/// <summary>
        /// We create our plantes from json data provided and add orbit script to each object
        /// </summary>
        /// <param name="creationData"></param>
        public void CreatePlanets(SolarSystemContainer creationData)
        {
            List <GameObject> planet = new List <GameObject>();

            var planetData = creationData.SolarSystem.Planets;

            for (int i = 0; i < planetData.Count; i++)
            {
                planet.Add(GameObject.CreatePrimitive(PrimitiveType.Sphere));

                planet[i].gameObject.transform.position = Vector3.forward * (planetData[i].distanceFromSun);

                planet[i].gameObject.name = planetData[i].name.ToString();

                planet[i].GetComponent <Renderer>().material.color = Utils.Parse(planetData[i].colour);

                planet[i].AddComponent <Orbit>();

                planet[i].GetComponent <Orbit>().orbitVelcityRatio = planetData[i].earthOrbitalVelocityRatio * 50;

                planet[i].GetComponent <Orbit>().rotationRate = Utils.rotationRange;

                planet[i].GetComponent <Orbit>().radius = planetData[i].earthSizeRatio * 100;
            }
            AssignPlanetMaterials(planet);
        }
        private void Start()
        {
            creationData = new SolarSystemContainer();

            dataLoader = GetComponentInChildren <DataLoader>();

            dataLoader.Initialise(creationData);
        }
        /// <summary>
        /// Method of type solar system container to proecss data
        /// </summary>
        /// <param name="systemCreatorData"></param>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        public SolarSystemContainer ProcessJsonData(SolarSystemContainer systemCreatorData, string jsonData)
        {
            systemCreatorData = JsonUtility.FromJson <SolarSystemContainer>(jsonData);

            systemCreator.Initialise(systemCreatorData);

            cameraController.Initialise(systemCreatorData);

            return(systemCreatorData);
        }
        /// <summary>
        /// Method loads data from url
        /// </summary>
        /// <param name="systemCreatorData"></param>
        /// <returns></returns>
        IEnumerator LoadResourceData(SolarSystemContainer systemCreatorData)
        {
            WWW www = new WWW(Utils.dataURL);

            yield return(www);

            try
            {
                if (www.error == null)
                {
                    ProcessJsonData(systemCreatorData, www.text);
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Error: Failed to load data from URL " + ex);
            }
            finally
            {
                www.Dispose();
            }
        }
        /// <summary>
        /// Mehtod to create instance of sun & assign its attributes
        /// </summary>
        /// <param name="creator"></param>
        public void CreateSun(SolarSystemContainer creationData)
        {
            var sunData = creationData.SolarSystem.Star;

            GameObject sun = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sun.gameObject.name = sunData.name.ToString();

            sun.gameObject.GetComponent <Renderer>().material.color = Utils.Parse(sunData.colour);

            sun.GetComponent <Renderer>().material = Resources.Load(Utils.sunMaterial) as Material;

            sun.gameObject.transform.localScale = Vector3.one * sunData.earthSizeRatio;

            sun.AddComponent <Orbit>();

            sun.GetComponent <Orbit>().orbitVelcityRatio = 0;

            sun.GetComponent <Orbit>().rotationRate = Utils.sunRotation;

            sun.GetComponent <Orbit>().radius = 0;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Method instantiates camera and assigns the positoin and rotation
        /// </summary>
        /// <param name="creationData"></param>
        private void CreateCameras(SolarSystemContainer creationData)
        {
            var cameraPositions = creationData.SolarSystem.CameraPos;

            for (int i = 0; i < cameraPositions.Count; i++)
            {
                Quaternion rotations = Quaternion.Euler(cameraPositions[i].Rotation);

                cameraList.Add(Instantiate(camera, cameraPositions[i].Position, rotations));

                cameraList[i].transform.parent = transform.parent;

                for (int x = 0; x < cameraList.Count; x++)
                {
                    cameraList[i].gameObject.SetActive(false);
                }

                if (cameraList.Count > 0)
                {
                    cameraList[0].gameObject.SetActive(true);
                }
            }
        }
 public void Initialise(SolarSystemContainer creationData)
 {
     StartCoroutine("LoadResourceData", creationData);
 }
Ejemplo n.º 8
0
 public void Initialise(SolarSystemContainer creationData)
 {
     CreateCameras(creationData);
 }
        /// <summary>
        /// Method to initialise creation of celestial objects
        /// </summary>
        /// <param name="creationData"></param>
        public void Initialise(SolarSystemContainer creationData)
        {
            CreateSun(creationData);

            CreatePlanets(creationData);
        }