コード例 #1
0
    public void SetUpBody(GenerationSettings.StarSettings starSettings, bool setPositions = true)
    {
        // this is called when a celestial body is wanting to be set up to be a star

        // add a rigidbody to the body
        if (rb is null)
        {
            rb = gameObject.AddComponent <Rigidbody>();
        }

        // set the type of body
        bodyType = starSettings.bodyType;

        // set up the visual sphere here
        visualSphere = new GameObject(gameObject.name + " visuals");
        visualSphere.transform.parent = transform;

        //CelestialBodyMesh meshConstructor = visualSphere.AddComponent<CelestialBodyMesh>();
        //meshConstructor.Generate(starSettings.structureSettings, starSettings.colorSettings);

        // set the properties of the body from the settings
        surfaceGravity = starSettings.surfaceGravity;
        radius         = starSettings.radius;
        mass           = radius * radius * surfaceGravity / Universe.gravitationalConstant;
        axisTilt       = starSettings.axisTilt;
        axialSpinSpeed = starSettings.axialSpin;

        Quaternion upRot = Quaternion.AngleAxis(axisTilt, Vector3.forward);

        localUpAxis = upRot * Vector3.up;

        StarMesh sm = visualSphere.AddComponent <StarMesh>();

        sm.Setup(starSettings.temperature);

        // set up the transform
        transform.localScale = Vector3.one;
        visualSphere.transform.localScale    = Vector3.one * radius * 2;
        visualSphere.transform.localRotation = upRot;

        // setup the rigidbody
        rb.mass = mass;

        // each object is given a unique id that is generated through its settings
        ID = starSettings.id;

        if (setPositions)
        {
            // set up the initial velocity
            // for a star in a single star system, we dont need initial velocity
            // as the star is not moving initially relative to all other objects
            // in the system
            initialVelocity = Vector3.zero;
            rb.position     = Vector3.zero;
        }
    }
コード例 #2
0
    void CreateStar(GenerationSettings.StarSettings starSettings)
    {
        // create a new star gameobject
        // and make it a child of the solar system
        GameObject newStar = new GameObject
        {
            name = "Star"
        };

        newStar.transform.parent = transform;

        // then add components and set the settings
        CelestialBody cbComponent = newStar.AddComponent <CelestialBody>();

        // pass the settings into the celestial body to all it to set up
        cbComponent.SetUpBody(starSettings);

        star = cbComponent;
        celestialBodies.Add(cbComponent);
    }