Пример #1
0
    //*****************************************************************
    // Run-time methods
    //*****************************************************************

    /// <summary>
    /// Run-time update of the solar system time. The new time must be a time later
    /// than the initial start time of the solar system.
    ///
    /// This API makes use of @GravityEngine#SetPhysicalTime. This requires that ALL
    /// objects in the scene be "on-rails" i.e. have an OrbitXXX component and be in Kepler
    /// evolution mode.
    ///
    /// </summary>
    /// <param name="year"></param>
    /// <param name="month"></param>
    /// <param name="day"></param>
    /// <param name="dayFrac"></param>
    public void SetTime(int year, int month, int day, float dayFrac)
    {
        // TODO - use dayFrac

        // C# DateTime/TimeSpan to find the number of seconds to add
        System.DateTime newTime       = new System.DateTime(year, month, day);
        System.DateTime startTime     = SolarUtils.DateForEpoch(_epochTime);
        double          secsFromStart = (newTime - startTime).Ticks / (1E7);

        if (secsFromStart < 0)
        {
            Debug.LogError("Cannot evolve earlier than solar system start time.");
        }
        Debug.LogFormat("Secs from start={0} phys={1} newPhys={2}",
                        secsFromStart,
                        GravityEngine.Instance().GetPhysicalTimeDouble(),
                        GravityScaler.WorldSecsToPhysTime(secsFromStart));
        GravityEngine.Instance().SetPhysicalTime(GravityScaler.WorldSecsToPhysTime(secsFromStart));
    }