Esempio n. 1
0
    /* adds a satellite in orbit around an existing body */
    public void AddSatellite(CelestialType type)
    {
        /*
         * TODO:
         * 1) get larger radius of primary's furthest orbital path
         * 2) min valid orbit rad = furthestOrbit.region.upperLimit + minDist (for now)
         * 3) add satellite at some radius s.t. not overlapping with former furthest
         */

        if (!_sceneIsEditable)
        {
            return;
        }

        CelestialBody primary;

        if (!user || !user.isActiveAndEnabled)
        {
            if (debugMode && debugSelectedObject)
            {
                primary = debugSelectedObject;
            }
            else
            {
                primary = initialStar;
            }
        }
        else if ((primary = user.selectedObject.GetComponent <CelestialBody> ()) == null)
        {
            return;
        }

        float furthestRegionLimit;

        if (primary.NumSatellites <= 0)
        {
            furthestRegionLimit = primary.naturalMaxSize / 2;
        }
        else
        {
            furthestRegionLimit = primary.FurthestSatellite.Region.Max;
        }

        float     orbitRadius = furthestRegionLimit + CelestialBody.MinimumSeparatingDistance + templates[type].naturalMaxSize / 2;
        OrbitPath path        = Instantiate(orbitPathTemplate);

        Debug.Log("orbit radius is " + orbitRadius);

        /*
         * TODO: spawn satellite at path's north position
         * set satellite's path
         * add satellite to SM's list of CBs
         */

        OrbitingBody satellite = Instantiate(templates[type]);

        satellite.InitSatellite(primary, path, orbitRadius, orbitRadius);
        bodies.Add(satellite);

        primary.AddOrbitingBody(satellite);

        if (debugMode)
        {
            UpdateDisplayInfo();
        }
    }