代码1:
public class TimePicker_Fragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
private static final String KEY_TIMEPICKER_TAG = "KEY_TIMEPICKER_TAG";
/**
*
* @param timePickerTag the tag by which you can identify a TimePicker.
* Will be set as tag to the TimePicker View in onTimeSet()
* @return x
*/
public static TimePicker_Fragment instance(String timePickerTag){
TimePicker_Fragment fragment = new TimePicker_Fragment();
Bundle b = new Bundle();
b.putString(KEY_TIMEPICKER_TAG, timePickerTag);
fragment.setArguments(b);
return fragment;
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
Context ctx = getContext();
return new TimePickerDialog(ctx, this, hour, minute, DateFormat.is24HourFormat(ctx));
}
public void onTimeSet(TimePicker timePicker, int i, int i2){
Bundle b = getArguments();
assert b != null;
timePicker.setTag(b.getString(KEY_TIMEPICKER_TAG));
((TimePickerDialog.OnTimeSetListener)getActivity()).onTimeSet(timePicker, i, i2);
}
}
答案 0 :(得分:4)
我将一次分解您帖子中的代码:
while (a){
a
为假,协程将立即退出(转到9),并且没有其他反应,否则,继续if(b){
b
为假,则转到7,否则,继续Debug.Log("test-1");
yield return new WaitForSeconds(1f);
StartCoroutine()
)的Unity系统时,该函数的执行将被挂起并在以后返回。在这种情况下,请等待1秒(此值由当前Time.timeScale
修改)。恢复执行后,请转到下一步:Debug.Log("test-2");
Debug.Log("test-3");
yield return break;
yield
)和(2)以后不再恢复该功能(break
)。不要转到步骤8。} //end while(a)
} //end function
因此,如果a
和b
都为真,那么回答您的问题“ test-1”将只打印一次。