コード例 #1
0
    public IEnumerator UpdateSolarObjects()
    {
        while (model.isActive)
        {
            for (int i = 0; i < model.solar.satelites.Count; i++)
            {
                SolarBody body     = model.solar.satelites[i];
                Vector3   position = (Vector2)body.GamePosition(game.data.date.time);

                Vector3 screenPoint = Camera.main.WorldToViewportPoint(position);
                bool    onScreen    = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;

                if (onScreen)
                {
                    var visible = CheckVisibility(body);

                    planets[i].SetActive(visible);

                    planets[i].transform.position = sun.transform.position + position;
                    //planets[i].transform.localScale = Vector3.one * (float)Mathd.Pow((body.bodyRadius), solarSpriteScale) * Mathf.Pow(game.localScaleMod, .9f);
                    planets[i].transform.localScale = sun.transform.localScale * .5f;

                    LineRenderer line = planets[i].GetComponent <LineRenderer>();

                    line.widthMultiplier = planets[i].transform.localScale.x * .3f;
                    yield return(null);
                }
            }

            for (int i = 0; i < moons.Count; i++)
            {
                SolarBody moon     = moonModels[i];
                Vector3   position = (Vector2)moon.GamePosition(game.data.date.time);
                position += model.solar.satelites[moon.solarIndex[1]].GamePosition(game.data.date.time);

                Vector3 screenPoint = Camera.main.WorldToViewportPoint(position);
                bool    onScreen    = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;

                if (onScreen)
                {
                    var visible = CheckVisibility(moon);
                    moons[i].SetActive(visible);
                    LineRenderer line = moons[i].GetComponent <LineRenderer>();

                    line.widthMultiplier = moons[i].transform.localScale.x * .3f;

                    moons[i].transform.position = position;
                    //moons[i].transform.localScale = Vector3.one * (float)Mathd.Pow((moon.bodyRadius), solarSpriteScale) * Mathf.Pow(game.localScaleMod, .9f);
                    moons[i].transform.localScale = sun.transform.localScale * .15f;

                    //Creates the line rendering for the orbit of moons

                    line = moons[i].GetComponent <LineRenderer>();

                    var positions = new Vector3[361];

                    var    timeInc = (moon.OrbitalPeriod(model.solar.satelites[moon.solarIndex[1]].mass) / 360);
                    double time    = game.data.date.time;

                    for (var b = 0; b < 361; b++)
                    {
                        positions[b] = model.solar.satelites[moon.solarIndex[1]].GamePosition(game.data.date.time) + moon.GamePosition(time);
                        time        += timeInc;
                    }
                    line.positionCount = 361;
                    line.SetPositions(positions);

                    yield return(null);
                }
            }
            yield return(null);
        }
    }
コード例 #2
0
    public void CreateSystem()
    {
        model.localScale     = 1;
        transform.localScale = Vector3.one;
        sun      = Instantiate(sunObj, transform);
        sun.name = model.name + " Sun";
        sun.transform.position   = Vector3.zero;
        sun.transform.localScale = Vector3.one * (float)Mathd.Pow((model.solar.bodyRadius / GameDataModel.solarDistanceMultiplication), solarSpriteScale);
        sun.GetComponent <SpriteRenderer>().color        = model.solar.color;
        sun.GetComponent <SpriteRenderer>().sortingOrder = 5;

        var info = sun.GetComponent <PlanetInfo>();

        info.solar = model.solar;

        planets = new List <GameObject>();
        for (int i = 0; i < model.solar.satelites.Count; i++)
        {
            SolarBody body     = model.solar.satelites[i];
            Vector3   position = sun.transform.position + body.GamePosition(game.data.date.time);
            planets.Add(Instantiate(planetObj, transform));
            planets[i].name = body.name;
            planets[i].transform.localPosition = position;
            planets[i].GetComponent <SpriteRenderer>().color        = body.color;
            planets[i].GetComponent <SpriteRenderer>().sortingOrder = 4;
            planets[i].transform.localScale = Vector3.one * (float)Mathd.Pow((body.bodyRadius), solarSpriteScale);

            info       = planets[i].GetComponent <PlanetInfo>();
            info.solar = body;

            //Creates the line rendering for the orbit of planets

            LineRenderer line = planets[i].GetComponent <LineRenderer>();

            Vector3[] positions = new Vector3[361];

            double timeInc = (body.OrbitalPeriod(model.solar.mass) / 360);
            double time    = game.data.date.time;

            for (var b = 0; b < 361; b++)
            {
                positions[b] = body.GamePosition(time);
                time        += timeInc;
            }
            line.positionCount = 361;
            line.SetPositions(positions);

            if (body.solarSubType == SolarSubType.GasGiant)
            {
                Color col = Color.blue;
                col.a           = .25f;
                line.startColor = col;
                line.endColor   = col;
            }
            else if (body.solarType == SolarType.DwarfPlanet)
            {
                Color col = Color.yellow;
                col.a           = .25f;
                line.startColor = col;
                line.endColor   = col;
            }
            else if (body.solarType == SolarType.Comet)
            {
                Color col = Color.white;
                col.a           = .25f;
                line.startColor = col;
                line.endColor   = col;
            }
            else
            {
                Color col = Color.green;
                col.a           = .25f;
                line.startColor = col;
                line.endColor   = col;
            }

            //Create Moons
            for (int m = 0; m < model.solar.satelites[i].satelites.Count; m++)
            {
                SolarBody moon = model.solar.satelites[i].satelites[m];
                position  = moon.GamePosition(game.data.date.time);
                position += model.solar.satelites[moon.solarIndex[1]].GamePosition(game.data.date.time);
                moonModels.Add(moon);

                moons.Add(Instantiate(moonObj, transform));
                moons[moons.Count - 1].name = moon.name;
                moons[moons.Count - 1].transform.position = position;
                moons[moons.Count - 1].GetComponent <SpriteRenderer>().color        = moon.color;
                moons[moons.Count - 1].GetComponent <SpriteRenderer>().sortingOrder = 3;
                moons[moons.Count - 1].transform.localScale = Vector3.one * (float)Mathd.Pow((moon.bodyRadius), solarSpriteScale);

                info       = moons[moons.Count - 1].GetComponent <PlanetInfo>();
                info.solar = moon;
            }
        }

        //Create Stations
        stations = new StationController[model.stations.Count];
        int c = 0;

        foreach (StationModel station in model.stations)
        {
            stations[c] = Controller.Instantiate <StationController>("station", station);
            c++;
        }

        StartCoroutine("UpdateSolarObjects");
    }