将Unity的Android日期选择器对话框的选项限制为从当前日期开始

时间:2019-07-07 00:14:53

标签: c# android unity3d android-datepicker

我需要日期选择器对话框选项仅允许从当前日期开始使用,在统一文档中看不到设置选项的选项

void Start() {        
    if (PlayerPrefs.GetString("StartingDateTime") != null) {
        if (PlayerPrefs.GetString("GoalDateTime") != null) {
            startingDate = Convert.ToDateTime(PlayerPrefs.GetString("StartingDateTime"));
            goalDate = Convert.ToDateTime(PlayerPrefs.GetString("GoalDateTime"));
            startingDateLoadedText.text = startingDate.ToString();
            goalDateLoadedText.text = goalDate.ToString();
            totalWeeksInt = PlayerPrefs.GetInt("TotalWeeks");
            SetWeeksToGoalDate();
            SetCurrentWeek();
        }
    }
}

void Update() {

    if (SelectedDate.newDate) {
        if (newSelectedStartingDate) {
            startingDate = SelectedDate.date;
            startingDateText.text = SelectedDate.date.ToString("d/M/yyyy");
            PlayerPrefs.SetString("StartingDateTime", SelectedDate.date.ToString());
            newSelectedStartingDate = false;
        } else if (newSelectedGoalDate) {
            goalDate = SelectedDate.date;
            goalDateText.text = SelectedDate.date.ToString("d/M/yyyy");
            PlayerPrefs.SetString("GoalDateTime", SelectedDate.date.ToString());
            newSelectedGoalDate = false;
        }
        SelectedDate.newDate = false;
    }
}

void PickDate()
{
    new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), SelectedDate.date.Year, SelectedDate.date.Month - 1, SelectedDate.date.Day).Call("show");
}

public void SelectStartingDate() {
    activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    activity.Call("runOnUiThread", new AndroidJavaRunnable(PickDate));
    newSelectedStartingDate = true;        
}

public void SelectGoalDate()
{
    activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    activity.Call("runOnUiThread", new AndroidJavaRunnable(PickDate));
    newSelectedGoalDate = true;        
}

public void SetWeeksToGoalDate() {        
    if (startingDate != null && goalDate != null) {
        TimeSpan goalDateWeeks = goalDate - startingDate;
        int weeks = goalDateWeeks.Days / 7;
        PlayerPrefs.SetInt("TotalWeeks", weeks);
        totalWeeksInt = weeks;
        weightLossPeriodText.text = weeks.ToString();
    }
}

我想了解一些有关通过Unity代码在何处设置选项的参考,或者是否需要通过Android插件设置插件并重新导入到应用中。

0 个答案:

没有答案