Esempio n. 1
0
    public static SolarSystemData LoadSolarSystem(string filename)
    {
        string          json        = ReadFromResource(filename);
        SolarSystemData solarSystem = JsonUtility.FromJson <SolarSystemData>(json);

        return(solarSystem);
    }
Esempio n. 2
0
 public GalaxyData(Galaxy g)
 {
     solarSystems = new SolarSystemData[g.solarSystems.Count];
     for (int i = 0; i < g.solarSystems.Count; i++)
     {
         solarSystems[i] = new SolarSystemData(g.solarSystems[i]);
     }
 }
Esempio n. 3
0
    public static SolarSystem SetupSystemsFromGen(SolarSystemData data)
    {
        var sysGen = GameObject.FindObjectOfType <Generation_Solar_System>();


        var systemGet = sysGen.GetSystemFromGen((int)(data.posX), (int)(data.posY), data.generationSeed);


        return(systemGet);
    }
    public void VisitedSolarObjects(SolarSystemData obj)
    {
        if (!obj.visited)
        {
            solarSystemPassport.Add(obj);
            obj.visited = true;
        }

        void RemoveLastItem()
        {
            if (!solarSystemPassport.Contains(null))
            {
                solarSystemPassport.RemoveAt(solarSystemPassport.Count - 1);
            }
        }
    }
Esempio n. 5
0
//	Planet earth;
//	Moon moon;
//	Planet mercury;
//	Planet venus;
//	Planet mars;
//	Planet jupiter;
//	Planet saturnus;
//	Planet uranus;
//	Planet neptune;

//	Orbit earthOrbit;
//	Orbit moonOrbit;
//	Orbit mercuryOrbit;
//	Orbit venusOrbit;
//	Orbit marsOrbit;
//	Orbit saturnusOrbit;
//	Orbit jupiterOrbit;
//	Orbit uranusOrbit;
//	Orbit neptuneOrbit;

//	public Canvas canvas;
//	public GameObject planetTemplate;
//	public GameObject sunTemplate;
//	GameObject earthObj;
//	GameObject moonObj;
//	GameObject mercuryObj;
//	GameObject venusObj;
//	GameObject uranusObj;
//	GameObject neptuneObj;
//	GameObject marsObj;
//	GameObject saturnusObj;
//	GameObject jupiterObj;
//	GameObject sunObj;

    void Start()
    {
        Scaling.DistanceScale     = DistanceScale;
        Scaling.MoonDistanceScale = MoonDistanceScale;

        Scaling.UseLogScale       = UseLogScale;
        Scaling.LogBaseAxisLength = LogBaseAxisLength;
        Scaling.PlanetSizeScale   = PlanetSizeScale;
        Scaling.MoonToPlanetRatio = MoonToPlanetRatio;
        Scaling.SunSizeScale      = SunSizeScale;
        Scaling.SpeedUpFactor     = SpeedUpFactor;

        SolarSystemData data = DataProcessor.LoadSolarSystem("SolarSystem.json");

        solarSystem = new SolarSystem(data);
        solarSystem.Start();
    }
Esempio n. 6
0
        public SolarSystem(SolarSystemData data, Galaxy g)
        {
            Name  = data.name;
            Index = data.index;

            linkedSystemIndex = new List <int>();
            links             = new Dictionary <int, Link>();
            galaxy            = g;

            for (int i = 0; i < data.linkedSystems.Length; i++)
            {
                linkedSystemIndex.Add(data.linkedSystems[i]);
            }

            Position = new Vector3(data.position[0], data.position[1], data.position[2]);

            Render();
        }
Esempio n. 7
0
        public static SolarSystemData generateSolarSystemOn(vector2 workingPos)
        {
            SolarSystemData workingData = new SolarSystemData();

            workingData.position    = workingPos;
            workingData.name        = "Unnamed: " + workingPos.toString();
            workingData.planetCount = utils.getIntInRange(1, 12);
            workingData.objects     = new List <updateableObject>();
            workingData.sun         = new gameObjects.universeObjects.Sun(true, workingPos, '%', 3);

            for (int i = 0; i < workingData.planetCount; i++)
            {
                List <vector2> orbit    = utils.getOnRadius(workingPos.x, workingPos.y, i * 10);
                vector2        startPos = utils.RandomValueFromList(orbit);
                workingData.objects.Add(new gameObjects.universeObjects.Planet(true, startPos, 'O', workingData.sun, orbit));
            }

            return(workingData);
        }
Esempio n. 8
0
        public static List <SolarSystemData> generateSolarSystems(Universe universe, int maxSolarSystems)
        {
            List <SolarSystemData> systems = new List <SolarSystemData>();
            vector2 workingPos             = new vector2();

            for (int i = 0; i < maxSolarSystems; i++)
            {
                Console.Write("Generating Solar System: " + i + "-" + maxSolarSystems);
                List <vector2> goodPositions = utils.getOnRadius(workingPos.x, workingPos.y, universe.data.solarSystemMinDist);
                workingPos = goodPositions[utils.getIntInRange(0, goodPositions.Count)];

                List <vector2> betterPositions = new List <vector2>();
                for (int j = 0; j < goodPositions.Count; j++)
                {
                    bool isBetter = true;
                    for (int k = 0; k < systems.Count; k++)
                    {
                        if (goodPositions[j].dist(systems[k].position) < universe.data.solarSystemMinDist)
                        {
                            isBetter = false;
                            break;
                        }
                    }
                    if (isBetter)
                    {
                        betterPositions.Add(goodPositions[j]);
                    }
                }

                if (betterPositions.Count > 0)
                {
                    workingPos = betterPositions[utils.getIntInRange(0, betterPositions.Count)];
                }

                SolarSystemData workingData = generateSolarSystemOn(workingPos);

                Console.WriteLine(" @: " + workingPos.toString() + " size: " + workingData.sun.radius + " planetCount: " + workingData.planetCount);

                systems.Add(workingData);
            }

            return(systems);
        }
Esempio n. 9
0
    public SolarSystem(SolarSystemData Data)
    {
        Suns            = new Sun[Data.Suns.Length];
        OrbitingPlanets = new Planet[Data.Planets.Length];

        systemObj      = new GameObject();
        systemObj.name = Data.Name;
        systemObj.transform.position = Vector3.zero;
        systemObj.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);

        // Create Suns, Planets and their Moons
        for (int i = 0; i < Suns.Length; i++)
        {
            SunData sd  = Data.Suns[i];
            Sun     sun = new Sun(sd.Name, sd.Type, sd.Color, sd.Radius, sd.Mass, sd.Age, systemObj);
            sun.SetPosition(sd.Position);
            Suns[i] = sun;
        }
        for (int i = 0; i < OrbitingPlanets.Length; i++)
        {
            PlanetData pd    = Data.Planets[i];
            Orbit      orbit = Orbit.Create(pd.Apoapsis, pd.Periapsis, Suns[pd.OrbitingIndex]);
            systemLogScaleBase = systemLogScaleBase > Mathf.Log(orbit.SemiMajor) ? Mathf.Log(orbit.SemiMajor) : systemLogScaleBase;
            Debug.Log(pd.Name + " Orbit info, T: " + orbit.Period + " Apoapsis: " + orbit.ApoApsis + " Periapsis: " + orbit.PeriApsis);
            Planet planet = new Planet(pd.Name, pd.Type, pd.Color, pd.Radius, pd.Mass, orbit, Suns[pd.OrbitingIndex].GameObject);
            if (pd.Moons != null)
            {
                int nr = pd.Moons.Length;
                planet.Moons = new Moon[nr];
                for (int j = 0; j < nr; j++)
                {
                    MoonData md        = pd.Moons[j];
                    Orbit    moonOrbit = Orbit.Create(md.Apoapsis, md.Periapsis, planet);
                    planet.Moons[j] = new Moon(md.Name, md.Type, md.Color, md.Radius, md.Mass, moonOrbit, md.Approachable, planet.GameObject);
                }
            }
            OrbitingPlanets[i] = planet;
        }
        Scaling.LogBase  = Mathf.Floor(systemLogScaleBase);
        TimeAcceleration = Scaling.SpeedUpFactor;
        SetOrbitingPositions(0);
    }
Esempio n. 10
0
 /// <summary>
 /// Constructor
 /// </summary>
 public AngularDistances()
 {
     this.solarSystemData = SolarSystemData.GetInstance();
 }
Esempio n. 11
0
    //Returns false on fail
    public static bool GenGalaxy(GalaxyGenData data)
    {
        //Randomly choose star count
        Random.InitState(data.randSeed);
        int starCount = Random.Range(data.minStar, data.maxStar);

        //Generate based on shape
        List <Vector2> positions;

        switch (data.shape)
        {
        case GalaxyShape.Spiral:
            positions = GenSpiralGalaxy(starCount, data);
            break;

        case GalaxyShape.Elliptical:
            positions = GenEllipticalGalaxy(starCount, data);
            break;

        case GalaxyShape.Irregular:
            positions = GenIrregularGalaxy(starCount, data);
            break;

        case GalaxyShape.Ring:
            positions = GenRingGalaxy(starCount, data);
            break;

        default:
            positions = new List <Vector2>();
            break;
        }

        //Remove points that are too close
        RemoveTooClose(ref positions, data);

        //Name file to array of names
        string[] names = File.ReadAllLines(data.nameFileDir);

        //Take each position into a solar system class
        SolarSystemData[] solarSystems = new SolarSystemData[positions.Count];
        for (int i = 0; i < solarSystems.Length; i++)
        {
            solarSystems[i]                = new SolarSystemData();
            solarSystems[i].id             = i;
            solarSystems[i].generationSeed = data.randSeed;
            solarSystems[i].posX           = positions[i].x;
            solarSystems[i].posY           = positions[i].y;
            solarSystems[i].name           = names[Random.Range(0, names.Length)];
            solarSystems[i].size           = (SolarSystemSize)Random.Range(0, 2);
            solarSystems[i].type           = GenRandomType(data);
            solarSystems[i].linkedIDs      = new int[data.maxLinked];
        }

        //Setup links
        SetupLinks(ref solarSystems, data);

        //Link clusters if needed
        if (data.linkClusters)
        {
            List <List <int> > clusters = FindClusters(ref solarSystems, data);
            LinkClusters(ref solarSystems, clusters, data);
        }

        //Create galaxy
        Galaxy galaxy = new Galaxy();

        galaxy.randSeed         = data.randSeed;
        galaxy.solarSystems     = solarSystems;
        galaxy.generatedSystems = new SolarSystem[solarSystems.Length];
        for (int i = 0; i < galaxy.solarSystems.Length; i++)
        {
            galaxy.generatedSystems[i] = SetupSystemsFromGen(galaxy.solarSystems[i]);
        }

        //Save galaxy
        //if (!DataSerializer.CheckExistence(data.saveFileDir))
        DataSerializer.Save(galaxy, data.saveFileDir);
        //else
        //	return false;

        //Refresh assets
        AssetDatabase.Refresh();

        //Return success
        return(true);
    }