Exemple #1
0
    // Close the Date/Time selection box and set the Date/Time
    public void CloseDateSelection()
    {
        dateSel.SetActive(false);

        // Assign the selected dropdown values to a new DateTime
        int newMonth = monthDrop.GetComponent <TMP_Dropdown>().value + 1;
        int newDay   = dayDrop.GetComponent <TMP_Dropdown>().value + 1;
        int newYear  = yearDrop.GetComponent <TMP_Dropdown>().value + 2000;
        int newHour  = hourDrop.GetComponent <TMP_Dropdown>().value;
        int newMin   = minDrop.GetComponent <TMP_Dropdown>().value;

        DateTime newDate = new DateTime(newYear, newMonth, newDay, newHour, newMin, 0);

        // Update s
        SetS(newDate);

        // Update t in EarthBehavior
        EarthBehavior earthObj = earth.GetComponent("EarthBehavior") as EarthBehavior;

        earthObj.SetT(newDate);

        // Update Earth's and Moon's rotation
        earthObj.SetRot(earthObj.GetDT());
        MoonBehavior moonObj = moon.GetComponent("MoonBehavior") as MoonBehavior;

        moonObj.SetRot(earthObj.GetDT());

        // Call FixedUpdate() to update the date and time
        FixedUpdate();
    }
    // Update is called once per frame
    void Update()
    {
        EarthBehavior earthObj = earth.GetComponent("EarthBehavior") as EarthBehavior;
        SunBehavior   sunObj   = sun.GetComponent("SunBehavior") as SunBehavior;
        MoonBehavior  moonObj  = moon.GetComponent("MoonBehavior") as MoonBehavior;

        switch (view)
        {
        // Sun View
        case 0:
            transform.position = Vector3.MoveTowards(earthObj.GetPosition(), sunObj.GetPosition(), .15f);
            transform.LookAt(sunObj.GetTransform());
            break;

        // Earth View
        case 1:
            transform.position  = earthObj.GetPosition();
            transform.position -= new Vector3(0, 0, .15f);
            transform.LookAt(earthObj.GetTransform());
            break;

        // Moon View
        case 2:
            transform.position = Vector3.MoveTowards(earthObj.GetPosition(), moonObj.GetPosition(), .15f);
            transform.LookAt(moonObj.GetTransform());
            break;

        // Top-down view
        case 3:
            transform.position = new Vector3(0, 3500, 0);
            transform.LookAt(sunObj.GetTransform());
            break;
        }
    }