Beispiel #1
0
 // Remove a specified Orbit from the StarSystem asset, save the changes and update the Orbit sub-inspectors.
 public void RemoveOrbitLine(OrbitLine orbit)
 {
     starSystem.orbits.Remove(orbit);
     AssetDatabase.RemoveObjectFromAsset(orbit);
     AssetDatabase.SaveAssets();
     AssetDatabase.Refresh();
     UpdateOrbitLines();
 }
Beispiel #2
0
    internal void Init(SceneCelestialBody sceneCelestialBody)
    {
        this.sceneCelestial = sceneCelestialBody;
        celestial           = sceneCelestialBody.celestialBody;

        List <Vector3d> orbitVertices = celestial.getOrbitVertices(false);

        if (orbitVertices == null)
        {
            return;
        }

        //get orbit line calculated from precise locations instead of assumed ellipse
        if (perturbedOrbitLine == null)
        {
            perturbedOrbitLine = new OrbitLine();
            perturbedOrbitLine.init(this, celestial.name, Color.cyan);
        }
        perturbedOrbitLine.setLine(orbitVertices);

        //get new orbit vertices, but elliptical (not perturbed)
        orbitVertices = celestial.getOrbitVertices(true);

        //does this body revolves around the system's main body? If so, draw its ecliptic
        if (celestial.relativeTo == null || celestial.relativeTo == SO.U.getBody())
        {
            var eclipticVertices = new List <Vector3d>(orbitVertices);

            for (int index = 0; index < eclipticVertices.Count; index++)
            {
                eclipticVertices[index] = eclipticVertices[index] * -1;
            }

            if (eclipticLine == null)
            {
                eclipticLine = new OrbitLine();
                eclipticLine.init(this, celestial.name, Color.magenta);
            }
            eclipticLine.setLine(eclipticVertices);
        }

        if (ellipticOrbitLine == null)
        {
            ellipticOrbitLine = new OrbitLine();
            ellipticOrbitLine.init(this, celestial.name, Color.magenta);
        }
        ellipticOrbitLine.setLine(orbitVertices);

        if (celestial.calculateFromElements)
        {
            celestial.revolution += body => recalculateOrbitLine(false);
        }

        orbitLine = celestial.calculateFromElements ? perturbedOrbitLine : ellipticOrbitLine;
    }
Beispiel #3
0
    // Create a new Orbit that is a child to the StarSystem asset. Save the assets to disk and update the Orbit sub-inspectors.
    private void AddOrbitLine()
    {
        OrbitLine orbitLine = ScriptableObject.CreateInstance <OrbitLine>();

        orbitLine.name = "New Orbit";
        starSystem.orbits.Add(orbitLine);
        AssetDatabase.AddObjectToAsset(orbitLine, starSystem);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        UpdateOrbitLines();
    }
Beispiel #4
0
    public OrbitLineSubEditor(StarSystemEditor starSystemEditor, OrbitLine orbitLine)
    {
        this.starSystemEditor = starSystemEditor;
        this.orbitLine        = orbitLine;

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Examples/StarSystemScene/Scripts/Editor/StarSystemEditor/OrbitLineSubEditor.uxml");

        visualTree.CloneTree(this);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/StarSystemScene/Scripts/Editor/StarSystemEditor/OrbitLineSubEditor.uss");

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("orbitLineSubEditor");

        // Store visual element that will contain the planet sub-inspectors.
        planetList = this.Query <VisualElement>("planetList").First();
        UpdatePlanets();

        noteList = this.Query <VisualElement>("noteList").First();
        UpdateNotes();


        #region Fields
        TextField stringField = this.Query <TextField>("orbitName").First();
        stringField.value = orbitLine.name;
        stringField.RegisterCallback <ChangeEvent <string> >(
            e =>
        {
            orbitLine.name = (string)e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        Slider distanceField = this.Query <Slider>("orbitDistance").First();
        distanceField.value = orbitLine.orbitDistance;
        distanceField.label = "Orbit Distance " + distanceField.value.ToString("F2");
        distanceField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            orbitLine.orbitDistance = e.newValue;
            distanceField.label     = "Orbit Distance " + e.newValue.ToString("F2");
            EditorUtility.SetDirty(orbitLine);
        }
            );


        Slider thicknessField = this.Query <Slider>("thickness").First();
        thicknessField.value = orbitLine.thickness;
        thicknessField.label = "Thickness " + thicknessField.value.ToString("F3");
        thicknessField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            orbitLine.thickness  = e.newValue;
            thicknessField.label = "Thickness " + e.newValue.ToString("F3");
            EditorUtility.SetDirty(orbitLine);
        }
            );

        IntegerField segmentsField = this.Query <IntegerField>("segments").First();
        segmentsField.value = orbitLine.segments;
        segmentsField.RegisterCallback <ChangeEvent <int> >(
            e =>
        {
            orbitLine.segments = e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        ColorField colorField = this.Query <ColorField>("color").First();
        colorField.value = orbitLine.color;
        colorField.RegisterCallback <ChangeEvent <Color> >(
            e =>
        {
            orbitLine.color = e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        Toggle waypointField = this.Query <Toggle>("useWaypoints").First();
        waypointField.value = orbitLine.useWaypoints;
        waypointField.RegisterCallback <ChangeEvent <bool> >(
            e =>
        {
            orbitLine.useWaypoints = e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        #endregion

        #region Buttons
        // Assign methods to the click events of the two buttons.
        Button btnAddPlanet = this.Query <Button>("btnAddNewPlanet").First();
        btnAddPlanet.clickable.clicked += AddPlanet;

        Button btnRemoveAllPlanets = this.Query <Button>("btnRemoveAllPlanets").First();
        btnRemoveAllPlanets.clickable.clicked += RemoveAllPlanets;

        // Assign methods to the click events of the two buttons.
        Button btnAddNote = this.Query <Button>("btnAddNewNote").First();
        btnAddNote.clickable.clicked += AddNote;

        Button btnRemoveAllNotes = this.Query <Button>("btnRemoveAllNotes").First();
        btnRemoveAllNotes.clickable.clicked += RemoveAllNotes;



        Button btnRemoveOrbit = this.Query <Button>("btnRemoveOrbitLine").First();
        btnRemoveOrbit.clickable.clicked += RemoveOrbitLine;
        #endregion
    }